<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <div class="flex items-center justify-between">
            <div class="flex items-center">
                <a href="<?php echo e(route('petugas.pasien.show', $pasien->id)); ?>" class="text-teal-500 hover:text-teal-700 mr-4">
                    <i class="fas fa-arrow-left"></i>
                </a>
                <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
                    Assign Dokter ke Pasien: <?php echo e($pasien->nama_lengkap); ?>

                </h2>
            </div>
        </div>
     <?php $__env->endSlot(); ?>

    <div class="py-12">
        <div class="max-w-4xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white dark:bg-slate-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <!-- Info Pasien -->
                    <div class="mb-8 p-4 bg-blue-50 dark:bg-slate-700 rounded-lg border border-blue-100 dark:border-slate-600">
                        <div class="flex items-center">
                            <i class="fas fa-info-circle text-blue-500 dark:text-blue-400 text-xl mr-3"></i>
                            <div>
                                <p class="font-medium text-blue-700 dark:text-blue-300">Informasi Pasien</p>
                                <div class="flex items-center space-x-4 mt-1">
                                    <span class="text-sm text-gray-600 dark:text-gray-400">No. RM: <?php echo e($pasien->no_rekam_medis); ?></span>
                                    <span class="text-sm text-gray-600 dark:text-gray-400">NIK: <?php echo e($pasien->nik ?: '-'); ?></span>
                                    <span class="text-sm px-2 py-1 rounded-full <?php echo e($pasien->status_pasien == 'AKTIF' ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200' : 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200'); ?>">
                                        <?php echo e($pasien->status_pasien); ?>

                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Alert Errors / Session Error -->
                    <?php if(session('error')): ?>
                        <div class="mb-6 p-4 bg-red-50 dark:bg-red-900/30 border-l-4 border-red-500 rounded-lg">
                            <div class="flex items-center">
                                <i class="fas fa-exclamation-circle text-red-500 mr-3"></i>
                                <span class="text-red-700 dark:text-red-300"><?php echo e(session('error')); ?></span>
                            </div>
                        </div>
                    <?php endif; ?>

                    <?php if($errors->any()): ?>
                        <div class="mb-6 p-4 bg-red-50 dark:bg-red-900/30 border-l-4 border-red-500 rounded-lg">
                            <div class="flex">
                                <i class="fas fa-exclamation-circle text-red-500 mr-3 mt-0.5"></i>
                                <div class="text-red-700 dark:text-red-300">
                                    <span class="font-medium">Terdapat kesalahan:</span>
                                    <ul class="mt-1 list-disc list-inside text-sm">
                                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <li><?php echo e($error); ?></li>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>

                    <?php if(isset($existing) && $existing): ?>
                        <div class="mb-6 p-4 bg-yellow-50 dark:bg-yellow-900/30 border-l-4 border-yellow-500 rounded-lg">
                            <div class="flex">
                                <i class="fas fa-info-circle text-yellow-600 dark:text-yellow-400 mt-0.5 mr-3"></i>
                                <div>
                                    <h4 class="text-sm font-semibold text-yellow-800 dark:text-yellow-300">Pasien Dalam Antrean</h4>
                                    <p class="text-sm text-yellow-700 dark:text-yellow-400 mt-1">
                                        Pasien ini saat ini sedang dalam antrean <strong><?php echo e($existing->dokter->nama_lengkap); ?> (<?php echo e($existing->dokter->spesialisasi); ?>)</strong>.
                                        Jika Anda melanjutkan, Anda akan memindahkan pasien ini ke dokter baru (Pindah Dokter).
                                    </p>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>

                    <form id="formAssign" action="<?php echo e(route('petugas.pasien.assign.store', $pasien->id)); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        
                        <div class="space-y-6">
                            <!-- Pilih Dokter -->
                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Pilih Dokter <span class="text-red-500">*</span>
                                </label>
                                <select name="dokter_id" id="dokter_id" required 
                                        class="w-full px-4 py-3 border border-gray-300 dark:border-slate-600 dark:bg-slate-700 dark:text-white rounded-lg focus:border-teal-500 focus:ring-teal-500 transition">
                                    <option value="">-- Pilih Dokter --</option>
                                    <?php $__currentLoopData = $dokters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dokter): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($dokter->id); ?>">
                                            <?php echo e($dokter->kode_dokter); ?> - <?php echo e($dokter->nama_lengkap); ?>

                                            (<?php echo e($dokter->spesialisasi); ?>)
                                            <?php if($dokter->hari_praktik): ?>
                                                - Praktik: <?php echo e(implode(', ', is_array($dokter->hari_praktik) ? $dokter->hari_praktik : json_decode($dokter->hari_praktik, true))); ?>

                                            <?php endif; ?>
                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
                                    Pilih dokter yang akan menangani pasien ini
                                </p>
                            </div>

                            <!-- Diagnosis Awal -->
                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Diagnosis Awal (Optional)
                                </label>
                                <textarea name="diagnosis_utama" rows="3"
                                          class="w-full px-4 py-3 border border-gray-300 dark:border-slate-600 dark:bg-slate-700 dark:text-white rounded-lg focus:border-teal-500 focus:ring-teal-500 transition"
                                          placeholder="Masukkan diagnosis awal jika ada"></textarea>
                                <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
                                    Diagnosis sementara atau alasan assign ke dokter
                                </p>
                            </div>

                            <!-- Informasi Tambahan -->
                            <div class="bg-gray-50 dark:bg-slate-700 p-4 rounded-lg">
                                <div class="flex items-center mb-3">
                                    <i class="fas fa-lightbulb text-yellow-500 dark:text-yellow-400 mr-2"></i>
                                    <p class="font-medium text-gray-700 dark:text-gray-300">Tips:</p>
                                </div>
                                <ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 dark:text-green-400 mr-2 mt-1"></i>
                                        <span>Pastikan dokter yang dipilih sesuai dengan spesialisasi yang dibutuhkan pasien</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 dark:text-green-400 mr-2 mt-1"></i>
                                        <span>Periksa jadwal praktik dokter sebelum menugaskan</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 dark:text-green-400 mr-2 mt-1"></i>
                                        <span>Notifikasi akan dikirim ke dokter tentang pasien baru</span>
                                    </li>
                                </ul>
                            </div>

                            <!-- Tombol Aksi -->
                            <div class="flex justify-between items-center pt-6 border-t dark:border-slate-700">
                                <div>
                                    <p class="text-sm text-gray-500 dark:text-gray-400">
                                        <i class="fas fa-shield-alt text-teal-500 mr-1"></i>
                                        Data penanganan akan dicatat dalam riwayat pasien
                                    </p>
                                </div>
                                <div class="flex space-x-3">
                                    <a href="<?php echo e(route('petugas.pasien.show', $pasien->id)); ?>" 
                                       class="px-6 py-3 border border-gray-300 dark:border-slate-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-slate-700 transition">
                                        Batal
                                    </a>
                                    <button type="submit" 
                                            class="px-6 py-3 bg-teal-500 hover:bg-teal-600 text-white rounded-lg transition flex items-center">
                                        <i class="fas <?php echo e(isset($existing) && $existing ? 'fa-exchange-alt' : 'fa-user-md'); ?> mr-2"></i> 
                                        <?php echo e(isset($existing) && $existing ? 'Pindah Dokter' : 'Assign Dokter'); ?>

                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <!-- List Dokter Tersedia -->
            <div class="mt-8">
                <h3 class="text-lg font-semibold mb-4 text-gray-800 dark:text-gray-200">Dokter Tersedia</h3>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <?php $__currentLoopData = $dokters->take(4); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dokter): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="bg-white dark:bg-slate-800 border border-gray-200 dark:border-slate-700 rounded-lg p-4">
                            <div class="flex items-center">
                                <?php if($dokter->foto_profil): ?>
                                    <img src="<?php echo e(asset('storage/' . $dokter->foto_profil)); ?>" 
                                         alt="Foto Dokter" 
                                         class="w-12 h-12 rounded-full mr-3">
                                <?php else: ?>
                                    <div class="w-12 h-12 bg-gray-200 dark:bg-slate-700 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-user-md text-gray-400 dark:text-slate-500"></i>
                                    </div>
                                <?php endif; ?>
                                <div class="flex-1">
                                    <p class="font-medium text-gray-800 dark:text-gray-200"><?php echo e($dokter->nama_lengkap); ?></p>
                                    <p class="text-sm text-gray-500 dark:text-gray-400"><?php echo e($dokter->spesialisasi); ?></p>
                                    <div class="flex items-center mt-1">
                                        <span class="text-xs px-2 py-1 rounded-full bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200">
                                            <?php echo e($dokter->status_dokter); ?>

                                        </span>
                                        <?php if($dokter->hari_praktik): ?>
                                            <span class="text-xs text-gray-500 dark:text-gray-400 ml-2">
                                                <?php echo e(implode(', ', array_slice(is_array($dokter->hari_praktik) ? $dokter->hari_praktik : json_decode($dokter->hari_praktik, true), 0, 2))); ?>

                                            </span>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
        </div>
    </div>

