

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

<?php $__env->startSection('content'); ?>
<div class="space-y-6">
    <!-- Header Section -->
    <div class="bg-white rounded-xl shadow-sm p-6">
        <div class="flex flex-col md:flex-row md:items-center md:justify-between">
            <div>
                <h1 class="text-2xl font-bold text-gray-900">Email Settings</h1>
                <p class="mt-1 text-gray-500">Configure your email server and notification preferences</p>
            </div>
        </div>
    </div>

    <?php if(session('success')): ?>
        <div class="bg-green-50 border-l-4 border-green-400 p-4 rounded-lg shadow-sm">
            <div class="flex">
                <div class="flex-shrink-0">
                    <i class="fas fa-check-circle text-green-400"></i>
                </div>
                <div class="ml-3">
                    <p class="text-sm text-green-700"><?php echo e(session('success')); ?></p>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <?php if(session('error')): ?>
        <div class="bg-red-50 border-l-4 border-red-400 p-4 rounded-lg shadow-sm">
            <div class="flex">
                <div class="flex-shrink-0">
                    <i class="fas fa-exclamation-circle text-red-400"></i>
                </div>
                <div class="ml-3">
                    <p class="text-sm text-red-700"><?php echo e(session('error')); ?></p>
                </div>
            </div>
        </div>
    <?php endif; ?>

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

        <!-- SMTP Settings -->
        <div class="bg-white rounded-xl shadow-sm overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-100">
                <h2 class="text-lg font-semibold text-gray-900 flex items-center">
                    <i class="fas fa-server text-blue-500 mr-2"></i>
                    SMTP Configuration
                </h2>
            </div>
            <div class="p-6">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <!-- From Name -->
                    <div>
                        <label for="mail_from_name" class="block text-sm font-medium text-gray-700 mb-1">From Name</label>
                        <div class="relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-user text-gray-400"></i>
                            </div>
                            <input type="text" name="mail_from_name" id="mail_from_name" 
                                value="<?php echo e(old('mail_from_name', $settings['mail_from_name'] ?? '')); ?>"
                                class="pl-10 block w-full rounded-lg border-gray-300 focus:ring-blue-500 focus:border-blue-500"
                                placeholder="Golden Musk Freight">
                        </div>
                        <?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 mb-1">From Email Address</label>
                        <div class="relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-envelope text-gray-400"></i>
                            </div>
                            <input type="email" name="mail_from_email" id="mail_from_email" 
                                value="<?php echo e(old('mail_from_email', $settings['mail_from_email'] ?? '')); ?>"
                                class="pl-10 block w-full rounded-lg border-gray-300 focus:ring-blue-500 focus:border-blue-500"
                                placeholder="noreply@example.com">
                        </div>
                        <?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 mb-1">SMTP Host</label>
                        <div class="relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-globe text-gray-400"></i>
                            </div>
                            <input type="text" name="mail_host" id="mail_host" 
                                value="<?php echo e(old('mail_host', $settings['mail_host'] ?? '')); ?>"
                                class="pl-10 block w-full rounded-lg border-gray-300 focus:ring-blue-500 focus:border-blue-500"
                                placeholder="smtp.example.com">
                        </div>
                        <?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 mb-1">SMTP Port</label>
                        <div class="relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-plug text-gray-400"></i>
                            </div>
                            <input type="number" name="mail_port" id="mail_port" 
                                value="<?php echo e(old('mail_port', $settings['mail_port'] ?? '')); ?>"
                                class="pl-10 block w-full rounded-lg border-gray-300 focus:ring-blue-500 focus:border-blue-500"
                                placeholder="587">
                        </div>
                        <?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 mb-1">SMTP Username</label>
                        <div class="relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-user-shield text-gray-400"></i>
                            </div>
                            <input type="text" name="mail_username" id="mail_username" 
                                value="<?php echo e(old('mail_username', $settings['mail_username'] ?? '')); ?>"
                                class="pl-10 block w-full rounded-lg border-gray-300 focus:ring-blue-500 focus:border-blue-500"
                                placeholder="Username or email address">
                        </div>
                        <?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 mb-1">SMTP Password</label>
                        <div class="relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-lock text-gray-400"></i>
                            </div>
                            <input type="password" name="mail_password" id="mail_password" 
                                value="<?php echo e(old('mail_password', $settings['mail_password'] ?? '')); ?>"
                                class="pl-10 block w-full rounded-lg border-gray-300 focus:ring-blue-500 focus:border-blue-500"
                                placeholder="••••••••">
                        </div>
                        <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 mb-1">Encryption</label>
                        <div class="relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-shield-alt text-gray-400"></i>
                            </div>
                            <select name="mail_encryption" id="mail_encryption" 
                                class="pl-10 block w-full rounded-lg border-gray-300 focus:ring-blue-500 focus:border-blue-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>
                        </div>
                        <?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>
        </div>

        <!-- Email Notifications -->
        <div class="bg-white rounded-xl shadow-sm overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-100">
                <h2 class="text-lg font-semibold text-gray-900 flex items-center">
                    <i class="fas fa-bell text-yellow-500 mr-2"></i>
                    Email Notifications
                </h2>
            </div>
            <div class="p-6">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <input type="hidden" name="notify_new_shipment" value="0">
                        <div class="flex items-start">
                            <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-blue-600 focus:ring-blue-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-xs text-gray-500 mt-1">Send email when new shipment is created</p>
                            </div>
                        </div>
                    </div>

                    <div class="bg-gray-50 p-4 rounded-lg">
                        <input type="hidden" name="notify_status_update" value="0">
                        <div class="flex items-start">
                            <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-blue-600 focus:ring-blue-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-xs text-gray-500 mt-1">Send email when shipment status is updated</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Test Email -->
        <div class="bg-white rounded-xl shadow-sm overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-100">
                <h2 class="text-lg font-semibold text-gray-900 flex items-center">
                    <i class="fas fa-paper-plane text-green-500 mr-2"></i>
                    Test Email Configuration
                </h2>
            </div>
            <div class="p-6">
                <div class="max-w-md">
                    <p class="text-sm text-gray-500 mb-4">Send a test email to verify your SMTP settings are working correctly.</p>
                    <label for="test_email" class="block text-sm font-medium text-gray-700 mb-1">Test Email Address</label>
                    <div class="mt-1 flex rounded-md shadow-sm">
                        <div class="relative flex items-stretch flex-grow">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-envelope text-gray-400"></i>
                            </div>
                            <input type="email" name="test_email" id="test_email" 
                                class="pl-10 block w-full rounded-l-lg border-gray-300 focus:ring-blue-500 focus:border-blue-500"
                                placeholder="Enter recipient email">
                        </div>
                        <button type="button" id="send_test_email" 
                            class="inline-flex items-center px-4 py-2 border border-l-0 border-gray-300 bg-blue-600 text-white font-medium rounded-r-lg hover:bg-blue-700 transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500">
                            <i class="fas fa-paper-plane mr-2"></i>
                            Send Test
                        </button>
                    </div>
                    <p class="mt-2 text-xs text-gray-500">Make sure to save your settings before testing.</p>
                </div>
            </div>
        </div>

        <div class="flex justify-end">
            <button type="submit"
                class="inline-flex items-center px-5 py-2.5 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-4 focus:ring-blue-300 shadow-sm transition-colors">
                <i class="fas fa-save mr-2"></i>
                Save Settings
            </button>
        </div>
    </form>
