{% extends 'admin/base.html' %}

{% block title %}Settings{% endblock %}

{% block content %}
<style>
    .alert {
        padding: 16px 24px;
        margin-bottom: 18px;
        border-radius: 6px;
        font-size: 16px;
        display: flex;
        align-items: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.04);
        border: 1px solid transparent;
        font-weight: 500;
    }
    .alert-success {
        color: #17603a;
        background-color: #edfaef;
        border-color: #b9efce;
    }
    .alert-danger {
        color: #7a1f1f;
        background-color: #ffeaea;
        border-color: #f5bcbc;
    }
    .alert i {
        margin-right: 8px;
        font-size: 19px;
    }
    .form-section {
        margin-top: 32px;
        padding-top: 20px;
        border-top: 1px solid #e2e5ea;
    }
    .form-section:first-of-type {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }
    .form-section h3 {
        font-size: 18px;
        margin-bottom: 16px;
    }
    .form-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        gap: 16px;
    }
    .form-group label {
        display: block;
        margin-bottom: 6px;
        font-weight: 500;
    }
    .form-group input {
        width: 100%;
        padding: 10px 12px;
        border: 1px solid #d8dde4;
        border-radius: 6px;
        font-size: 15px;
    }
    .form-group small {
        display: block;
        margin-top: 4px;
        color: #6c757d;
        font-size: 13px;
    }
</style>

<div class="page-header">
    <div>
        <h1 class="page-title">Settings</h1>
        <p class="page-subtitle">Configure defaults that apply to all companies.</p>
    </div>
</div>

{% if success_message %}
<div class="alert alert-success"><i class="fa-light fa-circle-check"></i>{{ success_message }}</div>
{% endif %}
{% if error_message %}
<div class="alert alert-danger"><i class="fa-light fa-circle-xmark"></i>{{ error_message }}</div>
{% endif %}

<div class="card">
    <div class="card-header">
        <div>
            <h2 class="card-title">File Management</h2>
            <p class="card-subtitle">Define global limits that packages can build upon.</p>
        </div>
    </div>
    <div class="card-body">
        <form class="settings-form" method="POST">
            <div class="form-group">
                <label for="fileSizeLimit">Maximum File Upload Size (MB)</label>
                <input type="number"
                       id="fileSizeLimit"
                       name="file_size_limit"
                       min="1"
                       step="1"
                       placeholder="e.g., 25"
                       value="{{ settings.file_size_limit }}">
                <small class="form-text text-muted">This is a global ceiling. Package-specific limits can be lower.</small>
            </div>

            <div class="form-section">
                <h3>Admin Personal Info</h3>
                <div class="form-group">
                    <label for="admin_email">Admin Email</label>
                    <input type="email"
                           id="admin_email"
                           name="admin_email"
                           placeholder="e.g., admin@example.com"
                           value="{{ settings.admin_email }}">
                    <small class="form-text text-muted">Your contact email for admin use and notifications.</small>
                </div>
            </div>

            <div class="form-section">
                <h3>SMTP Email Settings</h3>
                <div class="form-grid">
                    <div class="form-group">
                        <label for="mail_mailer">Mailer</label>
                        <input type="text"
                               id="mail_mailer"
                               name="mail_mailer"
                               placeholder="e.g., smtp"
                               value="{{ settings.mail_mailer }}">
                    </div>
                    <div class="form-group">
                        <label for="mail_host">Host</label>
                        <input type="text"
                               id="mail_host"
                               name="mail_host"
                               placeholder="e.g., smtp.gmail.com"
                               value="{{ settings.mail_host }}">
                    </div>
                    <div class="form-group">
                        <label for="mail_port">Port</label>
                        <input type="number"
                               id="mail_port"
                               name="mail_port"
                               min="1"
                               step="1"
                               placeholder="e.g., 465"
                               value="{{ settings.mail_port }}">
                    </div>
                    <div class="form-group">
                        <label for="mail_username">Username</label>
                        <input type="text"
                               id="mail_username"
                               name="mail_username"
                               placeholder="SMTP username"
                               value="{{ settings.mail_username }}">
                    </div>
                    <div class="form-group">
                        <label for="mail_password">Password</label>
                        <input type="password"
                               id="mail_password"
                               name="mail_password"
                               placeholder="SMTP password"
                               value="{{ settings.mail_password }}">
                    </div>
                    <div class="form-group">
                        <label for="mail_encryption">Encryption</label>
                        <input type="text"
                               id="mail_encryption"
                               name="mail_encryption"
                               placeholder="e.g., ssl, tls"
                               value="{{ settings.mail_encryption }}">
                    </div>
                    <div class="form-group">
                        <label for="mail_from_address">From Address</label>
                        <input type="email"
                               id="mail_from_address"
                               name="mail_from_address"
                               placeholder="e.g., noreply@example.com"
                               value="{{ settings.mail_from_address }}">
                    </div>
                    <div class="form-group">
                        <label for="mail_from_name">From Name</label>
                        <input type="text"
                               id="mail_from_name"
                               name="mail_from_name"
                               placeholder="e.g., Support Team"
                               value="{{ settings.mail_from_name }}">
                    </div>
                </div>
                <small class="form-text text-muted">Leave fields blank if SMTP is not configured yet.</small>
            </div>

            <div class="form-actions">
                <button type="submit" class="btn btn-primary">
                    <i class="fa-light fa-floppy-disk"></i>
                    <span>Save Changes</span>
                </button>
            </div>
        </form>
    </div>
</div>
{% endblock %}

