@extends('layouts/base_view')

@section('title')
{!! $variables['header_routes'] !!}
@endsection

@section('content')
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">{!! $variables['judul'] !!}</h3>
                        <div class="float-right">
                            <a href="{{ route('users.index') }}" class="btn btn-warning btn-sm button-cek-permission" data-permission="users.index">
                                <i class="fas fa-list"></i> Daftar
                            </a>
                            <a href="{{ route('users.edit',$data->id) }}" class="btn btn-warning btn-sm button-cek-permission" data-permission="users.edit">
                                <i class="fas fa-edit"></i> Ubah
                            </a>
                            @if($data->id == $logged_user_id)
                            <a href="{{ route('users.edit-my-account',$data->id) }}" class="btn btn-warning btn-sm button-cek-permission" data-permission="users.edit">
                                <i class="fas fa-user-edit"></i> Ubah Akun Saya
                            </a>
                            <a href="{{ route('users.change-password', $data->id) }}" class="btn btn-warning btn-sm button-cek-permission" data-permission="users.edit">
                                <i class="fas fa-key"></i> Ubah Password
                            </a>
                            @else
                            <a href="{{ route('users.reset-password', $data->id) }}" class="btn btn-warning btn-sm button-cek-permission" data-permission="users.edit">
                                <i class="fas fa-redo"></i> Reset Password
                            </a>
                            <a href="{{ route('users.destroy',$data->id) }}" onclick="notificationBeforeDelete(event, this)" class="btn btn-warning btn-sm button-cek-permission" data-permission="users.destroy">
                                <i class="fas fa-trash"></i> Hapus
                            </a>
                            @endif
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <!-- Single Card with All Information -->
                            <div class="col-12">
                                <div class="card card-outline card-warning">
                                    <div class="card-body">
                                        <div class="row">
                                            <!-- Role -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Role</label>
                                                    @if($data->roles && $data->roles->count() > 0)
                                                        @foreach($data->roles as $role)
                                                            <span class="badge badge-info mr-1">{{ $role->name }}</span>
                                                        @endforeach
                                                    @else
                                                        <span class="badge badge-secondary">Tidak Ada Role</span>
                                                    @endif
                                                </div>
                                            </div>
                                            
                                            <!-- Username -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Username</label>
                                                    <span class="badge badge-info">{{ $data->username }}</span>
                                                </div>
                                            </div>
                                            
                                            <!-- Fullname -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Nama Lengkap</label>
                                                    <p class="mb-0">{{ $data->fullname }}</p>
                                                </div>
                                            </div> 
                                            
                                            <!-- Email -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Email</label>
                                                    <p class="mb-0">
                                                        @if($data->email)
                                                            <a href="mailto:{{ $data->email }}" class="text-decoration-none">
                                                                {{ $data->email }}
                                                            </a>
                                                        @else
                                                            -
                                                        @endif
                                                    </p>
                                                </div>
                                            </div>
                                            
                                            <!-- Telephone -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Telepon</label>
                                                    <p class="mb-0">
                                                        @if($data->telephone)
                                                            <a href="tel:{{ $data->telephone }}" class="text-decoration-none">
                                                                {{ $data->telephone }}
                                                            </a>
                                                        @else
                                                            -
                                                        @endif
                                                    </p>
                                                </div>
                                            </div>
                                            
                                            <!-- Backdate SO Flag -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Backdate SO</label>
                                                    @if($data->flag_backdate_so)
                                                        <span class="badge badge-success">
                                                            <i class="fas fa-check-circle"></i> Diizinkan
                                                        </span>
                                                    @else
                                                        <span class="badge badge-secondary">
                                                            <i class="fas fa-times-circle"></i> Tidak Diizinkan
                                                        </span>
                                                    @endif
                                                </div>
                                            </div>
                                            
                                            <!-- Created By -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Dibuat Oleh</label>
                                                    <p class="mb-0">
                                                        <small class="text-muted">
                                                            {{ $data->creator->fullname ?? 'System' }}<br>
                                                            {{ $data->created_at->format('d M Y, H:i') }}
                                                        </small>
                                                    </p>
                                                </div>
                                            </div>
                                            
                                            <!-- Updated By -->
                                            @if($data->modificator)
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Diubah Oleh</label>
                                                    <p class="mb-0">
                                                        <small class="text-muted">
                                                            {{ $data->modificator->fullname }}<br>
                                                            {{ $data->updated_at->format('d M Y, H:i') }}
                                                        </small>
                                                    </p>
                                                </div>
                                            </div>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- User Access Stores -->
                        @if(isset($variables['stores']) && count($variables['stores']) > 0)
                        <div class="row">
                            <div class="col-12">
                                <div class="card card-outline card-warning">
                                    <div class="card-header">
                                        <h5 class="mb-0">Akses Toko User ({{ count($variables['stores']) }} toko)</h5>
                                        <div class="ml-auto card-tools">
                                            <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                                                <i class="fas fa-minus"></i>
                                            </button>
                                        </div>
                                    </div>
                                    <div class="card-body">
                                        <div class="table-responsive">
                                            <table class="table table-hover table-sm">
                                                <thead class="bg-light">
                                                    <tr>
                                                        <th width="5%">No</th>
                                                        <th width="15%">Kode Toko</th>
                                                        <th width="40%">Nama Toko</th>
                                                        <th width="20%">PIC</th>
                                                        <th width="20%">Status</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    @foreach ($variables['stores'] as $key => $store)
                                                    <tr>
                                                        <td>{{ $key + 1 }}</td>
                                                        <td>
                                                            <span class="badge badge-info">{{ $store->code }}</span>
                                                        </td>
                                                        <td>
                                                            <a href="{{ route('stores.show', $store->id) }}" class="text-decoration-none">
                                                                {{ $store->name }}
                                                            </a>
                                                        </td>
                                                        <td>{{ $store->pic ?: '-' }}</td>
                                                        <td>
                                                            @if($store->status == 'Active')
                                                                <span class="badge badge-success">{{ $store->status }}</span>
                                                            @else
                                                                <span class="badge badge-secondary">{{ $store->status }}</span>
                                                            @endif
                                                        </td>
                                                    </tr>
                                                    @endforeach
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<form action="" id="delete-form" method="post">
    @method('delete')
    @csrf
</form>
@endsection