@extends('component.app')
@section('title', 'Edit 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 ps-4 pe-4">
                    <div class="box d-flex align-items-center justify-content-between">
                        <a href="{{ route('pegawai.index') }}" class="ms-5"><i class="bx bx-left-arrow-alt"></i></a>
                        <h4 class="card-header">Edit Data Pegawai</h4>
                    </div>
                    <form action="{{ route('pegawai.update', $data->id) }}" method="POST" enctype="multipart/form-data">
                        @csrf

                        <button type="submit" class="btn btn-primary me-2 btn-sm me-2"><i class="bx bx-save bx-sm"></i>
                            Simpan</button>
                </div>
                <div class="card-body">
                    <div class="row">
                        <!-- Kolom Kiri -->
                        <div class="col-md-4">

                            @if (Auth::user()->role == 'admin' || Auth::user()->role == 'superadmin')
                                <!-- Laundry -->
                                <div class="mb-3">
                                    <label for="laundry_id" class="form-label">Pilih Laundry</label>
                                    <select id="admin" name="laundry_id" required>
                                        <option value="{{ $data->laundry_id }}">{{ $data->laundry->nama_laundry }}</option>
                                        @foreach ($laundry as $laundry)
                                            <option value="{{ $laundry->id }}">{{ $laundry->nama_laundry }}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                            @else
                                <div class="mb-3">
                                    <label for="laundry_id" class="form-label">Laundry</label>
                                    <input type="text" hidden class="form-control form-control-sm" id="laundry_id"
                                        name="laundry_id" placeholder="Masukkan Username" value="{{ $laundry->id }}"
                                        required>
                                    <input type="text" class="form-control form-control-sm" id="laundry_id"
                                        value="{{ $laundry->nama_laundry }}" readonly>
                                </div>
                            @endif
                            <!-- Username -->
                            <div class="mb-3">
                                <label for="username" class="form-label">Username</label>
                                <input type="text" class="form-control form-control-sm" id="username" name="username"
                                    placeholder="Masukkan Username" value="{{ $data->user->username }}" required>
                            </div>

                            <!-- Email -->
                            <div class="mb-3">
                                <label for="email" class="form-label">Email</label>
                                <input type="email" class="form-control form-control-sm" id="email" name="email"
                                    placeholder="Masukkan Email" value="{{ $data->user->email }}" required>
                            </div>

                            <!-- Password -->
                            <div class="mb-3">
                                <label for="password" class="form-label">Password</label>
                                <input type="password" class="form-control form-control-sm" id="password" name="password"
                                    placeholder="Masukkan Password">
                                <span class="text-danger">*Isi jika ingin perbarui password</span>
                            </div>

                            <!-- Phone -->
                            <div class="mb-3">
                                <label for="phone" class="form-label">No. Telp</label>
                                <input type="number" class="form-control form-control-sm" id="phone" name="no_telp"
                                    placeholder="Masukkan No. Telp" value="{{ $data->no_telp }}" required>
                            </div>

                        </div>

                        <!-- Kolom Kanan -->
                        <div class="col-md-4">
                            <!-- Nama -->
                            <div class="mb-3">
                                <label for="nama" class="form-label">Nama</label>
                                <input type="text" class="form-control form-control-sm" id="nama" name="nama"
                                    placeholder="Masukkan Nama" value="{{ $data->nama }}" required>
                            </div>

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

                            <!-- Foto -->
                            <div class="mb-3">
                                <label for="foto" class="form-label">Foto</label>
                                <input type="file" class="form-control form-control-sm" id="foto" name="foto">
                                <span class="text-danger">*Isi jika ingin perbarui foto</span>
                            </div>

                            <div class="mb-3">
                                <img src="{{ asset('storage/img/' . $data->foto) }}" class="img-preview img-fluid mb-3"
                                    width="100px" alt="">
                            </div>

                        </div>



                        <div class="col-md-4">


                            <div class="boxnya">

                                <div class="mb-3">
                                    <label for="status" class="form-label">Gaji Pokok</label>
                                    <input type="text" class="form-control form-control-sm"
                                        value=" {{ $data->gaji_pokok }}">
                                </div>
                                <div class="mb-3">
                                    <label for="status" class="form-label">Komisi Harian</label>
                                    <input type="text" class="form-control form-control-sm"
                                        value="{{ $data->komisi_harian }}">
                                </div>
                                </form>
                                <div class="mb-3">
                                    <div class="box d-flex justify-content-between align-items-center">
                                        <label for="status" class="form-label">List Paket & Komisi</label>
                                        <button type="button" class="bg-white border-0 text-secondary"
                                            data-bs-toggle="modal" data-bs-target="#staticBackdrop"><i
                                                class="bx bx-plus-circle"></i></button>
                                    </div>
                                    @foreach ($paket as $paket)
                                        <div class="box d-flex justify-content-between align-items-center mt-2">

                                            <div class="mb-3 d-flex align-items-start flex-column">
                                                <form action="{{ route('pegawaiPaketUpdate', $paket->id) }}"
                                                    method="POST" style="display: inline;">
                                                    @csrf
                                                    @method('POST')


                                                    <p class="m-0" style="font-size: 12px">
                                                        {{ '*' . $paket->paket->nama_paket . '(' . $paket->paket->satuan . ')' }}
                                                    </p>
                                                    <input type="hidden" name="paket_id"
                                                        value="{{ $paket->paket->id }}">
                                                    <input type="text"
                                                        class=" form-control form-control-sm form-control form-control-sm-sm"
                                                        value="{{ $paket->komisi_paket }}" name="komisi_paket">
                                            </div>
                                            <div class="boxnya d-flex justify-content-center align-items-center">
                                                <button type="submit" class="btn btn-link p-0 m-0 align-baseline">
                                                    <i class="bx bx-check text-warning"></i>
                                                </button>
                                                </form>

                                                <form action="{{ route('pegawaiPaketDestroy', $paket->id) }}"
                                                    method="POST">
                                                    @csrf
                                                    @method('POST')
                                                    <button type="submit" class="bg-white border-0 text-danger"
                                                        onclick="return confirm('Apakah Anda yakin ingin menghapus item ini?')">
                                                        <i class="bx bx-trash"></i>
                                                    </button>
                                                </form>
                                            </div>
                                        </div>
                                    @endforeach
                                </div>



                            </div>

                        </div>
                    </div>

                </div>
            </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-sm">
                <div class="modal-content ">
                    <div class="modal-header">
                        <h5 class="modal-title" id="staticBackdropLabel">Tambah Paket Pegawai</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <form action="{{ route('tambahPaket', $data->id) }}" method="POST"
                            enctype="multipart/form-data">
                            @csrf
                            @php

                                if (Auth::user()->role == 'kepala_toko') {
                                    $akun_login = App\Models\KepalaToko::where('users_id', Auth::user()->id)->first();
                                    $data_paket = App\Models\Paket::where('laundry_id', $akun_login->laundry_id)->get();
                                } else {
                                    $data_paket = [];
                                }

                            @endphp
                            <div class="row">
                                <!-- Kolom Kiri -->
                                <div class="col-md-12">
                                    <div class="mb-3">
                                        <label for="pilih_paket" class="form-label">Kelola Paket</label>
                                        <select id="pelanggan" class="form-select form-control form-control-sm"
                                            name="paket_id[]" multiple="multiple" required style="width: 100%">

                                            @foreach ($data_paket as $paket)
                                                <option value="{{ $paket->id }}">
                                                    {{ $paket->nama_paket }}({{ $paket->satuan }})</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 form-control-sm" id="komisi_perpaket"
                                            name="komisi_perpaket" placeholder="Masukkan Komisi Per Paket" required>
                                    </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
