<?php
/**
 * Front-End Switcher Assets
 * SECTION 26 : FRONT-END SWITCHER ASSETS (Modularized)
 */

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

/*==============================================================================
 SECTION 26 : FRONT-END SWITCHER ASSETS (CLEANED for Modern CSS)
==============================================================================*/

add_action('wp_enqueue_scripts', 'reeid_enqueue_switcher_assets');
function reeid_enqueue_switcher_assets()
{
    wp_enqueue_style(
        'reeid-switcher-style',
        plugins_url('assets/css/switcher.css', dirname(__FILE__) . '/../reeid-translate.php'),
        [],
        '1.0'
    );

    wp_enqueue_script(
        'reeid-switcher-script',
        plugins_url('assets/js/switcher.js', dirname(__FILE__) . '/../reeid-translate.php'),
        ['jquery'],
        '1.0',
        true
    );
}

/**
 * Add switcher alignment CSS through WordPress enqueue API.
 */
add_action( 'wp_enqueue_scripts', 'reeid_inject_switcher_alignment', 20 );
function reeid_inject_switcher_alignment() {
    $align = sanitize_key( (string) get_option( 'reeid_switcher_alignment', 'center' ) );

    if ( ! in_array( $align, array( 'left', 'center', 'right' ), true ) ) {
        $align = 'center';
    }

    $css = sprintf(
        '#reeid-switcher-container { text-align: %s; }',
        $align
    );

    wp_add_inline_style( 'reeid-switcher-style', $css );
}