<?php
if ( ! defined( 'ABSPATH' ) ) exit;

class Sifency_Addons_Admin_Themes {

    /**
     * Renders the entire dynamic theme library page with filtering functionality.
     */
    public function render() {
        $themes = [
            [
                'name' => 'Anglo', 'image' => 'https://public-files.gumroad.com/dhxeatezlyqpkn1l05jp32x93ici', 'live' => 'https://sifency.com/anglo', 'buy'  => 'https://sifency.gumroad.com/l/portnew?wanted=true', 'category' => 'Business', 'is_pro' => true,
            ],
            [
                'name' => 'Portnew', 'image' => 'https://public-files.gumroad.com/wippmpzkx3ghgrsovxolink4czgr', 'live' => 'https://sifency.com/portnew', 'buy'  => 'https://sifency.gumroad.com/l/anglo?wanted=true', 'category' => 'Creative', 'is_pro' => true,
            ],
        ];
        
        $categories = array_unique( wp_list_pluck( $themes, 'category' ) );
        array_unshift( $categories, 'All' );
        
        ?>

        <div class="sifency-dashboard-layout">
            
            <!-- CATEGORY TABS (Navigation) -->
            <div class="sifency-dashboard-nav">
                <?php foreach ( $categories as $index => $cat ) : ?>
                    <button class="sifency-nav-item sifency-admin-btn <?php echo ( 0 === $index ) ? 'active' : ''; ?>" data-filter="<?php echo esc_attr( strtolower( $cat ) ); ?>">
                        <?php echo esc_html( $cat ); ?>
                    </button>
                <?php endforeach; ?>
            </div>

            <!-- THEME GRID (Content) -->
            <div class="sifency-theme-grid">
                <?php foreach ( $themes as $theme ) : 
                    $pro_label = $theme['is_pro'] ? '<span class="sifency-pro-badge sifency-theme-pro-badge">Pro</span>' : '';
                    ?>
                    <div class="sifency-theme-card" data-category="<?php echo esc_attr( strtolower( $theme['category'] ) ); ?>">
                        <div class="sifency-theme-thumb">
                            <img src="<?php echo esc_url( $theme['image'] ); ?>" alt="<?php echo esc_attr( $theme['name'] ); ?>">
                            <div class="sifency-theme-hover">
                                <a href="<?php echo esc_url( $theme['live'] ); ?>" target="_blank" class="sifency-admin-btn live-link-btn"><span><?php esc_html_e( 'Live Preview', 'sifency-addons' ); ?></span></a>
                            </div>
                            <?php echo wp_kses_post($pro_label); // Badge is already escaped HTML ?>
                        </div>
                        <div class="sifency-theme-info">
                            <h3 class="sifency-theme-title"><?php echo esc_html( $theme['name'] ); ?></h3>
                            <a href="<?php echo esc_url( $theme['buy'] ); ?>" target="_blank" class="sifency-upgrade-btn sifency-admin-btn"><?php esc_html_e( 'Buy Now', 'sifency-addons' ); ?></a>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>

        <?php
    }
}