<?php $__env->startPush('styles'); ?>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<style>
    /* Styling Select2 untuk menyesuaikan dengan Tailwind & Dark Mode */
    .select2-container .select2-selection--single {
        height: 48px; /* py-3 size */
        border-color: #d1d5db; /* gray-300 */
        border-radius: 0.5rem; /* rounded-lg */
        display: flex;
        align-items: center;
    }
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: normal;
        padding-left: 1rem;
        color: #374151;
    }
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 46px;
        right: 10px;
    }
    
    /* Dark Mode Select2 */
    .dark .select2-container .select2-selection--single {
        background-color: #334155; /* slate-700 */
        border-color: #475569; /* slate-600 */
    }
    .dark .select2-container--default .select2-selection--single .select2-selection__rendered {
        color: #ffffff;
    }
    .dark .select2-dropdown {
        background-color: #334155;
        border-color: #475569;
        color: #ffffff;
    }
    .dark .select2-search input {
        background-color: #1e293b;
        color: #ffffff;
        border-color: #475569;
    }
    .dark .select2-results__option--selected {
        background-color: #475569 !important;
    }
    .dark .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
        background-color: #14b8a6; /* teal-500 */
        color: white;
    }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startPush('scripts'); ?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
    $(document).ready(function() {
        // Initialize Select2
        $('#dokter_id').select2({
            placeholder: '-- Pilih Dokter --',
            allowClear: true,
            width: '100%'
        });
    });

    const form = document.getElementById('formAssign');
    form.addEventListener('submit', function(e) {
        e.preventDefault();

        // Ambil value dari select2 (bisa pakai jQuery atau native)
        const dokterValue = $('#dokter_id').val();
        if (!dokterValue) {
            Swal.fire({
                title: 'Pilih Dokter',
                text: 'Silakan pilih dokter terlebih dahulu dari daftar',
                icon: 'warning',
                confirmButtonColor: '#14b8a6',
                background: document.documentElement.classList.contains('dark') ? '#1e293b' : '#fff',
                color: document.documentElement.classList.contains('dark') ? '#fff' : '#000',
            });
            return;
        }

        Swal.fire({
            title: '<?php echo e(isset($existing) && $existing ? "Pindah Dokter?" : "Assign Dokter?"); ?>',
            html: `<?php echo isset($existing) && $existing 
                ? "Anda akan memindahkan pasien <strong>". addslashes($pasien->nama_lengkap) ."</strong> dari <strong>". addslashes($existing->dokter->nama_lengkap) ."</strong> ke dokter baru." 
                : "Anda akan menugaskan dokter kepada <strong>". addslashes($pasien->nama_lengkap) ."</strong>"; ?>`,
            icon: 'question',
            showCancelButton: true,
            confirmButtonColor: '#14b8a6',
            cancelButtonColor: '#ef4444',
            confirmButtonText: 'Ya, Lanjutkan',
            cancelButtonText: 'Batal',
            background: document.documentElement.classList.contains('dark') ? '#1e293b' : '#fff',
            color: document.documentElement.classList.contains('dark') ? '#fff' : '#000',
        }).then((result) => {
            if (result.isConfirmed) {
                form.submit();
            }
        });
    });
</script>
<?php $__env->stopPush(); ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?><?php /**PATH C:\laragon\www\KESEHATAN\resources\views/petugas/pasien/assign.blade.php ENDPATH**/ ?>