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

/**
 * GLSE_Theme_Compat - Theme integration loader.
 *
 * Detects the active WordPress theme and loads the matching compat file from
 * includes/compat/themes/. Each compat class extends GLSE_Compat_Base and is
 * entirely self-contained.
 */
final class GLSE_Theme_Compat {

    /**
     * Map of WordPress template slugs (lowercase) to their compat class names.
     */
    private const SUPPORTED = [
        'shoptimizer' => 'GLSE_Compat_Shoptimizer',
        'astra'       => 'GLSE_Compat_Astra',
        'kadence'     => 'GLSE_Compat_Kadence',
    ];

    /**
     * Detect active theme and load matching compat class.
     *
     * @since 1.4.0
     */
    public function __construct() {
        $theme = strtolower( get_template() );

        if ( ! isset( self::SUPPORTED[ $theme ] ) ) {
            return;
        }

        $base_dir = __DIR__ . '/compat/';
        $class    = self::SUPPORTED[ $theme ];

        require_once $base_dir . 'class-compat-base.php';

        $file = $base_dir . 'themes/' . basename( $theme ) . '.php';

        if ( file_exists( $file ) ) {
            require_once $file;
            new $class();
        }
    }
}
