<?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, []); ?> Pengaturan Sistem <?php $__env->endSlot(); ?>

    
    <?php $__env->startPush('styles'); ?>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
    <?php $__env->stopPush(); ?>

    <div class="max-w-4xl mx-auto py-8 px-4 sm:px-6 lg:px-8 space-y-6">

        <form id="formPengaturan" class="space-y-6">
            <?php echo csrf_field(); ?>

            
            <div class="kkd-card">
                <h2 class="section-title flex items-center gap-2 mb-5">
                    <i class="fas fa-hospital text-teal-500"></i> Profil Klinik
                </h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div class="md:col-span-2">
                        <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">Nama Klinik <span class="text-red-500">*</span></label>
                        <input type="text" name="nama_klinik" required
                               value="<?php echo e($pengaturan['nama_klinik']); ?>"
                               class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none">
                    </div>
                    <div class="md:col-span-2">
                        <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">Alamat Klinik</label>
                        <textarea name="alamat_klinik" rows="2"
                                  class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none"><?php echo e($pengaturan['alamat_klinik']); ?></textarea>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">Telepon Klinik</label>
                        <input type="text" name="telepon_klinik"
                               value="<?php echo e($pengaturan['telepon_klinik']); ?>"
                               placeholder="0812-xxxx-xxxx"
                               class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none">
                    </div>
                </div>
            </div>

            
            <div class="kkd-card">
                <h2 class="section-title flex items-center gap-2 mb-5">
                    <i class="fas fa-thermometer-half text-orange-500"></i> Konfigurasi Batas Suhu
                </h2>
                <div class="grid grid-cols-2 md:grid-cols-3 gap-4">
                    <?php $__currentLoopData = [
                        ['suhu_normal_min',   'Normal Min (°C)',   'text-green-600',  36.0],
                        ['suhu_normal_max',   'Normal Max (°C)',   'text-green-600',  37.5],
                        ['suhu_demam_ringan', 'Demam Ringan (°C)', 'text-yellow-600', 37.6],
                        ['suhu_demam_sedang', 'Demam Sedang (°C)','text-orange-600', 38.5],
                        ['suhu_demam_tinggi', 'Demam Tinggi (°C)','text-red-600',    39.0],
                    ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$name, $label, $color, $default]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div>
                        <label class="block text-sm font-medium <?php echo e($color); ?> mb-1"><?php echo e($label); ?></label>
                        <input type="number" step="0.1" name="<?php echo e($name); ?>" required
                               value="<?php echo e($pengaturan[$name] ?? $default); ?>"
                               class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none">
                    </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
                <p class="text-xs text-slate-500 dark:text-slate-400 mt-3">
                    <i class="fas fa-info-circle"></i>
                    Urutan: Normal → Demam Ringan → Demam Sedang → Demam Tinggi
                </p>
            </div>

            
            <div class="kkd-card">
                <h2 class="section-title flex items-center gap-2 mb-1">
                    <i class="fas fa-robot text-purple-500"></i> Integrasi SiputZX AI
                </h2>
                <p class="section-subtitle mb-5">Layanan AI gratis tanpa memerlukan API Key. Mendukung Gemini 2.0 Flash dan model AI lainnya.</p>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
                    <div>
                        <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">Base URL API</label>
                        <input type="url" name="siputzx_api_url"
                               value="<?php echo e($pengaturan['siputzx_api_url']); ?>"
                               placeholder="https://api.siputzx.my.id"
                               class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none">
                        <p class="text-xs text-slate-500 dark:text-slate-400 mt-1">
                            <i class="fas fa-info-circle"></i> Aktif: <code class="bg-slate-100 dark:bg-slate-700 px-1 rounded text-purple-600 dark:text-purple-300"><?php echo e($pengaturan['siputzx_api_url']); ?></code>
                        </p>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">Model AI</label>
                        <input type="text" name="siputzx_model"
                               value="<?php echo e($pengaturan['siputzx_model']); ?>"
                               placeholder="gemini-2.0-flash-lite"
                               class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none">
                        <p class="text-xs text-slate-500 dark:text-slate-400 mt-1">
                            <i class="fas fa-info-circle"></i> Model yang digunakan: <code class="bg-slate-100 dark:bg-slate-700 px-1 rounded text-purple-600 dark:text-purple-300"><?php echo e($pengaturan['siputzx_model']); ?></code>
                        </p>
                    </div>
                </div>
                <div class="p-3 rounded-lg bg-slate-50 dark:bg-slate-700/50 border border-slate-200 dark:border-slate-600">
                    <div class="flex items-center justify-between">
                        <p class="text-sm font-medium text-slate-700 dark:text-slate-300">
                            <i class="fas fa-vial text-purple-400"></i> Test Koneksi AI
                        </p>
                        <button type="button" onclick="apiTest('<?php echo e(route('admin.pengaturan.test-ai')); ?>', {}, 'siputzx_test_result')"
                                class="px-4 py-2 bg-purple-500 hover:bg-purple-600 text-white text-sm font-medium rounded-lg transition-colors">
                            <i class="fas fa-play mr-1"></i> Test
                        </button>
                    </div>
                    <p id="siputzx_test_result" class="text-xs mt-2 hidden"></p>
                </div>
            </div>

            
            <div class="kkd-card">
                <h2 class="section-title flex items-center gap-2 mb-1">
                    <i class="fas fa-user-circle text-blue-500"></i> Face Recognition AI (Python Flask)
                </h2>
                <p class="section-subtitle mb-5">Server Python untuk ekstraksi dan pengenalan wajah pasien.</p>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">URL Server Face AI</label>
                    <input type="url" name="face_ai_url"
                           value="<?php echo e($pengaturan['face_ai_url']); ?>"
                           placeholder="http://127.0.0.1:5000"
                           class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none">
                    <p class="text-xs text-slate-500 dark:text-slate-400 mt-1">
                        Aktif: <code class="bg-slate-100 dark:bg-slate-700 px-1 rounded text-teal-600 dark:text-teal-300"><?php echo e($pengaturan['face_ai_url']); ?></code>
                    </p>
                </div>
                <div class="p-3 rounded-lg bg-slate-50 dark:bg-slate-700/50 border border-slate-200 dark:border-slate-600">
                    <div class="flex items-center justify-between">
                        <p class="text-sm font-medium text-slate-700 dark:text-slate-300">
                            <i class="fas fa-plug text-blue-400"></i> Test Koneksi Flask Server
                        </p>
                        <button type="button" onclick="apiTest('<?php echo e(route('admin.pengaturan.test-face-ai')); ?>', {}, 'faceai_test_result')"
                                class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white text-sm font-medium rounded-lg transition-colors">
                            <i class="fas fa-plug mr-1"></i> Test
                        </button>
                    </div>
                    <p id="faceai_test_result" class="text-xs mt-2 hidden"></p>
                </div>
            </div>

            
            <div class="kkd-card">
                <h2 class="section-title flex items-center gap-2 mb-1">
                    <i class="fab fa-whatsapp text-green-500"></i> Integrasi WhatsApp (Fonnte)
                </h2>
                <p class="section-subtitle mb-5">Untuk mengirim notifikasi hasil pemeriksaan ke pasien via WhatsApp.</p>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
                    <div>
                        <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">API Key Fonnte</label>
                        <div class="relative">
                            <input type="text" name="whatsapp_api_key" id="whatsapp_api_key"
                                   value="<?php echo e($pengaturan['whatsapp_api_key']); ?>"
                                   placeholder="Masukkan Fonnte API Key..."
                                   class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 pr-10 text-sm focus:ring-2 focus:ring-teal-500 outline-none font-mono">
                            <button type="button" onclick="toggleVisibility('whatsapp_api_key', this)"
                                    class="absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 dark:hover:text-slate-200">
                                <i class="fas fa-eye-slash text-sm"></i>
                            </button>
                        </div>
                        <?php if($pengaturan['whatsapp_api_key']): ?>
                            <p class="text-xs text-green-600 dark:text-green-400 mt-1"><i class="fas fa-check-circle"></i> API Key tersimpan</p>
                        <?php else: ?>
                            <p class="text-xs text-orange-500 mt-1"><i class="fas fa-exclamation-circle"></i> Belum dikonfigurasi</p>
                        <?php endif; ?>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">Nomor Pengirim (Sender)</label>
                        <input type="text" name="whatsapp_sender"
                               value="<?php echo e($pengaturan['whatsapp_sender']); ?>"
                               placeholder="628xxxxxxxxxx"
                               class="w-full rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm focus:ring-2 focus:ring-teal-500 outline-none">
                    </div>
                </div>
                <div class="p-3 rounded-lg bg-slate-50 dark:bg-slate-700/50 border border-slate-200 dark:border-slate-600">
                    <p class="text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
                        <i class="fas fa-vial text-green-400"></i> Test Kirim Pesan WhatsApp
                    </p>
                    <div class="flex gap-2">
                        <input type="text" id="nomor_test_wa" placeholder="628xxxxxxxxxx"
                               class="flex-1 rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-800 dark:text-slate-100 px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-teal-500">
                        <button type="button" onclick="testWhatsapp()"
                                class="px-4 py-2 bg-green-500 hover:bg-green-600 text-white text-sm font-medium rounded-lg transition-colors whitespace-nowrap">
                            <i class="fab fa-whatsapp mr-1"></i> Test
                        </button>
                    </div>
                    <p id="wa_test_result" class="text-xs mt-2 hidden"></p>
                </div>
            </div>

            
            <div class="flex justify-end pb-8">
                <button type="submit" id="btnSimpan"
                        class="px-8 py-2.5 bg-teal-600 hover:bg-teal-700 text-white font-semibold rounded-lg shadow transition-colors flex items-center gap-2">
                    <i class="fas fa-save"></i> Simpan Pengaturan
                </button>
            </div>
        </form>
    </div>

    <?php $__env->startPush('scripts'); ?>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script>
        const CSRF = '<?php echo e(csrf_token()); ?>';

        // ===== Toggle show/hide API key =====
        function toggleVisibility(fieldId, btn) {
            const input = document.getElementById(fieldId);
            const icon  = btn.querySelector('i');
            if (input.type === 'password') {
                input.type = 'text';
                icon.className = 'fas fa-eye text-sm';
            } else {
                input.type = 'password';
                icon.className = 'fas fa-eye-slash text-sm';
            }
        }

        // ===== Submit form pakai AJAX + SweetAlert2 =====
        document.getElementById('formPengaturan').addEventListener('submit', function(e) {
            e.preventDefault();

            const btn = document.getElementById('btnSimpan');
            btn.disabled = true;
            btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Menyimpan...';

            const formData = new FormData(this);
            formData.append('_method', 'PUT');

            fetch('<?php echo e(route("admin.pengaturan.update")); ?>', {
                method: 'POST',
                headers: { 'X-CSRF-TOKEN': CSRF },
                body: formData,
            })
            .then(r => r.json())
            .then(data => {
                btn.disabled = false;
                btn.innerHTML = '<i class="fas fa-save"></i> Simpan Pengaturan';

                if (data.success) {
                    Swal.fire({
                        icon: 'success',
                        title: 'Berhasil!',
                        text: data.message,
                        confirmButtonColor: '#0d9488',
                        confirmButtonText: 'OK',
                        timer: 3000,
                        timerProgressBar: true,
                        showClass: {
                            popup: 'animate__animated animate__fadeInDown'
                        },
                        hideClass: {
                            popup: 'animate__animated animate__fadeOutUp'
                        }
                    });
                } else {
                    Swal.fire({
                        icon: 'error',
                        title: 'Gagal!',
                        text: data.message ?? 'Terjadi kesalahan.',
                        confirmButtonColor: '#ef4444',
                    });
                }
            })
            .catch(err => {
                btn.disabled = false;
                btn.innerHTML = '<i class="fas fa-save"></i> Simpan Pengaturan';
                Swal.fire({
                    icon: 'error',
                    title: 'Error!',
                    text: 'Gagal terhubung ke server. Coba lagi.',
                    confirmButtonColor: '#ef4444',
                });
            });
        });

        // ===== API Test helper =====
        function apiTest(url, body, resultId) {
            const el = document.getElementById(resultId);
            el.className = 'text-xs mt-2 text-slate-500';
            el.textContent = 'Menguji koneksi...';
            el.classList.remove('hidden');

            fetch(url, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': CSRF },
                body: JSON.stringify(body)
            })
            .then(r => r.json())
            .then(data => {
                el.className = data.success
                    ? 'text-xs mt-2 text-green-600 dark:text-green-400'
                    : 'text-xs mt-2 text-red-600 dark:text-red-400';
                el.textContent = (data.success ? '✅ ' : '❌ ') + data.message;

                // Popup kecil juga
                const Toast = Swal.mixin({
                    toast: true,
                    position: 'top-end',
                    showConfirmButton: false,
                    timer: 3000,
                    timerProgressBar: true,
                });
                Toast.fire({
                    icon: data.success ? 'success' : 'error',
                    title: data.message
                });
            })
            .catch(() => {
                el.className = 'text-xs mt-2 text-red-600';
                el.textContent = '❌ Gagal terhubung ke server.';
            });
        }

        // ===== Test WhatsApp =====
        function testWhatsapp() {
            const nomor = document.getElementById('nomor_test_wa').value;
            if (!nomor) {
                Swal.fire({ icon: 'warning', title: 'Input diperlukan', text: 'Masukkan nomor tujuan test terlebih dahulu.', confirmButtonColor: '#0d9488' });
                return;
            }
            apiTest('<?php echo e(route("admin.pengaturan.test-whatsapp")); ?>', { nomor_test: nomor }, 'wa_test_result');
        }
    </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/admin/pengaturan/index.blade.php ENDPATH**/ ?>