<?= $this->extend('layouts/app') ?>

<?= $this->section('content') ?>
<form method="post" action="<?= site_url('settings/branding') ?>" enctype="multipart/form-data" class="stack-lg settings-form">
    <?= csrf_field() ?>

    <section class="card stack-md">
        <div class="section-head">
            <div>
                <h3>Identidad visual</h3>
                <p>Estos ajustes actualizan el nombre del sistema, el logo y el pie de desarrollador.</p>
            </div>
            <div class="actions-row">
                <a class="btn btn-secondary" href="<?= site_url('dashboard') ?>">Volver</a>
                <button type="submit" form="branding-lock-form" class="btn btn-secondary">Bloquear panel</button>
            </div>
        </div>

        <div class="grid grid-2">
            <div>
                <label for="company_name">Nombre de la empresa</label>
                <input id="company_name" name="company_name" type="text" value="<?= esc(old('company_name', $settings['company_name'])) ?>" required>
            </div>

            <div>
                <label for="brand_mark">Marca corta</label>
                <input id="brand_mark" name="brand_mark" type="text" maxlength="4" value="<?= esc(old('brand_mark', $settings['brand_mark'])) ?>">
            </div>

            <div>
                <label for="company_tagline">Subtítulo del sistema</label>
                <input id="company_tagline" name="company_tagline" type="text" value="<?= esc(old('company_tagline', $settings['company_tagline'])) ?>">
            </div>

            <div>
                <label for="developer_footer">Pie de desarrollador</label>
                <input id="developer_footer" name="developer_footer" type="text" value="<?= esc(old('developer_footer', $settings['developer_footer'])) ?>">
            </div>
        </div>

        <div class="grid grid-2 brand-assets-grid">
            <div class="brand-asset-card">
                <span>Logo actual</span>
                <?php if ($logoUrl): ?>
                    <img src="<?= esc($logoUrl) ?>" alt="Logo actual" class="brand-preview-image">
                <?php else: ?>
                    <div class="brand-preview-placeholder">Sin logo</div>
                <?php endif; ?>
                <label for="logo_file">Actualizar logo</label>
                <input id="logo_file" name="logo_file" type="file" accept=".png,.jpg,.jpeg,.webp">
            </div>

            <div class="brand-asset-card">
                <span>QR actual</span>
                <?php if ($qrUrl): ?>
                    <img src="<?= esc($qrUrl) ?>" alt="QR actual" class="brand-preview-image brand-preview-qr">
                <?php else: ?>
                    <div class="brand-preview-placeholder">Sin QR</div>
                <?php endif; ?>
                <label for="qr_file">Actualizar QR</label>
                <input id="qr_file" name="qr_file" type="file" accept=".png,.jpg,.jpeg,.webp">
            </div>
        </div>
    </section>

    <section class="card stack-md">
        <div class="section-head">
            <div>
                <h3>Datos comerciales</h3>
                <p>Información reutilizada en el panel, PDFs y página pública de verificación.</p>
            </div>
        </div>

        <div class="grid grid-2">
            <div>
                <label for="company_website">Sitio web</label>
                <input id="company_website" name="company_website" type="text" value="<?= esc(old('company_website', $settings['company_website'])) ?>">
            </div>

            <div>
                <label for="company_linkedin">LinkedIn</label>
                <input id="company_linkedin" name="company_linkedin" type="text" value="<?= esc(old('company_linkedin', $settings['company_linkedin'])) ?>">
            </div>

            <div>
                <label for="company_whatsapp">WhatsApp</label>
                <input id="company_whatsapp" name="company_whatsapp" type="text" value="<?= esc(old('company_whatsapp', $settings['company_whatsapp'])) ?>">
            </div>

            <div>
                <label for="default_delivery_time">Tiempo de entrega por defecto</label>
                <input id="default_delivery_time" name="default_delivery_time" type="text" value="<?= esc(old('default_delivery_time', $settings['default_delivery_time'])) ?>">
            </div>

            <div>
                <label for="default_payment_terms">Condiciones de pago por defecto</label>
                <input id="default_payment_terms" name="default_payment_terms" type="text" value="<?= esc(old('default_payment_terms', $settings['default_payment_terms'])) ?>">
            </div>

            <div class="full-span">
                <label for="company_emails">Correos (uno por línea)</label>
                <textarea id="company_emails" name="company_emails" rows="3"><?= esc(old('company_emails', $settings['company_emails'])) ?></textarea>
            </div>

            <div class="full-span">
                <label for="company_phones">Teléfonos (uno por línea)</label>
                <textarea id="company_phones" name="company_phones" rows="3"><?= esc(old('company_phones', $settings['company_phones'])) ?></textarea>
            </div>

            <div class="full-span">
                <label for="company_intro_lead">Texto principal de introducción</label>
                <textarea id="company_intro_lead" name="company_intro_lead" rows="3"><?= esc(old('company_intro_lead', $settings['company_intro_lead'])) ?></textarea>
            </div>

            <div class="full-span">
                <label for="company_intro_body">Texto secundario</label>
                <textarea id="company_intro_body" name="company_intro_body" rows="3"><?= esc(old('company_intro_body', $settings['company_intro_body'])) ?></textarea>
            </div>

            <div class="full-span">
                <label for="company_strengths">Fortalezas (una por línea)</label>
                <textarea id="company_strengths" name="company_strengths" rows="5"><?= esc(old('company_strengths', $settings['company_strengths'])) ?></textarea>
            </div>

            <div class="full-span">
                <label for="condition_lines">Condiciones comerciales (una por línea)</label>
                <textarea id="condition_lines" name="condition_lines" rows="5"><?= esc(old('condition_lines', $settings['condition_lines'])) ?></textarea>
            </div>
        </div>
    </section>

    <section class="card stack-md">
        <div class="section-head">
            <div>
                <h3>PIN del panel oculto</h3>
                <p>Déjalo en blanco si no quieres cambiar el PIN actual.</p>
            </div>
        </div>

        <div class="grid grid-2">
            <div>
                <label for="new_pin">Nuevo PIN</label>
                <input id="new_pin" name="new_pin" type="password" inputmode="numeric" autocomplete="new-password">
            </div>

            <div>
                <label for="confirm_pin">Confirmar PIN</label>
                <input id="confirm_pin" name="confirm_pin" type="password" inputmode="numeric" autocomplete="new-password">
            </div>
        </div>
    </section>

    <div class="actions-row page-actions">
        <button class="btn btn-primary" type="submit">Guardar branding</button>
    </div>
</form>

<form id="branding-lock-form" method="post" action="<?= site_url('settings/branding/lock') ?>">
    <?= csrf_field() ?>
</form>
<?= $this->endSection() ?>
