<?php require __DIR__ . '/settings_nav.php'; ?>
<div class="d-flex flex-wrap justify-content-between align-items-start gap-2 mb-3">
    <div>
        <h2 class="mb-1"><?= h(t('public_site.settings_heading')) ?></h2>
        <div class="text-muted"><?= h(t('public_site.settings_intro')) ?></div>
    </div><a class="btn btn-outline-primary" href="<?= h(PublicSiteController::url()) ?>" target="_blank">↗
        <?= h(t('public_site.preview')) ?></a>
</div>
<?php if ($saved): ?><div class="alert alert-success">✅ <?= h(t('public_site.saved')) ?></div>
<?php endif; ?><?php if ($error): ?><div class="alert alert-danger">⚠️ <?= h($error) ?></div><?php endif; ?>
<form method="post" action="/settings/public-site/save"><input type="hidden" name="csrf" value="<?= h(Auth::csrf()) ?>">
    <div class="card mb-3">
        <div class="card-status-top bg-green"></div>
        <div class="card-header">
            <h3 class="card-title"><?= h(t('public_site.activation_style')) ?></h3>
        </div>
        <div class="card-body">
            <div class="row g-3">
                <div class="col-12"><label class="form-check form-switch"><input class="form-check-input"
                            type="checkbox" name="public_site_enabled" value="1"
                            <?= ($settings['public_site_enabled'] ?? '0') === '1' ? 'checked' : '' ?>><span
                            class="form-check-label fw-bold"><?= h(t('public_site.enable')) ?></span></label>
                    <div class="form-hint"><?= h(t('public_site.enable_help')) ?></div>
                </div>
                <div class="col-12"><label class="form-label"><?= h(t('public_site.main_address')) ?></label>
                    <div class="row g-2">
                        <div class="col-md-6"><label class="form-selectgroup-item w-100"><input
                                    class="form-selectgroup-input" type="radio" name="public_site_routing"
                                    value="integrated"
                                    <?= ($settings['public_site_routing'] ?? 'integrated') === 'integrated' ? 'checked' : '' ?>><span
                                    class="form-selectgroup-label d-block"><strong><?= h(t('public_site.routing_management')) ?></strong><span
                                        class="d-block text-muted small"><?= h(t('public_site.routing_management_help')) ?></span></span></label>
                        </div>
                        <div class="col-md-6"><label class="form-selectgroup-item w-100"><input
                                    class="form-selectgroup-input" type="radio" name="public_site_routing" value="root"
                                    <?= ($settings['public_site_routing'] ?? 'integrated') === 'root' ? 'checked' : '' ?>><span
                                    class="form-selectgroup-label d-block"><strong><?= h(t('public_site.routing_public')) ?></strong><span
                                        class="d-block text-muted small"><?= h(t('public_site.routing_public_help')) ?></span></span></label>
                        </div>
                    </div>
                    <div class="form-hint mt-2"><?= h(t('public_site.routing_no_server')) ?></div>
                </div>
                <div class="col-12"><label class="form-label"><?= h(t('public_site.theme')) ?></label>
                    <div class="row g-2">
                        <?php foreach (['warm' => ['🧡',t('public_site.theme_warm')],'nature' => ['🌿',t('public_site.theme_nature')],'minimal' => ['◻️',t('public_site.theme_minimal')]] as $key => $theme): ?>
                        <div class="col-md-4"><label class="form-selectgroup-item w-100"><input type="radio"
                                    name="public_site_theme" value="<?= h($key) ?>" class="form-selectgroup-input"
                                    <?= ($settings['public_site_theme'] ?? 'warm') === $key ? 'checked' : '' ?>><span
                                    class="form-selectgroup-label d-flex align-items-center gap-2"><?= $theme[0] ?>
                                    <strong><?= h($theme[1]) ?></strong></span></label></div><?php endforeach; ?></div>
                </div>
            </div>
        </div>
    </div>
    <div class="card mb-3">
        <div class="card-header">
            <h3 class="card-title">🏠 <?= h(t('public_site.home')) ?></h3>
        </div>
        <div class="card-body row g-3">
            <div class="col-12"><label class="form-label"><?= h(t('common.title')) ?></label><input class="form-control"
                    name="public_site_home_title" value="<?= h($settings['public_site_home_title']) ?>" required></div>
            <div class="col-12"><label class="form-label"><?= h(t('common.text')) ?></label><textarea
                    class="form-control" name="public_site_home_text"
                    rows="4"><?= h($settings['public_site_home_text']) ?></textarea></div>
        </div>
    </div>
    <div class="card mb-3">
        <div class="card-header">
            <h3 class="card-title">📖 <?= h(t('public_site.free_page')) ?></h3>
        </div>
        <div class="card-body row g-3">
            <div class="col-12"><label class="form-check form-switch"><input class="form-check-input" type="checkbox"
                        name="public_site_about_enabled" value="1"
                        <?= ($settings['public_site_about_enabled'] ?? '0') === '1' ? 'checked' : '' ?>><span
                        class="form-check-label"><?= h(t('public_site.show_free_page')) ?></span></label></div>
            <div class="col-md-4"><label class="form-label"><?= h(t('common.title')) ?></label><input
                    class="form-control" name="public_site_about_title"
                    value="<?= h($settings['public_site_about_title']) ?>"></div>
            <div class="col-md-8"><label class="form-label"><?= h(t('common.text')) ?></label><textarea
                    class="form-control" name="public_site_about_text"
                    rows="5"><?= h($settings['public_site_about_text']) ?></textarea></div>
        </div>
    </div>
    <div class="card mb-3">
        <div class="card-header">
            <h3 class="card-title">💝 <?= h(t('public_site.donation')) ?></h3>
        </div>
        <div class="card-body row g-3">
            <div class="col-md-4"><label class="form-label"><?= h(t('common.title')) ?></label><input
                    class="form-control" name="public_site_donation_title"
                    value="<?= h($settings['public_site_donation_title']) ?>"></div>
            <div class="col-md-8"><label class="form-label"><?= h(t('public_site.donation_url')) ?></label><input
                    class="form-control" type="url" name="public_site_donation_url"
                    value="<?= h($settings['public_site_donation_url']) ?>" placeholder="https://..."></div>
            <div class="col-12"><label class="form-label"><?= h(t('common.text')) ?></label><textarea
                    class="form-control" name="public_site_donation_text"
                    rows="4"><?= h($settings['public_site_donation_text']) ?></textarea></div>
        </div>
    </div>
    <div class="card mb-3">
        <div class="card-header">
            <h3 class="card-title">✉️ <?= h(t('public_site.contact')) ?></h3>
        </div>
        <div class="card-body row g-3">
            <div class="col-12">
                <div class="alert alert-info py-2"><?= h(t('public_site.contact_reuse')) ?></div><label
                    class="form-label"><?= h(t('common.text')) ?></label><textarea class="form-control"
                    name="public_site_contact_text" rows="3"><?= h($settings['public_site_contact_text']) ?></textarea>
            </div>
            <div class="col-md-6"><label class="form-label">Facebook</label><input class="form-control" type="url"
                    name="public_site_facebook_url" value="<?= h($settings['public_site_facebook_url']) ?>"></div>
            <div class="col-md-6"><label class="form-label">Instagram</label><input class="form-control" type="url"
                    name="public_site_instagram_url" value="<?= h($settings['public_site_instagram_url']) ?>"></div>
        </div>
    </div>
    <div class="card mb-3">
        <div class="card-header">
            <h3 class="card-title">⚖️ <?= h(t('public_site.legal_privacy')) ?></h3>
        </div>
        <div class="card-body row g-3">
            <div class="col-md-6"><label class="form-label"><?= h(t('public_site.legal')) ?></label><textarea
                    class="form-control" name="public_site_legal_text"
                    rows="16"><?= h(PublicSiteController::legalText($settings)) ?></textarea></div>
            <div class="col-md-6"><label class="form-label"><?= h(t('public_site.privacy')) ?></label><textarea
                    class="form-control" name="public_site_privacy_text"
                    rows="16"><?= h(PublicSiteController::privacyText($settings)) ?></textarea></div>
            <div class="col-12 form-hint"><?= h(t('public_site.legal_hint')) ?></div>
        </div>
    </div>
    <div class="text-end mb-4"><button class="btn btn-primary"><?= h(t('common.save')) ?></button></div>
</form>
