@extends('component.app')
@section('title', 'Kepala Laundry')
@section('active12', 'active')
@section('menu1', 'open')
@section('content')


    <div class="content-wrapper">
        <div class="container-xxl flex-grow-1 container-p-y">
            <!-- Invoice List Table -->
            <div class="card">
                <div class="header-menu d-flex justify-content-between align-items-center">
                    <h4 class="card-header">Data Kepala Laundry</h4>
                    {{-- @if (Auth::user()->role != 'pegawai' && Auth::user()->role != '')
                        <button type="button" class="btn btn-primary me-2" data-bs-toggle="modal"
                            data-bs-target="#staticBackdrop"><i class="bx bx-plus bx-sm"></i> Add</button>
                    @endif --}}
                </div>
                <div class="table-responsive">
                    <table class="table table-hover" id="Mytable">
                        <thead class="table-primary text-center">
                            <tr>
                                <th scope="col">Foto</th>
                                <th scope="col">Laundry</th>
                                <th scope="col">Username</th>
                                <th scope="col">Email</th>
                                <th scope="col">No Telp</th>
                                <th scope="col">nama</th>
                                <th scope="col">Alamat</th>
                                <th scope="col">Status</th>
                                <th scope="col">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($kepala_toko as $kepala_toko)
                                <tr>
                                    <td>
                                        <img src="{{ $kepala_toko->foto ? asset('storage/img/' . $kepala_toko->foto) : asset('default-avatar.png') }}"
                                            alt="Foto Pegawai" width="50px" height="50px">
                                    </td>

                                    <td>{{ $kepala_toko->laundry->nama_laundry }}</td>
                                    <td>{{ $kepala_toko->user->username }}</td>
                                    <td>{{ $kepala_toko->user->email }}</td>
                                    <td>{{ $kepala_toko->no_telp }}</td>
                                    <td>{{ $kepala_toko->nama }}</td>
                                    <td>{{ $kepala_toko->alamat }}</td>
                                    <td>
                                        @if (Auth::user()->role == 'admin')
                                            @if ($kepala_toko->pegawai_status == 'aktif')
                                                <span class="badge bg-label-success me-1">Aktif</span>
                                            @elseif ($kepala_toko->status == 'tidak aktif')
                                                <span class="badge bg-label-danger me-1">Tidak Aktif</span>
                                            @endif
                                        @else
                                            @if ($kepala_toko->status == 'aktif')
                                                <span class="badge bg-label-success me-1">Aktif</span>
                                            @elseif ($kepala_toko->status == 'tidak aktif')
                                                <span class="badge bg-label-danger me-1">Tidak Aktif</span>
                                            @endif
                                        @endif
                                    </td>
                                    <td>
                                        <a href="{{ route('kepala_toko.edit', $kepala_toko->user->id) }}"
                                            class="btn btn-sm btn-label-secondary"> <i class="bx bx-edit-alt"></i></a>

                                        <form action="{{ route('kepala_toko.aktifasi', $kepala_toko->id) }}" method="POST">
                                            @csrf

                                            @if ($kepala_toko->status == 'aktif')
                                                <button type="submit" class="btn btn-sm btn-label-danger"
                                                    onclick="return confirm('Apakah anda yakin ingin menonaktifkan akun ini?')">
                                                    <i class="bx bx-user-x bx-sm"></i>
                                                </button>
                                            @elseif ($kepala_toko->status == 'tidak aktif')
                                                <button type="submit" class="btn btn-sm btn-label-success"
                                                    onclick="return confirm('Apakah anda yakin ingin mengaktifkan akun ini?')">
                                                    <i class="bx bx-user-check bx-sm"></i>
                                                </button>
                                            @endif
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>

            </div>
            <!-- Modal -->
            <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
                aria-labelledby="staticBackdropLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content ">
                        <div class="modal-header">
                            <h5 class="modal-title" id="staticBackdropLabel">Tambah Data Pegawai</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <form action="{{ route('pegawai.store') }}" method="POST" enctype="multipart/form-data">
                                @csrf
                                <div class="row">
                                    <!-- Kolom Kiri -->
                                    <div class="col-md-6">
                                        <!-- Laundry -->
                                        @if (Auth::user()->role == 'superadmin')
                                            <div class="mb-3">
                                                <label for="laundry_id" class="form-label">Pilih Laundry</label>
                                                <select id="laundry_id" name="laundry_id" class="form-select" required>
                                                    <option value="">Pilih Laundry</option>
                                                    @foreach ($laundry as $laundry)
                                                        <option value="{{ $laundry->id }}">{{ $laundry->nama_laundry }}
                                                        </option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        @else
                                            <input type="hidden" id="laundry_id" name="laundry_id"
                                                value="{{ $laundry->nama_laundry }}">

                                            <input type="hidden" id="laundry_id" name="laundry_id"
                                                value="{{ $laundry->id }}">

                                        @endif
                                        <!-- Username -->
                                        <div class="mb-3">
                                            <label for="username" class="form-label">Username</label>
                                            <input type="text" class="form-control" id="username" name="username"
                                                placeholder="Masukkan Username" required>
                                        </div>

                                        <!-- Email -->
                                        <div class="mb-3">
                                            <label for="email" class="form-label">Email</label>
                                            <input type="email" class="form-control" id="email" name="email"
                                                placeholder="Masukkan Email" required>
                                        </div>

                                        <!-- Password -->
                                        <div class="mb-3">
                                            <label for="password" class="form-label">Password</label>
                                            <input type="password" class="form-control" id="password" name="password"
                                                placeholder="Masukkan Password" required>
                                        </div>

                                        <!-- Phone -->
                                        <div class="mb-3">
                                            <label for="phone" class="form-label">No. Telp</label>
                                            <input type="text" class="form-control" id="phone" name="no_telp"
                                                placeholder="Masukkan No. Telp" required>
                                        </div>

                                        <!-- Role -->
                                        {{-- <div class="mb-3">
                                            <label for="role" class="form-label">Role</label>
                                            <select id="role" name="role" class="form-select" required>
                                                <option value="superadmin">Superadmin</option>
                                                <option value="admin">Admin</option>
                                                <option value="pegawai">Pegawai</option>
                                                <option value="pelanggan">Pelanggan</option>
                                            </select>
                                        </div> --}}
                                    </div>

                                    <!-- Kolom Kanan -->
                                    <div class="col-md-6">
                                        <!-- Nama -->
                                        <div class="mb-3">
                                            <label for="nama" class="form-label">Nama</label>
                                            <input type="text" class="form-control" id="nama" name="nama"
                                                placeholder="Masukkan Nama" required>
                                        </div>

                                        <!-- Alamat -->
                                        <div class="mb-3">
                                            <label for="alamat" class="form-label">Alamat</label>
                                            <textarea class="form-control" id="alamat" name="alamat" placeholder="Masukkan Alamat" rows="3" required></textarea>
                                        </div>

                                        <!-- Foto -->
                                        <div class="mb-3">
                                            <label for="foto" class="form-label">Foto</label>
                                            <input type="file" class="form-control" id="foto" name="foto">
                                        </div>



                                        {{-- <!-- Status -->
                                        <div class="mb-3">
                                            <label for="status" class="form-label">Status</label>
                                            <select id="status" name="status" class="form-select" required>
                                                <option value="aktif">Aktif</option>
                                                <option value="tidak aktif">Tidak Aktif</option>
                                            </select>
                                        </div> --}}
                                    </div>
                                </div>

                        </div>

                        <div class="modal-footer">
                            {{-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> --}}
                            <button type="submit" class="btn btn-primary">Simpan</button>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
        @endsection
