<?php
if (!defined('ABSPATH')) exit;
?>
<div class="pg-license-wrap">
    <div class="pg-license-panel" data-pg-license-panel>
        <div class="pg-license-hero">
            <div class="pg-license-status">
                <span class="pg-license-badge <?php echo esc_attr($badge_class); ?>"><?php echo esc_html($badge_text); ?></span>
                <p class="pg-license-hero-desc">
                    <?php esc_html_e('Las claves se gestionan en wptheme.site. El nombre del producto en el servidor debe coincidir exactamente con el indicado a la derecha.', 'pulsegrid'); ?>
                </p>
            </div>
            <dl class="pg-license-meta">
                <div>
                    <dt><?php esc_html_e('Producto', 'pulsegrid'); ?></dt>
                    <dd><code class="pg-license-code"><?php echo esc_html($product); ?></code></dd>
                </div>
                <div>
                    <dt><?php esc_html_e('Este sitio', 'pulsegrid'); ?></dt>
                    <dd><code class="pg-license-code"><?php echo esc_html($site); ?></code></dd>
                </div>
                <div>
                    <dt><?php esc_html_e('Última comprobación', 'pulsegrid'); ?></dt>
                    <dd><?php echo esc_html($checked_at); ?></dd>
                </div>
            </dl>
        </div>

        <div class="pg-license-grid">
            <div class="pg-license-card pg-license-card--key">
                <h3 class="pg-license-card-title"><?php esc_html_e('Clave de licencia', 'pulsegrid'); ?></h3>
                <?php if ($is_active) : ?>
                    <?php if ($can_manage) : ?>
                        <p class="pg-license-card-hint">
                            <?php esc_html_e('La licencia está activa en este dominio. Puedes desactivarla para liberar la activación en el servidor; el sitio público mostrará el aviso de licencia hasta que vuelvas a activar una clave.', 'pulsegrid'); ?>
                        </p>
                        <div class="pg-license-actions">
                            <button type="button" class="button pg-license-btn pg-license-btn--danger" data-action="deactivate">
                                <span class="pg-btn-label"><?php esc_html_e('Desactivar licencia', 'pulsegrid'); ?></span>
                            </button>
                            <span class="spinner pg-license-spinner"></span>
                        </div>
                        <p class="pg-license-msg" data-pg-license-msg hidden></p>
                    <?php else : ?>
                        <p class="pg-license-card-hint"><?php esc_html_e('La licencia está activa en este sitio.', 'pulsegrid'); ?></p>
                    <?php endif; ?>
                <?php elseif ($can_manage) : ?>
                    <p class="pg-license-card-hint">
                        <?php esc_html_e('Pega la clave (formato WZDL-XXXX-…). Al activar, este sitio usará una activación en el servidor para este dominio.', 'pulsegrid'); ?>
                    </p>
                    <label class="screen-reader-text" for="pg-license-key-input"><?php esc_html_e('Clave', 'pulsegrid'); ?></label>
                    <input type="password" id="pg-license-key-input" class="pg-license-key-input regular-text" autocomplete="off" placeholder="<?php esc_attr_e('WZDL-XXXX-XXXX-XXXX-XXXX', 'pulsegrid'); ?>" value="" />
                    <div class="pg-license-actions">
                        <button type="button" class="button button-primary pg-license-btn" data-action="activate">
                            <span class="pg-btn-icon" aria-hidden="true">
                                <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z"/><circle cx="16.5" cy="7.5" r=".5" fill="currentColor"/></svg>
                            </span>
                            <span class="pg-btn-label"><?php esc_html_e('Activar licencia', 'pulsegrid'); ?></span>
                        </button>
                        <span class="spinner pg-license-spinner"></span>
                    </div>
                    <p class="pg-license-msg" data-pg-license-msg hidden></p>
                <?php else : ?>
                    <p class="pg-license-card-hint"><?php esc_html_e('Solo los administradores del sitio pueden introducir o activar la clave de licencia.', 'pulsegrid'); ?></p>
                <?php endif; ?>
            </div>

            <div class="pg-license-card pg-license-card--details">
                <h3 class="pg-license-card-title"><?php esc_html_e('Detalles', 'pulsegrid'); ?></h3>
                <ul class="pg-license-detail-list" data-pg-license-details>
                    <li><span><?php esc_html_e('Tipo', 'pulsegrid'); ?></span> <strong data-field="license_type"><?php echo esc_html($license_type_label); ?></strong></li>
                    <li><span><?php esc_html_e('Activaciones', 'pulsegrid'); ?></span> <strong data-field="activations"><?php echo esc_html($activations_label); ?></strong></li>
                    <li><span><?php esc_html_e('Caducidad', 'pulsegrid'); ?></span> <strong data-field="expiry"><?php echo esc_html($expiry_label); ?></strong></li>
                    <li><span><?php esc_html_e('Mensaje', 'pulsegrid'); ?></span> <strong data-field="message"><?php echo esc_html($message_label); ?></strong></li>
                </ul>
                <p class="pg-license-help">
                    <a href="https://forobeta.com/members/jach12k7.282356/" target="_blank" rel="noopener noreferrer"><?php esc_html_e('¿Problemas con la licencia? ForoBeta', 'pulsegrid'); ?></a>
                    ·
                    <a href="https://wptheme.site/" target="_blank" rel="noopener noreferrer"><?php esc_html_e('Wptheme.site', 'pulsegrid'); ?></a>
                </p>
            </div>
        </div>

        <?php if ($can_manage) : ?>
        <div class="pg-license-modal" data-pg-license-modal="activate" hidden>
            <button type="button" class="pg-license-modal__backdrop" data-pg-license-modal-close aria-label="<?php esc_attr_e('Cerrar', 'pulsegrid'); ?>"></button>
            <div class="pg-license-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="pg-license-modal-activate-title" tabindex="-1">
                <div class="pg-license-modal__icon" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
                </div>
                <h2 id="pg-license-modal-activate-title" class="pg-license-modal__title"><?php esc_html_e('¿Activar la licencia en este sitio?', 'pulsegrid'); ?></h2>
                <div class="pg-license-modal__body">
                    <p><?php esc_html_e('Se registrará esta instalación como activada para el dominio indicado arriba. Podrás desactivarla en cualquier momento desde esta misma pantalla.', 'pulsegrid'); ?></p>
                    <p class="pg-license-modal__emphasis"><?php esc_html_e('Confirma que esta URL es la instalación correcta.', 'pulsegrid'); ?></p>
                </div>
                <div class="pg-license-modal__footer">
                    <button type="button" class="button pg-license-modal__btn-cancel" data-pg-license-modal-close><?php esc_html_e('Cancelar', 'pulsegrid'); ?></button>
                    <button type="button" class="button button-primary pg-license-modal__btn-confirm" data-pg-license-do="activate"><?php esc_html_e('Sí, activar en este sitio', 'pulsegrid'); ?></button>
                </div>
            </div>
        </div>
        <div class="pg-license-modal" data-pg-license-modal="deactivate" hidden>
            <button type="button" class="pg-license-modal__backdrop" data-pg-license-modal-close aria-label="<?php esc_attr_e('Cerrar', 'pulsegrid'); ?>"></button>
            <div class="pg-license-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="pg-license-modal-deactivate-title" tabindex="-1">
                <div class="pg-license-modal__icon" aria-hidden="true">
                    <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
                </div>
                <h2 id="pg-license-modal-deactivate-title" class="pg-license-modal__title"><?php esc_html_e('¿Desactivar la licencia en este sitio?', 'pulsegrid'); ?></h2>
                <div class="pg-license-modal__body">
                    <p><?php esc_html_e('Se liberará la activación en el servidor para este dominio.', 'pulsegrid'); ?></p>
                    <p><?php esc_html_e('El sitio público mostrará el aviso de licencia hasta que actives de nuevo una clave.', 'pulsegrid'); ?></p>
                    <p class="pg-license-modal__emphasis"><?php esc_html_e('¿Seguro que quieres continuar?', 'pulsegrid'); ?></p>
                </div>
                <div class="pg-license-modal__footer">
                    <button type="button" class="button pg-license-modal__btn-cancel" data-pg-license-modal-close><?php esc_html_e('Cancelar', 'pulsegrid'); ?></button>
                    <button type="button" class="button button-primary pg-license-modal__btn-confirm pg-license-modal__btn-confirm--danger" data-pg-license-do="deactivate"><?php esc_html_e('Sí, desactivar', 'pulsegrid'); ?></button>
                </div>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>
