<?php
if ( ! defined( 'ABSPATH' ) ) exit;

class CAMANAGER_Frontend {

    public function __construct() {
        add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ] );
        add_action( 'wp_body_open', [ $this, 'add_skip_link' ] );
        add_action( 'wp_footer', [ $this, 'maybe_add_toolbar' ] );
    }

    public function enqueue_assets() {
        wp_enqueue_style( 'camanager-frontend', CAMANAGER_URL . 'assets/css/frontend.css', [], CAMANAGER_VERSION );
        wp_enqueue_script( 'camanager-frontend', CAMANAGER_URL . 'assets/js/frontend.js', [], CAMANAGER_VERSION, true );
        // Pass attributes to JS
        $attributes = get_option( 'camanager_attributes', [] );
        wp_localize_script( 'camanager-frontend', 'camFrontend', [
            'attributes' => $attributes,
        ]);
    }

    public function add_skip_link() {
        echo '<a href="#main" class="camanager-skip-link">' . esc_html__( 'Skip to content', 'custom-attributes-manager' ) . '</a>';
    }

    public function maybe_add_toolbar() {
        $licensed = get_option( 'camanager_license', false );
        if ( $licensed ) {
            echo '<div id="camanager-toolbar">
                    <button data-action="increase-font">A+</button>
                    <button data-action="decrease-font">A-</button>
                    <button data-action="toggle-contrast">Contrast</button>
                 </div>';
        }
    }
}
