@extends('component.app')
@section('title', 'Pegawai')
@section('active5', '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 Pegawai</h4>
                    @if (Auth::user()->role != 'pegawai' && Auth::user()->role != 'admin' && Auth::user()->role != 'superadmin')
                        <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 ($pegawai as $pegawai)
                                <tr>
                                    <td>
                                        <img src="{{ $pegawai->foto ? asset('storage/img/' . $pegawai->foto) : asset('default-avatar.png') }}"
                                            alt="Foto Pegawai" width="50px" height="50px">
                                    </td>

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


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

                                                @if ($pegawai->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 ($pegawai->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>
                                        @endif
                                    </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">
                            <!-- Carousel untuk form slider -->
                            <div id="formCarousel" class="carousel slide" data-bs-ride="false" data-bs-interval="false">
                                <div class="carousel-inner">
                                    <!-- Slide 1: Data Pegawai -->
                                    <div class="carousel-item active">
                                        <form action="{{ route('pegawai.store') }}" method="POST" id="formPegawai"
                                            enctype="multipart/form-data">
                                            @csrf
                                            <div class="row">
                                                <!-- Kolom Kiri -->
                                                <div class="col-md-6">
                                                    <!-- Laundry -->
                                                    @if (Auth::user()->role == 'superadmin' || Auth::user()->role == 'admin')
                                                        <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->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>
                                                </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>
                                                </div>
                                            </div>

                                            <!-- Tombol Next -->
                                            <button type="button" class="btn btn-primary" data-bs-target="#formCarousel"
                                                data-bs-slide="next">
                                                Next
                                            </button>

                                    </div>

                                    <!-- Slide 2: Komisi dan Paket -->
                                    <div class="carousel-item">

                                        <div class="row">
                                            <!-- Komisi Harian -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="komisi_harian" class="form-label">Komisi
                                                        Harian</label>
                                                    <input type="number" class="form-control" id="komisi_harian"
                                                        name="komisi_harian" placeholder="Masukkan Komisi Harian"
                                                        required>
                                                </div>

                                                <!-- Gaji Pokok -->
                                                <div class="mb-3">
                                                    <label for="gaji_pokok" class="form-label">Gaji Pokok</label>
                                                    <input type="number" class="form-control" id="gaji_pokok"
                                                        name="gaji_pokok" placeholder="Masukkan Gaji Pokok" required>
                                                </div>
                                            </div>

                                            <!-- Pilih Paket -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="pilih_paket" class="form-label">Kelola Paket</label>
                                                    <select id="pelanggan" class="form-select form-control"
                                                        name="paket_id[]" multiple="multiple" required
                                                        style="width: 100%">
                                                        @foreach ($paket as $paket)
                                                            <option value="{{ $paket->id }}">
                                                                {{ $paket->nama_paket }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>

                                                <!-- Komisi Per Paket -->
                                                <div class="mb-3">
                                                    <label for="komisi_perpaket" class="form-label">Komisi Per
                                                        Paket</label>
                                                    <input type="number" class="form-control" id="komisi_perpaket"
                                                        name="komisi_perpaket" placeholder="Masukkan Komisi Per Paket"
                                                        required>
                                                </div>
                                            </div>
                                        </div>

                                        <!-- Tombol Previous dan Submit -->
                                        <button type="button" class="btn btn-secondary" data-bs-target="#formCarousel"
                                            data-bs-slide="prev">
                                            Previous
                                        </button>
                                        <button type="submit" class="btn btn-success">Submit</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        {{-- <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                        </div> --}}
                    </div>
                </div>
            </div>


        @endsection
