<?php
/**
 * Extensions Page View
 *
 * Displays the available extensions with beautiful card UI.
 *
 * @package Freefactu
 * @since 1.2.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
?>

<div class="freefactu-extensions-page">
    <div class="freefactu-extensions-grid">
        <?php foreach ( $extensions as $freefactu_extension ) : ?>
<?php
$freefactu_is_coming_soon = ! empty( $freefactu_extension['coming_soon'] );
?>
            <div class="freefactu-extension-card <?php echo $freefactu_extension['required'] ? 'is-required' : ''; ?> <?php echo $freefactu_extension['active'] ? 'is-active' : ''; ?> <?php echo $freefactu_is_coming_soon ? 'is-coming-soon' : ''; ?>" data-extension-id="<?php echo esc_attr( $freefactu_extension['id'] ); ?>">
                
                <?php if ( $freefactu_is_coming_soon ) : ?>
                    <div class="freefactu-extension-card__badge freefactu-extension-card__badge--coming-soon">
                        <span class="dashicons dashicons-clock"></span>
                        <?php esc_html_e( 'Próximamente', 'freefactu' ); ?>
                    </div>
                <?php elseif ( $freefactu_extension['required'] ) : ?>
                    <div class="freefactu-extension-card__badge freefactu-extension-card__badge--required">
                        <span class="dashicons dashicons-lock"></span>
                        <?php esc_html_e( 'Requerido', 'freefactu' ); ?>
                    </div>
                <?php elseif ( $freefactu_extension['active'] ) : ?>
                    <div class="freefactu-extension-card__badge freefactu-extension-card__badge--active">
                        <span class="dashicons dashicons-yes-alt"></span>
                        <?php esc_html_e( 'Activo', 'freefactu' ); ?>
                    </div>
                <?php endif; ?>

                <div class="freefactu-extension-card__icon">
                    <span class="dashicons <?php echo esc_attr( $freefactu_extension['icon'] ); ?>"></span>
                </div>

                <div class="freefactu-extension-card__content">
                    <h3 class="freefactu-extension-card__title">
                        <?php echo esc_html( $freefactu_extension['name'] ); ?>
                    </h3>
                    <p class="freefactu-extension-card__description">
                        <?php echo esc_html( $freefactu_extension['description'] ); ?>
                    </p>
                    <div class="freefactu-extension-card__meta">
                        <span class="freefactu-extension-card__version">
                            <span class="dashicons dashicons-tag"></span>
                            v<?php echo esc_html( $freefactu_extension['version'] ); ?>
                        </span>
                        <span class="freefactu-extension-card__author">
                            <span class="dashicons dashicons-admin-users"></span>
                            <?php echo esc_html( $freefactu_extension['author'] ); ?>
                        </span>
                    </div>
                </div>

                <div class="freefactu-extension-card__footer">
                    <?php if ( $freefactu_is_coming_soon ) : ?>
                        <button type="button" class="button freefactu-extension-btn freefactu-extension-btn--coming-soon" disabled>
                            <span class="dashicons dashicons-clock"></span>
                            <?php esc_html_e( 'Próximamente', 'freefactu' ); ?>
                        </button>
                    <?php elseif ( $freefactu_extension['required'] ) : ?>
                        <button type="button" class="button freefactu-extension-btn freefactu-extension-btn--disabled" disabled>
                            <span class="dashicons dashicons-lock"></span>
                            <?php esc_html_e( 'Desactivar', 'freefactu' ); ?>
                        </button>
                    <?php elseif ( $freefactu_extension['active'] ) : ?>
                        <button type="button" 
                                class="button freefactu-extension-btn freefactu-extension-btn--deactivate" 
                                data-extension-id="<?php echo esc_attr( $freefactu_extension['id'] ); ?>"
                                data-action="deactivate">
                            <span class="dashicons dashicons-no-alt"></span>
                            <?php esc_html_e( 'Desactivar', 'freefactu' ); ?>
                        </button>
                    <?php else : ?>
                        <button type="button" 
                                class="button button-primary freefactu-extension-btn freefactu-extension-btn--activate" 
                                data-extension-id="<?php echo esc_attr( $freefactu_extension['id'] ); ?>"
                                data-action="activate">
                            <span class="dashicons dashicons-yes"></span>
                            <?php esc_html_e( 'Activar', 'freefactu' ); ?>
                        </button>
                    <?php endif; ?>
                </div>

                <?php if ( $freefactu_extension['active'] && ! $freefactu_extension['required'] ) : ?>
                    <div class="freefactu-extension-card__glow"></div>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>

    <div class="freefactu-extensions-footer">
        <div class="freefactu-extensions-footer__info">
            <span class="dashicons dashicons-info-outline"></span>
            <p><?php esc_html_e( 'Las extensiones requeridas son componentes esenciales del plugin y no pueden ser desactivadas. Las extensiones opcionales amplían las funcionalidades y pueden activarse o desactivarse según tus necesidades.', 'freefactu' ); ?></p>
        </div>
    </div>
</div>


