<?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>
                <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                    Settings Manager
                </h2>
                <p class="text-xs text-gray-400 mt-0.5">Configure system-wide SMTP settings and business-scoped preferences</p>
            </div>
        </div>
     <?php $__env->endSlot(); ?>

    <div class="py-12" x-data="{ 
        tab: 'business',
        testing: false,
        async testSmtp() {
            const emailInput = document.getElementById('test_email');
            const email = emailInput ? emailInput.value.trim() : '';
            if (!email) {
                alert('Please enter a recipient email address.');
                return;
            }
            this.testing = true;
            notify('Testing SMTP Connection...', 'info');
            try {
                const res = await apiFetch('<?php echo e(route("settings.test-smtp")); ?>', {
                    method: 'POST',
                    body: {
                        test_email: email,
                        mail_host: document.querySelector('[name=mail_host]').value,
                        mail_port: document.querySelector('[name=mail_port]').value,
                        mail_username: document.querySelector('[name=mail_username]').value,
                        mail_password: document.querySelector('[name=mail_password]').value,
                        mail_encryption: document.querySelector('[name=mail_encryption]').value,
                        mail_from_address: document.querySelector('[name=mail_from_address]').value,
                        mail_from_name: document.querySelector('[name=mail_from_name]').value,
                    }
                });
                if (res.success) {
                    notify(res.message, 'success');
                } else {
                    notify(res.message || 'SMTP Test failed.', 'error');
                }
            } catch (e) {
                notify(e.message || 'SMTP Connection failed.', 'error');
            } finally {
                this.testing = false;
            }
        }
    }">
        <div class="max-w-4xl mx-auto sm:px-6 lg:px-8">
            
            <?php if(session('success')): ?>
                <div class="mb-6 p-4 bg-emerald-50 border border-emerald-200 text-emerald-800 rounded-xl flex items-center gap-3">
                    <svg class="w-5 h-5 text-emerald-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                    </svg>
                    <span class="text-sm font-medium"><?php echo e(session('success')); ?></span>
                </div>
            <?php endif; ?>

            <?php if($errors->any()): ?>
                <div class="mb-6 p-4 bg-rose-50 border border-rose-200 text-rose-800 rounded-xl shadow-sm">
                    <div class="font-semibold text-sm text-rose-900 mb-2">Please correct the following errors:</div>
                    <ul class="list-disc list-inside text-xs text-rose-700 space-y-1">
                        <?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>
            <?php endif; ?>

            <!-- Navigation Tabs -->
            <div class="flex border-b border-gray-200 mb-6 gap-2">
                <button @click="tab = 'business'" type="button"
                        :class="tab === 'business' ? 'border-indigo-600 text-indigo-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'"
                        class="py-2.5 px-4 border-b-2 font-medium text-sm transition focus:outline-none">
                    General Settings
                </button>
                <button @click="tab = 'smtp'" type="button"
                        :class="tab === 'smtp' ? 'border-indigo-600 text-indigo-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'"
                        class="py-2.5 px-4 border-b-2 font-medium text-sm transition focus:outline-none">
                    SMTP Settings
                </button>
                <button @click="tab = 'cron'" type="button"
                        :class="tab === 'cron' ? 'border-indigo-600 text-indigo-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'"
                        class="py-2.5 px-4 border-b-2 font-medium text-sm transition focus:outline-none">
                    Cron Scheduler
                </button>
            </div>

            <form action="<?php echo e(route('settings.update')); ?>" method="POST" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>

                <!-- General Settings Tab -->
                <div x-show="tab === 'business'" class="space-y-6">
                    <div class="bg-white rounded-2xl border border-gray-100 p-6 shadow-sm">
                        <h3 class="text-sm font-bold text-gray-800 uppercase tracking-wider mb-4">Precision & Formatting</h3>
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Currency Decimal Precision</label>
                                <select name="currency_precision" class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400">
                                    <option value="0" <?php echo e($businessSettings['currency_precision'] == '0' ? 'selected' : ''); ?>>0 Decimals (e.g. Rs. 100)</option>
                                    <option value="1" <?php echo e($businessSettings['currency_precision'] == '1' ? 'selected' : ''); ?>>1 Decimal (e.g. Rs. 100.0)</option>
                                    <option value="2" <?php echo e($businessSettings['currency_precision'] == '2' ? 'selected' : ''); ?>>2 Decimals (e.g. Rs. 100.00)</option>
                                    <option value="3" <?php echo e($businessSettings['currency_precision'] == '3' ? 'selected' : ''); ?>>3 Decimals (e.g. Rs. 100.000)</option>
                                    <option value="4" <?php echo e($businessSettings['currency_precision'] == '4' ? 'selected' : ''); ?>>4 Decimals (e.g. Rs. 100.0000)</option>
                                </select>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Quantity Decimal Precision</label>
                                <select name="quantity_precision" class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400">
                                    <option value="0" <?php echo e($businessSettings['quantity_precision'] == '0' ? 'selected' : ''); ?>>0 Decimals (e.g. 10)</option>
                                    <option value="1" <?php echo e($businessSettings['quantity_precision'] == '1' ? 'selected' : ''); ?>>1 Decimal (e.g. 10.0)</option>
                                    <option value="2" <?php echo e($businessSettings['quantity_precision'] == '2' ? 'selected' : ''); ?>>2 Decimals (e.g. 10.00)</option>
                                    <option value="3" <?php echo e($businessSettings['quantity_precision'] == '3' ? 'selected' : ''); ?>>3 Decimals (e.g. 10.000)</option>
                                    <option value="4" <?php echo e($businessSettings['quantity_precision'] == '4' ? 'selected' : ''); ?>>4 Decimals (e.g. 10.0000)</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="bg-white rounded-2xl border border-gray-100 p-6 shadow-sm">
                        <h3 class="text-sm font-bold text-gray-800 uppercase tracking-wider mb-4">Localization & Output</h3>
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Business Timezone</label>
                                <select name="timezone" class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400">
                                    <option value="Asia/Karachi" <?php echo e($businessSettings['timezone'] == 'Asia/Karachi' ? 'selected' : ''); ?>>Asia/Karachi (PKT)</option>
                                    <option value="UTC" <?php echo e($businessSettings['timezone'] == 'UTC' ? 'selected' : ''); ?>>UTC</option>
                                    <option value="Europe/London" <?php echo e($businessSettings['timezone'] == 'Europe/London' ? 'selected' : ''); ?>>Europe/London (GMT)</option>
                                    <option value="Asia/Dubai" <?php echo e($businessSettings['timezone'] == 'Asia/Dubai' ? 'selected' : ''); ?>>Asia/Dubai</option>
                                </select>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Invoice Number Prefix</label>
                                <input type="text" name="invoice_prefix" value="<?php echo e($businessSettings['invoice_prefix']); ?>"
                                       class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400"
                                       placeholder="INV-">
                            </div>
                        </div>

                        <div class="mt-6 border-t border-gray-100 pt-6">
                            <label class="flex items-center gap-3 cursor-pointer select-none">
                                <input type="hidden" name="show_symbol_rs" value="0">
                                <input type="checkbox" name="show_symbol_rs" value="1" <?php echo e($businessSettings['show_symbol_rs'] == '1' ? 'checked' : ''); ?>

                                       class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                                <div>
                                    <span class="text-sm font-semibold text-gray-700">Display Currency Symbol (Rs.)</span>
                                    <p class="text-xs text-gray-400 mt-0.5">Toggle whether the "Rs." symbol is shown alongside monetary figures on invoices and UI metrics.</p>
                                </div>
                            </label>
                        </div>
                    </div>
                </div>

                <!-- SMTP Mail Settings Tab -->
                <div x-show="tab === 'smtp'" class="space-y-6" style="display: none;">
                    <div class="bg-white rounded-2xl border border-gray-100 p-6 shadow-sm">
                        <h3 class="text-sm font-bold text-gray-800 uppercase tracking-wider mb-4">Mail Server (SMTP) Preferences</h3>
                        
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                            <div class="md:col-span-2">
                                <label class="block text-sm font-medium text-gray-700 mb-1">SMTP Host</label>
                                <input type="text" name="mail_host" value="<?php echo e($smtpSettings['mail_host']); ?>"
                                       class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400"
                                       placeholder="smtp.mailtrap.io">
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">SMTP Port</label>
                                <input type="text" name="mail_port" value="<?php echo e($smtpSettings['mail_port']); ?>"
                                       class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400"
                                       placeholder="587">
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mt-6">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">SMTP Username</label>
                                <input type="text" name="mail_username" value="<?php echo e($smtpSettings['mail_username']); ?>"
                                       class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400"
                                       placeholder="your-smtp-username">
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">SMTP Password</label>
                                <input type="password" name="mail_password" value="<?php echo e($smtpSettings['mail_password']); ?>"
                                       class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400"
                                       placeholder="••••••••••••">
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mt-6">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Encryption Protocol</label>
                                <select name="mail_encryption" class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400">
                                    <option value="tls" <?php echo e($smtpSettings['mail_encryption'] == 'tls' ? 'selected' : ''); ?>>TLS</option>
                                    <option value="ssl" <?php echo e($smtpSettings['mail_encryption'] == 'ssl' ? 'selected' : ''); ?>>SSL</option>
                                    <option value="none" <?php echo e($smtpSettings['mail_encryption'] == 'none' ? 'selected' : ''); ?>>None</option>
                                </select>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">From Email Address</label>
                                <input type="email" name="mail_from_address" value="<?php echo e($smtpSettings['mail_from_address']); ?>"
                                       class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400"
                                       placeholder="noreply@fbr-invoices.com">
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">From Sender Name</label>
                                <input type="text" name="mail_from_name" value="<?php echo e($smtpSettings['mail_from_name']); ?>"
                                       class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400"
                                       placeholder="FBR Billing Center">
                            </div>
                        </div>

                        <!-- Test Connection Widget -->
                        <div class="mt-8 border-t border-gray-100 pt-6">
                            <h4 class="text-xs font-bold text-gray-800 uppercase tracking-wide mb-3">Test Mail Delivery</h4>
                            <div class="flex flex-col sm:flex-row items-end gap-3 max-w-lg">
                                <div class="w-full">
                                    <label class="block text-xs font-medium text-gray-500 mb-1">Recipient Email Address</label>
                                    <input type="email" id="test_email" placeholder="test@example.com"
                                           class="w-full rounded-lg border-gray-200 text-sm focus:border-indigo-400 focus:ring-indigo-400">
                                </div>
                                <button type="button" @click="testSmtp()" :disabled="testing"
                                        class="w-full sm:w-auto shrink-0 inline-flex items-center justify-center gap-1.5 px-4 py-2.5 rounded-xl border border-gray-200 hover:bg-gray-50 text-gray-700 text-xs font-bold transition shadow-sm disabled:opacity-50">
                                    <svg x-show="!testing" class="w-4 h-4 text-gray-500" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5" />
                                    </svg>
                                    <svg x-show="testing" class="w-4 h-4 animate-spin text-gray-500" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" />
                                    </svg>
                                    <span x-text="testing ? 'Testing...' : 'Test SMTP Connection'"></span>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Cron Job Scheduler Tab -->
                <div x-show="tab === 'cron'" class="space-y-6">
                    <div class="bg-white rounded-2xl border border-gray-100 p-6 shadow-sm">
                        <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-gray-50 pb-4 mb-5">
                            <div>
                                <h3 class="text-sm font-bold text-gray-800 uppercase tracking-wider">Cron Job Configuration</h3>
                                <p class="text-xs text-gray-400 mt-0.5">Automates the background sync process for all scheduled invoices & intervals</p>
                            </div>

                            <!-- Live status indicator -->
                            <div>
                                <?php if($lastCronRun && now()->diffInMinutes(\Carbon\Carbon::parse($lastCronRun)) < 5): ?>
                                    <span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-semibold bg-green-50 text-green-700 border border-green-100">
                                        <span class="w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"></span>
                                        Scheduler Active / Running
                                    </span>
                                <?php else: ?>
                                    <span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-semibold bg-amber-50 text-amber-700 border border-amber-100">
                                        <span class="w-1.5 h-1.5 rounded-full bg-amber-500"></span>
                                        Inactive / Not Connected
                                    </span>
                                <?php endif; ?>
                            </div>
                        </div>

                        <!-- Instructions -->
                        <div class="space-y-4">
                            <?php if($lastCronRun): ?>
                                <div class="p-3 bg-gray-50 rounded-xl text-xs text-gray-500 border border-gray-100 flex items-center justify-between">
                                    <span>Last successful execution:</span>
                                    <span class="font-mono font-bold text-gray-700"><?php echo e(\Carbon\Carbon::parse($lastCronRun)->diffForHumans()); ?> (<?php echo e($lastCronRun); ?>)</span>
                                </div>
                            <?php endif; ?>

                            <div class="prose prose-sm text-gray-600 space-y-3">
                                <p class="text-xs text-gray-500">
                                    FBR Digital Invoicing auto-sync engine relies on Laravel's core scheduler to run periodic sync processes. 
                                    To activate the scheduler, add the following entry to your production server's system crontab:
                                </p>
                                
                                <div class="bg-gray-900 text-gray-100 p-4 rounded-xl font-mono text-xs overflow-x-auto select-all cursor-pointer" title="Click to select all">
                                    * * * * * cd <?php echo e(base_path()); ?> && php artisan schedule:run >> /dev/null 2>&1
                                </div>

                                <h4 class="text-xs font-bold text-gray-800 uppercase tracking-wide mt-6 mb-2">Alternative Manual Sync Trigger</h4>
                                <p class="text-xs text-gray-500">
                                    If you prefer running a direct cron job specifically for processing these scheduled sync actions, you can run this command directly at your chosen interval:
                                </p>
                                <div class="bg-gray-900 text-gray-100 p-4 rounded-xl font-mono text-xs overflow-x-auto select-all cursor-pointer" title="Click to select all">
                                    php artisan fbr:process-scheduled-syncs
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="mt-6 flex justify-end" x-show="tab !== 'cron'">
                    <button type="submit" class="inline-flex items-center gap-2 px-5 py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-medium transition shadow-sm">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
                        </svg>
                        Save Settings
                    </button>
                </div>
            </form>

        </div>
    </div>
 <?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 /home/iris/public_html/resources/views/settings/edit.blade.php ENDPATH**/ ?>