<?php $__env->startSection('title', 'WhatsApp Gateway & Absensi Lokasi'); ?>
<?php $__env->startSection('page-title', 'WhatsApp Gateway & Otomasi Absensi Lokasi'); ?>
<?php $__env->startSection('page-subtitle', 'Karyawan cukup kirimkan Share Location via WhatsApp — sistem otomatis mengenali identitas, mencatat presensi, dan membalas.'); ?>

<?php $__env->startSection('content'); ?>

<div class="card shadow-sm border-0 mb-4 bg-gradient text-white" style="background: linear-gradient(135deg, #128C7E 0%, #075E54 100%);">
    <div class="card-body p-4">
        <div class="row align-items-center">
            <div class="col-md-8">
                <div class="d-flex align-items-center mb-2">
                    <div class="badge bg-white text-success px-3 py-2 fs-6 rounded-pill me-2">
                        <i class="bi bi-geo-alt-fill me-1"></i> Otomasi Absensi via WhatsApp
                    </div>
                    <span class="badge bg-warning text-dark px-3 py-2 rounded-pill">Tanpa Ketik Nama / Status</span>
                </div>
                <h4 class="fw-bold mb-2 text-white">Cukup Kirimkan Share Location dari WhatsApp</h4>
                <p class="mb-0 text-white-50 fs-6">
                    Pegawai hanya perlu membagikan <strong>Lokasi Terkini (Share Location)</strong> via WhatsApp ke nomor gateway. Sistem backend otomatis membaca nomor pengirim, mengenali identitas & NIK pegawai, menghitung radius GPS ke kantor terdekat, mencatat jam masuk/pulang, dan mengirim balasan konfirmasi secara instan!
                </p>
            </div>
            <div class="col-md-4 text-md-end mt-3 mt-md-0">
                <div class="bg-white bg-opacity-10 p-3 rounded-3 text-start border border-white border-opacity-25">
                    <small class="text-white-50 d-block mb-1 fw-bold"><i class="bi bi-link-45deg me-1"></i> Fonnte Webhook URL:</small>
                    <div class="input-group input-group-sm">
                        <input type="text" class="form-control form-control-sm bg-white text-dark font-monospace" value="<?php echo e(url('/api/whatsapp/webhook')); ?>" id="webhookUrlInput" readonly>
                        <button class="btn btn-warning btn-sm" type="button" onclick="navigator.clipboard.writeText(document.getElementById('webhookUrlInput').value); Swal.fire({icon: 'success', title: 'Tersalin!', text: 'Webhook URL berhasil disalin ke clipboard.', timer: 1500, showConfirmButton: false});">
                            <i class="bi bi-clipboard"></i> Salin
                        </button>
                    </div>
                    <small class="text-white-50 mt-1 d-block" style="font-size: 11px;">Tempel URL ini di menu Webhook dashboard Fonnte.</small>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    
    <div class="col-12 col-lg-7 mb-4">
        <div class="card shadow-sm border-0 h-100">
            <div class="card-header bg-white py-3 border-bottom d-flex justify-content-between align-items-center">
                <h5 class="card-title mb-0 fw-bold"><i class="bi bi-sliders text-success me-2"></i> Konfigurasi Gateway & Notifikasi</h5>
                <span class="badge bg-success bg-opacity-10 text-success px-3 py-2 rounded-pill">Fonnte Connected</span>
            </div>
            <form action="<?php echo e(route('admin.whatsapp.update')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>
                <div class="card-body p-4">
                    <div class="form-check form-switch p-3 bg-light rounded-3 mb-4 border">
                        <input class="form-check-input ms-0 me-3" type="checkbox" name="whatsapp_enabled" value="true" id="waEnabled" <?php echo e(($settings['whatsapp_enabled'] ?? 'true') === 'true' ? 'checked' : ''); ?>>
                        <label class="form-check-label fw-bold" for="waEnabled">
                            Aktifkan WhatsApp Gateway & Auto-Reply
                            <small class="d-block text-muted fw-normal">Otomatisasi balasan saat karyawan share lokasi, notifikasi check-in, check-out, dan keterlambatan.</small>
                        </label>
                    </div>

                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label fw-bold">Provider Gateway</label>
                            <select name="whatsapp_provider" class="form-select">
                                <option value="fonnte" <?php echo e(($settings['whatsapp_provider'] ?? 'fonnte') == 'fonnte' ? 'selected' : ''); ?>>Fonnte (Rekomendasi)</option>
                                <option value="generic" <?php echo e(($settings['whatsapp_provider'] ?? '') == 'generic' ? 'selected' : ''); ?>>Generic HTTP API</option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">Waktu Reminder Absen Pagi</label>
                            <input type="time" name="whatsapp_reminder_time" class="form-control" value="<?php echo e($settings['whatsapp_reminder_time'] ?? '08:30'); ?>">
                        </div>

                        <div class="col-12">
                            <label class="form-label fw-bold">Template Pesan Notifikasi Masuk (Check-In)</label>
                            <textarea name="whatsapp_template_checkin" class="form-control" rows="2"><?php echo e($settings['whatsapp_template_checkin'] ?? "{nama}\nmasuk"); ?></textarea>
                            <small class="text-muted">Placeholder: <code>{nama}</code>, <code>{tanggal}</code>, <code>{jam}</code>, <code>{status}</code>, <code>{jarak}</code></small>
                        </div>

                        <div class="col-12">
                            <label class="form-label fw-bold">Template Pesan Notifikasi Pulang (Check-Out)</label>
                            <textarea name="whatsapp_template_checkout" class="form-control" rows="2"><?php echo e($settings['whatsapp_template_checkout'] ?? "{nama}\npulang"); ?></textarea>
                            <small class="text-muted">Placeholder: <code>{nama}</code>, <code>{tanggal}</code>, <code>{jam}</code></small>
                        </div>

                        <div class="col-12">
                            <label class="form-label fw-bold">Template Pesan Keterlambatan</label>
                            <textarea name="whatsapp_template_late" class="form-control" rows="2"><?php echo e($settings['whatsapp_template_late'] ?? "{nama}\nterlambat {jumlah_menit} menit"); ?></textarea>
                            <small class="text-muted">Placeholder: <code>{nama}</code>, <code>{tanggal}</code>, <code>{jam}</code>, <code>{jumlah_menit}</code></small>
                        </div>
                    </div>
                </div>
                <div class="card-footer bg-light p-3 text-end border-top">
                    <button type="submit" class="btn btn-primary px-4"><i class="bi bi-save me-1"></i> Simpan Konfigurasi</button>
                </div>
            </form>
        </div>
    </div>

    
    <div class="col-12 col-lg-5">
        
        <div class="card shadow-sm border-0 mb-4">
            <div class="card-header bg-white py-3 border-bottom">
                <h5 class="card-title mb-0 fw-bold"><i class="bi bi-send-check text-primary me-2"></i> Uji Coba Kirim Pesan (Test Send)</h5>
            </div>
            <form action="<?php echo e(route('admin.whatsapp.test-send')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="card-body p-4">
                    <div class="mb-3">
                        <label class="form-label fw-bold">Nomor WhatsApp Tujuan</label>
                        <input type="text" name="test_phone" class="form-control" placeholder="085196026704" value="<?php echo e(config('services.whatsapp.sender_phone')); ?>" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold">Isi Pesan Uji Coba</label>
                        <textarea name="test_message" class="form-control" rows="2" required>Halo, ini adalah pesan uji coba dari Sistem Absensi Karyawan PT Inovasi Digital Nusantara.</textarea>
                    </div>
                    <button type="submit" class="btn btn-success w-100 shadow-sm">
                        <i class="bi bi-whatsapp me-1"></i> Kirim Pesan Uji Coba
                    </button>
                </div>
            </form>
        </div>

        
        <div class="card shadow-sm border-0">
            <div class="card-header bg-white py-3 border-bottom d-flex justify-content-between align-items-center">
                <h6 class="card-title mb-0 fw-bold"><i class="bi bi-clock-history me-1 text-secondary"></i> Log Pesan WhatsApp Terakhir</h6>
                <a href="<?php echo e(route('admin.notification-logs.index')); ?>" class="btn btn-outline-primary btn-sm py-0 px-2 text-xs">Lihat Semua</a>
            </div>
            <div class="card-body p-0">
                <div class="list-group list-group-flush">
                    <?php $__empty_1 = true; $__currentLoopData = $recentLogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="list-group-item p-3">
                            <div class="d-flex justify-content-between align-items-center mb-1">
                                <span class="fw-bold text-xs"><?php echo e($log->recipient); ?> (<?php echo e($log->employee?->name ?? 'Pengguna'); ?>)</span>
                                <?php if($log->status === 'sent'): ?>
                                    <span class="badge bg-success">Terkirim</span>
                                <?php else: ?>
                                    <span class="badge bg-danger">Gagal</span>
                                <?php endif; ?>
                            </div>
                            <p class="text-xs text-muted mb-0 text-truncate font-monospace"><?php echo e($log->message); ?></p>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p class="text-muted text-center py-3 mb-0 text-xs">Belum ada riwayat pengiriman.</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\absensi\resources\views/admin/whatsapp/index.blade.php ENDPATH**/ ?>