<?php
namespace Avision;

class Avision_Assets {
    private $css_files = [];
    private $js_files = [];

    public function init() {
        $this->register_styles();
        $this->register_scripts();
    }

    private function register_styles() {
        $this->css_files = [
            'avision-landing' => 'assets/css/landing.css',
            'avision-main' => 'assets/css/main.css',
            'avision-nav' => 'assets/css/nav.css',
            'avision-header' => 'assets/css/header.css',
            'avision-score' => 'assets/css/score.css',
            'avision-chat' => 'assets/css/chat.css',
            'avision-levels' => 'assets/css/levels.css',
            'avision-dashboard' => 'assets/css/dashboard.css',
            'avision-chatbot' => 'assets/css/chatbot.css',
            'avision-responsive' => 'assets/css/responsive.css'
        ];
    }

    private function register_scripts() {
        $this->js_files = [
            'avision-i18n' => 'assets/js/i18n.js',
            'avision-main' => 'assets/js/main.js',
            'avision-levels' => 'assets/js/levels.js',
            'avision-score' => 'assets/js/score.js',
            'avision-chatbot' => 'assets/js/chatbot.js',
            'avision-confetti' => 'assets/js/confetti.js'
        ];
    }

    public function get_css_files() {
        return $this->css_files;
    }

    public function get_js_files() {
        return $this->js_files;
    }

    public function enqueue_all() {
        $base_url = $this->get_base_url();
        $output = '';
        
        foreach ($this->css_files as $handle => $path) {
            $output .= '<link rel="stylesheet" href="' . $base_url . $path . '?v=' . AVISION_VERSION . '">' . "\n";
        }
        
        return $output;
    }

    public function enqueue_scripts() {
        $base_url = $this->get_base_url();
        $output = '';
        
        foreach ($this->js_files as $handle => $path) {
            $output .= '<script src="' . $base_url . $path . '?v=' . AVISION_VERSION . '"></script>' . "\n";
        }
        
        return $output;
    }

    private function get_base_url() {
        $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
        $host = $_SERVER['HTTP_HOST'] ?? 'localhost';
        return $protocol . '://' . $host . '/wordpress/wp-content/plugins/avision-dashboard/';
    }
}
