<?php

namespace MovieEngine\Admin\Player\Tabs;

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

class SourcesTab {

    public static function render($options) {
        // Allow Pro plugin to take over rendering if active
        if (has_action('movie_engine_render_pro_sources')) {
            do_action('movie_engine_render_pro_sources', $options);
            return;
        }
?>
        <input type="hidden" name="movie_engine_player_settings[active_sub_tab]" value="player_sources">
        <div class="movie-engine-card">
            <div class="movie-engine-card-header">
                <h3><span class="fa-solid fa-network-wired"></span> <?php esc_html_e('Sources', 'cine-movie-engine'); ?></h3>
            </div>
            <div class="movie-engine-card-body">
                <div class="me-pro-notice-box">
                    <span class="dashicons dashicons-lock"></span>
                    <div class="me-pro-notice-message">
                        <strong><?php esc_html_e('Player Sources', 'cine-movie-engine'); ?></strong>
                        <p><?php esc_html_e('is a PRO feature. Upgrade to unlock multiple server support.', 'cine-movie-engine'); ?></p>
                    </div>
                    <a href="<?php echo esc_url(\MovieEngine\Admin\Upgrade::get_pro_url('pricing')); ?>" target="_blank" class="button button-primary me-pro-notice-btn">
                        <?php esc_html_e('Upgrade to Pro', 'cine-movie-engine'); ?>
                    </a>
                </div>

                <div class="me-locked-feature">
                    <div class="movie-engine-form-group">
                        <label class="movie-engine-checkbox-label">
                            <input type="checkbox" disabled checked>
                            <span><?php esc_html_e('Enable Multiple Sources', 'cine-movie-engine'); ?></span>
                        </label>
                    </div>
                    <div class="movie-engine-form-group">
                        <label for="default_source"><?php esc_html_e('Default Source', 'cine-movie-engine'); ?></label>
                        <select id="default_source" class="movie-engine-select" disabled>
                            <option selected><?php esc_html_e('Server 1', 'cine-movie-engine'); ?></option>
                        </select>
                    </div>
                    <div class="movie-engine-form-group">
                        <label class="movie-engine-checkbox-label">
                            <input type="checkbox" disabled checked>
                            <span><?php esc_html_e('Auto Fallback on Error', 'cine-movie-engine'); ?></span>
                        </label>
                    </div>
                    <div class="movie-engine-form-group">
                        <label class="movie-engine-checkbox-label">
                            <input type="checkbox" disabled checked>
                            <span><?php esc_html_e('Show Source Tabs in Player', 'cine-movie-engine'); ?></span>
                        </label>
                    </div>
                    <div class="movie-engine-form-group">
                        <label class="movie-engine-checkbox-label">
                            <input type="checkbox" disabled>
                            <span><?php esc_html_e('Randomize Source Order', 'cine-movie-engine'); ?></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>

        <div class="movie-engine-card">
            <div class="movie-engine-card-header">
                <h3><span class="fa-solid fa-gauge-high"></span> <?php esc_html_e('Quality', '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_quality_selector]" value="0">
                        <input type="checkbox" name="movie_engine_player_settings[enable_quality_selector]" value="1" <?php checked($options['movie_engine_enable_quality_selector'] ?? ($options['enable_quality_selector'] ?? 1), 1); ?>>
                        <span><?php esc_html_e('Enable Quality Selector', 'cine-movie-engine'); ?></span>
                    </label>
                </div>
                <div class="movie-engine-form-group">
                    <label for="default_quality"><?php esc_html_e('Default Quality', 'cine-movie-engine'); ?></label>
                    <select id="default_quality" name="movie_engine_player_settings[default_quality]" class="movie-engine-select">
                        <?php
                        $default_quality = $options['movie_engine_default_quality'] ?? ($options['default_quality'] ?? 'auto');
                        ?>
                        <option value="auto" <?php selected($default_quality, 'auto'); ?>><?php esc_html_e('Auto', 'cine-movie-engine'); ?></option>
                        <option value="4k" <?php selected($default_quality, '4k'); ?>><?php esc_html_e('4K', 'cine-movie-engine'); ?></option>
                        <option value="1080p" <?php selected($default_quality, '1080p'); ?>><?php esc_html_e('1080p', 'cine-movie-engine'); ?></option>
                        <option value="720p" <?php selected($default_quality, '720p'); ?>><?php esc_html_e('720p', 'cine-movie-engine'); ?></option>
                        <option value="480p" <?php selected($default_quality, '480p'); ?>><?php esc_html_e('480p', 'cine-movie-engine'); ?></option>
                    </select>
                </div>
                <div class="movie-engine-form-group">
                    <label class="movie-engine-checkbox-label">
                        <input type="hidden" name="movie_engine_player_settings[auto_quality]" value="0">
                        <input type="checkbox" name="movie_engine_player_settings[auto_quality]" value="1" <?php checked($options['movie_engine_auto_quality'] ?? ($options['auto_quality'] ?? 1), 1); ?>>
                        <span><?php esc_html_e('Auto Quality Detection', '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[buffer_switch]" value="0">
                        <input type="checkbox" name="movie_engine_player_settings[buffer_switch]" value="1" <?php checked($options['movie_engine_buffer_switch'] ?? ($options['buffer_switch'] ?? 1), 1); ?>>
                        <span><?php esc_html_e('Allow Auto Switch When Buffering', 'cine-movie-engine'); ?></span>
                    </label>
                </div>
            </div>
        </div>
<?php
    }
}
