<?php

namespace BWDK\Front;

use BWDK\Support\Constant;

class Assets
{

    public $options;
    public function register(): void
    {
        $this->options = get_option(Constant::BWDK_OPTION_NAME);

        add_action('wp_enqueue_scripts', [$this, 'enqueue']);
        add_action( 'wp_head', [$this, 'bwdk_load_custom_css'],9999 );
        add_action( 'wp_footer', [$this, 'bwdk_load_custom_js'],9999 );

    }

    public function enqueue(): void
    {




        wp_enqueue_style(
            'bwdk-front-style',
            BWDK_PUBLIC_CSS . 'bwdk-public.css',
            [],
            '1.0.0'
        );


        wp_enqueue_script(
            'bwdk-front-script',
            BWDK_PUBLIC_JS . 'bwdk-public.js',
            ['jquery'],
            '1.0.0',
            true
        );




        wp_localize_script('bwdk-front-script', 'bwdk_ajax', [
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce'    => wp_create_nonce('bwdk_nonce')
        ]);

    }
    function bwdk_load_custom_css() {
        $custom_css = $this->options["custom"]["css"]??"";
        if ( ! empty( $custom_css ) ) {
            echo '<style>' . wp_strip_all_tags( $custom_css ) . '</style>';
        }
    }

    function bwdk_load_custom_js() {
        $custom_js = $this->options["custom"]["js"]??"";
        if ( ! empty( $custom_js ) ) {
            echo '<script>' . wp_strip_all_tags( $custom_js ) . '</script>';
        }
    }

}