</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;
        }

        // Show loading state
        const button = this;
        const originalContent = button.innerHTML;
        button.disabled = true;
        button.innerHTML = '<i class="fas fa-circle-notch fa-spin mr-2"></i> Sending...';

        // 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 => {
            // Reset button state
            button.disabled = false;
            button.innerHTML = originalContent;

            // Show notification
            const notificationContainer = document.createElement('div');
            notificationContainer.className = data.success ? 
                'fixed bottom-4 right-4 bg-green-50 border-l-4 border-green-400 p-4 rounded-lg shadow-lg z-50' :
                'fixed bottom-4 right-4 bg-red-50 border-l-4 border-red-400 p-4 rounded-lg shadow-lg z-50';
            
            notificationContainer.innerHTML = `
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas ${data.success ? 'fa-check-circle text-green-400' : 'fa-exclamation-circle text-red-400'}"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-sm ${data.success ? 'text-green-700' : 'text-red-700'}">${data.message}</p>
                    </div>
                    <div class="ml-auto pl-3">
                        <button class="inline-flex text-gray-400 hover:text-gray-500">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(notificationContainer);
            
            // Close button handler
            notificationContainer.querySelector('button').addEventListener('click', function() {
                notificationContainer.remove();
            });
            
            // Auto remove after 5 seconds
            setTimeout(() => {
                if (notificationContainer.parentNode) {
                    notificationContainer.remove();
                }
            }, 5000);
        })
        .catch(error => {
            // Reset button state
            button.disabled = false;
            button.innerHTML = originalContent;
            
            // Show error
            alert('Error sending test email. Please check your network connection.');
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home2/gczzqaya/goldenmuskfreight.com/resources/views/admin/settings/email.blade.php ENDPATH**/ ?>