<?php $__env->startSection('title', 'Email Settings'); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-4xl mx-auto">
    <div class="bg-white shadow rounded-lg">
        <div class="px-6 py-4 border-b border-gray-200">
            <h2 class="text-lg font-medium text-gray-900">Email Settings</h2>
        </div>

        <div class="p-6">
            <?php if(session('success')): ?>
                <div class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded relative" role="alert">
                    <span class="block sm:inline"><?php echo e(session('success')); ?></span>
                </div>
            <?php endif; ?>

            <?php if(session('error')): ?>
                <div class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded relative" role="alert">
                    <span class="block sm:inline"><?php echo e(session('error')); ?></span>
                </div>
            <?php endif; ?>

            <form action="<?php echo e(route('admin.settings.update')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>

                <!-- SMTP Settings -->
                <div class="space-y-6">
                    <div>
                        <h3 class="text-lg font-medium text-gray-900">SMTP Configuration</h3>
                        <p class="mt-1 text-sm text-gray-500">Configure your email sending settings.</p>
                    </div>

                    <div class="grid grid-cols-1 gap-6">
                        <!-- From Name -->
                        <div>
                            <label for="mail_from_name" class="block text-sm font-medium text-gray-700">From Name</label>
                            <input type="text" name="mail_from_name" id="mail_from_name" 
                                value="<?php echo e(old('mail_from_name', $settings['mail_from_name'] ?? '')); ?>"
                                class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                            <?php $__errorArgs = ['mail_from_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <!-- From Email -->
                        <div>
                            <label for="mail_from_email" class="block text-sm font-medium text-gray-700">From Email Address</label>
                            <input type="email" name="mail_from_email" id="mail_from_email" 
                                value="<?php echo e(old('mail_from_email', $settings['mail_from_email'] ?? '')); ?>"
                                class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                            <?php $__errorArgs = ['mail_from_email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <!-- Mail Host -->
                        <div>
                            <label for="mail_host" class="block text-sm font-medium text-gray-700">SMTP Host</label>
                            <input type="text" name="mail_host" id="mail_host" 
                                value="<?php echo e(old('mail_host', $settings['mail_host'] ?? '')); ?>"
                                class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                            <?php $__errorArgs = ['mail_host'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <!-- Mail Port -->
                        <div>
                            <label for="mail_port" class="block text-sm font-medium text-gray-700">SMTP Port</label>
                            <input type="number" name="mail_port" id="mail_port" 
                                value="<?php echo e(old('mail_port', $settings['mail_port'] ?? '')); ?>"
                                class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                            <?php $__errorArgs = ['mail_port'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <!-- Mail Username -->
                        <div>
                            <label for="mail_username" class="block text-sm font-medium text-gray-700">SMTP Username</label>
                            <input type="text" name="mail_username" id="mail_username" 
                                value="<?php echo e(old('mail_username', $settings['mail_username'] ?? '')); ?>"
                                class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                            <?php $__errorArgs = ['mail_username'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <!-- Mail Password -->
                        <div>
                            <label for="mail_password" class="block text-sm font-medium text-gray-700">SMTP Password</label>
                            <input type="password" name="mail_password" id="mail_password" 
                                value="<?php echo e(old('mail_password', $settings['mail_password'] ?? '')); ?>"
                                class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                            <p class="mt-1 text-xs text-gray-500">Leave empty to keep current password</p>
                            <?php $__errorArgs = ['mail_password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <!-- Mail Encryption -->
                        <div>
                            <label for="mail_encryption" class="block text-sm font-medium text-gray-700">Encryption</label>
                            <select name="mail_encryption" id="mail_encryption" 
                                class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                <option value="">None</option>
                                <option value="tls" <?php echo e((old('mail_encryption', $settings['mail_encryption'] ?? '') == 'tls') ? 'selected' : ''); ?>>TLS</option>
                                <option value="ssl" <?php echo e((old('mail_encryption', $settings['mail_encryption'] ?? '') == 'ssl') ? 'selected' : ''); ?>>SSL</option>
                            </select>
                            <?php $__errorArgs = ['mail_encryption'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>
                    </div>
                </div>

                <!-- Email Notifications -->
                <div class="mt-10 space-y-6">
                    <div>
                        <h3 class="text-lg font-medium text-gray-900">Email Notifications</h3>
                        <p class="mt-1 text-sm text-gray-500">Configure when to send email notifications</p>
                    </div>

                    <div class="space-y-4">
                        <div class="flex items-start">
                            <input type="hidden" name="notify_new_shipment" value="0">
                            <div class="flex h-5 items-center">
                                <input type="checkbox" name="notify_new_shipment" id="notify_new_shipment" 
                                    value="1" <?php echo e(old('notify_new_shipment', $settings['notify_new_shipment'] ?? '') ? 'checked' : ''); ?>

                                    class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                            </div>
                            <div class="ml-3">
                                <label for="notify_new_shipment" class="text-sm font-medium text-gray-700">New Shipment</label>
                                <p class="text-sm text-gray-500">Send email when new shipment is created</p>
                            </div>
                        </div>

                        <div class="flex items-start">
                                <input type="hidden" name="notify_status_update" value="0">
                            <div class="flex h-5 items-center">
                                <input type="checkbox" name="notify_status_update" id="notify_status_update" 
                                    value="1" <?php echo e(old('notify_status_update', $settings['notify_status_update'] ?? '') ? 'checked' : ''); ?>

                                    class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                            </div>
                            <div class="ml-3">
                                <label for="notify_status_update" class="text-sm font-medium text-gray-700">Status Update</label>
                                <p class="text-sm text-gray-500">Send email when shipment status is updated</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Test Email -->
                <div class="mt-10 space-y-6">
                    <div>
                        <h3 class="text-lg font-medium text-gray-900">Test Email Configuration</h3>
                        <p class="mt-1 text-sm text-gray-500">Send a test email to verify your settings</p>
                    </div>

                    <div>
                        <label for="test_email" class="block text-sm font-medium text-gray-700">Test Email Address</label>
                        <div class="mt-1 flex rounded-md shadow-sm">
                            <input type="email" name="test_email" id="test_email" 
                                class="block w-full rounded-l-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
                                placeholder="Enter email address">
                            <button type="button" id="send_test_email" 
                                class="inline-flex items-center rounded-r-md border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm font-medium text-gray-700 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
                                Test
                            </button>
                        </div>
                    </div>
                </div>

                <div class="mt-6 flex justify-end">
                    <button type="submit"
                        class="inline-flex justify-center rounded-md border border-transparent bg-indigo-600 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
                        Save Settings
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>


<script>
    document.getElementById('send_test_email').addEventListener('click', function() {
        const testEmail = document.getElementById('test_email').value;
        if (!testEmail) {
            alert('Please enter a test email address');
            return;
        }

        // Send test email using AJAX
        fetch('<?php echo e(route("admin.settings.test-email")); ?>', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>'
            },
            body: JSON.stringify({ email: testEmail })
        })
        .then(response => response.json())
        .then(data => {
            alert(data.message);
        })
        .catch(error => {
            alert('Error sending test email');
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/sfcmchxq/public_html/expressdeliveryfreight.com/resources/views/admin/settings/email.blade.php ENDPATH**/ ?>