<?php

namespace MovieEngine\Admin\Player\Tabs;

if (! defined("ABSPATH")) {
    exit; // Exit if accessed directly
}

class SubtitlesTab {

    public static function render($options) {
?>
        <input type="hidden" name="movie_engine_player_settings[active_sub_tab]" value="player_subtitles">
        <div class="movie-engine-card">
            <div class="movie-engine-card-header">
                <h3><span class="fa-solid fa-closed-captioning"></span> <?php esc_html_e('Subtitle Display', 'cine-movie-engine'); ?></h3>
            </div>
            <div class="movie-engine-card-body">
                <div class="movie-engine-form-group">
                    <label class="movie-engine-checkbox-label">
                        <input type="hidden" name="movie_engine_player_settings[enable_subtitles]" value="0">
                        <input type="checkbox" name="movie_engine_player_settings[enable_subtitles]" value="1" <?php checked($options['movie_engine_enable_subtitles'] ?? ($options['enable_subtitles'] ?? 1), 1); ?>>
                        <span><?php esc_html_e('Enable Subtitles', 'cine-movie-engine'); ?></span>
                    </label>
                </div>
                <div class="movie-engine-form-group">
                    <label for="default_subtitle_lang"><?php esc_html_e('Default Subtitle Language', 'cine-movie-engine'); ?></label>
                    <input type="text" id="default_subtitle_lang" name="movie_engine_player_settings[default_subtitle_lang]" value="<?php echo esc_attr($options['movie_engine_default_subtitle_lang'] ?? ($options['default_subtitle_lang'] ?? 'en')); ?>" class="movie-engine-input" placeholder="en">
                </div>
                <div class="movie-engine-form-group">
                    <label for="subtitle_state"><?php esc_html_e('Default Subtitle State', 'cine-movie-engine'); ?></label>
                    <select id="subtitle_state" name="movie_engine_player_settings[subtitle_state]" class="movie-engine-select">
                        <?php
                        $subtitle_state = $options['movie_engine_subtitle_state'] ?? ($options['subtitle_state'] ?? 'off');
                        ?>
                        <option value="on" <?php selected($subtitle_state, 'on'); ?>><?php esc_html_e('On', 'cine-movie-engine'); ?></option>
                        <option value="off" <?php selected($subtitle_state, 'off'); ?>><?php esc_html_e('Off', 'cine-movie-engine'); ?></option>
                    </select>
                </div>
                <div class="movie-engine-form-group">
                    <label for="subtitle_size"><?php esc_html_e('Subtitle Font Size', 'cine-movie-engine'); ?></label>
                    <select id="subtitle_size" name="movie_engine_player_settings[subtitle_size]" class="movie-engine-select">
                        <?php
                        $subtitle_size = $options['movie_engine_subtitle_size'] ?? ($options['subtitle_size'] ?? 'medium');
                        ?>
                        <option value="small" <?php selected($subtitle_size, 'small'); ?>><?php esc_html_e('Small', 'cine-movie-engine'); ?></option>
                        <option value="medium" <?php selected($subtitle_size, 'medium'); ?>><?php esc_html_e('Medium', 'cine-movie-engine'); ?></option>
                        <option value="large" <?php selected($subtitle_size, 'large'); ?>><?php esc_html_e('Large', 'cine-movie-engine'); ?></option>
                        <option value="xl" <?php selected($subtitle_size, 'xl'); ?>><?php esc_html_e('Extra Large', 'cine-movie-engine'); ?></option>
                    </select>
                </div>
                <div class="movie-engine-form-group">
                    <label for="subtitle_color"><?php esc_html_e('Subtitle Color', 'cine-movie-engine'); ?></label>
                    <input type="color" id="subtitle_color" name="movie_engine_player_settings[subtitle_color]" value="<?php echo esc_attr($options['movie_engine_subtitle_color'] ?? ($options['subtitle_color'] ?? '#ffffff')); ?>" class="movie-engine-color-picker">
                </div>
                <div class="movie-engine-form-group">
                    <label for="subtitle_bg_color"><?php esc_html_e('Subtitle Background Color', 'cine-movie-engine'); ?></label>
                    <input type="color" id="subtitle_bg_color" name="movie_engine_player_settings[subtitle_bg_color]" value="<?php echo esc_attr($options['movie_engine_subtitle_bg_color'] ?? ($options['subtitle_bg_color'] ?? '#000000')); ?>" class="movie-engine-color-picker">
                </div>
                <div class="movie-engine-form-group">
                    <label for="subtitle_bg_opacity"><?php esc_html_e('Subtitle Background Opacity', 'cine-movie-engine'); ?></label>
                    <input type="range" id="subtitle_bg_opacity" name="movie_engine_player_settings[subtitle_bg_opacity]" min="0" max="100" value="<?php echo esc_attr($options['movie_engine_subtitle_bg_opacity'] ?? ($options['subtitle_bg_opacity'] ?? 50)); ?>" class="movie-engine-range">
                </div>
                <div class="movie-engine-form-group">
                    <label class="movie-engine-checkbox-label">
                        <input type="hidden" name="movie_engine_player_settings[subtitle_shadow]" value="0">
                        <input type="checkbox" name="movie_engine_player_settings[subtitle_shadow]" value="1" <?php checked($options['movie_engine_subtitle_shadow'] ?? ($options['subtitle_shadow'] ?? 1), 1); ?>>
                        <span><?php esc_html_e('Enable Subtitle Outline / Shadow', 'cine-movie-engine'); ?></span>
                    </label>
                </div>
                <div class="movie-engine-form-group">
                    <label class="movie-engine-checkbox-label">
                        <input type="hidden" name="movie_engine_player_settings[user_upload]" value="0">
                        <input type="checkbox" name="movie_engine_player_settings[user_upload]" value="1" <?php checked($options['movie_engine_user_upload'] ?? ($options['user_upload'] ?? 0), 1); ?>>
                        <span><?php esc_html_e('Allow User Subtitle Upload (Admin Only)', 'cine-movie-engine'); ?></span>
                    </label>
                </div>
            </div>
        </div>
<?php
    }
}
