<?php
/**
 * Frontend Prototype Player Controller
 * Renders full-screen InVision playback experience
 */

class Proto_Preview_Player {

    protected $db;

    public function __construct(Proto_Preview_DB $db) {
        $this->db = $db;
    }

    public function init() {
        add_action('init', [$this, 'add_rewrite_rules']);
        add_filter('query_vars', [$this, 'add_query_vars']);
        add_action('template_redirect', [$this, 'template_redirect_player']);
    }

    public function add_rewrite_rules() {
        add_rewrite_rule('^proto-preview/?$', 'index.php?proto_preview=1', 'top');
    }

    public function add_query_vars($vars) {
        $vars[] = 'proto_preview';
        $vars[] = 'project';
        $vars[] = 'page_id_screen';
        $vars[] = 'layout';
        $vars[] = 'token';
        return $vars;
    }

    public function template_redirect_player() {
        $is_preview = get_query_var('proto_preview') || isset($_GET['proto_preview']);
        if (!$is_preview) {
            return;
        }

        // Render full screen player template directly
        require_once PROTO_PREVIEW_PLUGIN_DIR . 'templates/player.php';
        exit;
    }
}
