<?php require __DIR__ . '/settings_nav.php'; ?>
<div class="mb-3">
    <h2 class="mb-1"><?= h(t('settings.general_title')) ?></h2>
    <div class="text-muted"><?= h(t('settings.general_intro')) ?></div>
</div>
<?php if ($saved): ?><div class="alert alert-success">✅ <?= h(t('settings.saved')) ?></div><?php endif; ?>
<?php if ($error !== ''): ?><div class="alert alert-danger">⚠️ <?= h($error) ?></div><?php endif; ?>
<form method="post" action="/settings/general/save" enctype="multipart/form-data">
    <div class="card mb-3 overflow-hidden">
        <div class="card-status-top bg-primary"></div>
        <div class="card-header">
            <h3 class="card-title"><?= h(t('settings.association')) ?></h3>
        </div>
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-6"><label
                        class="form-label required"><?= h(t('settings.association_name')) ?></label><input
                        class="form-control" name="association_name" value="<?= h($settings['association_name']) ?>"
                        required></div>
                <div class="col-md-3"><label class="form-label"><?= h(t('settings.rna')) ?></label><input
                        class="form-control" name="association_rna" value="<?= h($settings['association_rna']) ?>"
                        placeholder="W…"></div>
                <div class="col-md-3"><label class="form-label"><?= h(t('settings.siret')) ?></label><input
                        class="form-control" name="association_siret" value="<?= h($settings['association_siret']) ?>">
                </div>
                <div class="col-12"><label class="form-label"><?= h(t('settings.address')) ?></label><input
                        class="form-control" name="association_address"
                        value="<?= h($settings['association_address']) ?>"></div>
                <div class="col-md-3"><label class="form-label"><?= h(t('settings.postcode')) ?></label><input
                        class="form-control" name="association_postal_code"
                        value="<?= h($settings['association_postal_code']) ?>"></div>
                <div class="col-md-3"><label class="form-label"><?= h(t('settings.city')) ?></label><input
                        class="form-control" name="association_city" value="<?= h($settings['association_city']) ?>">
                </div>
                <div class="col-md-3"><label class="form-label"><?= h(t('settings.phone')) ?></label><input
                        class="form-control" name="association_phone" value="<?= h($settings['association_phone']) ?>">
                </div>
                <div class="col-md-3"><label class="form-label"><?= h(t('settings.email')) ?></label><input
                        class="form-control" type="email" name="association_email"
                        value="<?= h($settings['association_email']) ?>"></div>
                <div class="col-12">
                    <hr class="my-1">
                </div>
                <div class="col-md-8"><label class="form-label"><?= h(t('settings.association_logo')) ?></label><input
                        class="form-control" type="file" name="association_logo"
                        accept="image/png,image/jpeg,image/webp">
                    <div class="form-hint"><?= h(t('settings.logo_help')) ?></div><?php if ($associationLogo): ?><label
                        class="form-check mt-2"><input class="form-check-input" type="checkbox"
                            name="delete_association_logo" value="1"><span
                            class="form-check-label text-danger"><?= h(t('settings.delete_logo')) ?></span></label><?php endif; ?>
                </div>
                <div class="col-md-4 d-flex align-items-center justify-content-md-end"><?php if ($associationLogo): ?>
                    <div class="border rounded bg-white p-2 text-center"><img
                            src="/settings/association-logo?v=<?= (int)filemtime($associationLogo) ?>"
                            alt="<?= h(t('settings.logo_alt', ['name' => $settings['association_name']])) ?>"
                            style="display:block;max-width:180px;max-height:90px;object-fit:contain">
                        <div class="small text-muted mt-1"><?= h(t('settings.current_preview')) ?></div>
                    </div><?php else: ?><div class="text-muted small"><?= h(t('settings.no_logo')) ?></div>
                    <?php endif; ?></div>
            </div>
        </div>
    </div>
    <div class="card overflow-hidden">
        <div class="card-status-top bg-orange"></div>
        <div class="card-header">
            <h3 class="card-title"><?= h(t('settings.operation')) ?></h3>
        </div>
        <div class="card-body row g-3">
            <div class="col-md-4"><label class="form-label"><?= h(t('settings.language')) ?></label><select
                    class="form-select" name="app_language"><?php foreach (I18n::LOCALES as $code => $label): ?><option
                        value="<?= h($code) ?>" <?= ($settings['app_language'] ?? 'fr') === $code ? 'selected' : '' ?>>
                        <?= h($label) ?></option><?php endforeach; ?></select>
                <div class="form-hint"><?= h(t('settings.language_help')) ?></div>
            </div>
            <div class="col-md-4"><label class="form-label"><?= h(t('settings.quarantine_duration')) ?></label>
                <div class="input-group"><input class="form-control" type="number" min="1" max="90"
                        name="quarantine_days" value="<?= (int)$settings['quarantine_days'] ?>"><span
                        class="input-group-text"><?= h(t('settings.days')) ?></span></div>
            </div>
            <div class="col-md-4"><label class="form-label"><?= h(t('settings.backups_kept')) ?></label>
                <div class="input-group"><input class="form-control" type="number" min="1" max="50"
                        name="backup_retention" value="<?= (int)$settings['backup_retention'] ?>"><span
                        class="input-group-text">ZIP</span></div>
            </div>
        </div>
    </div>
    <div class="text-end mt-3"><button class="btn btn-primary"><?= h(t('settings.save')) ?></button></div>
</form>
