<?php

namespace CouponsPlus\App\Handlers;

use CouponsPlus\Original\Environment\Env;
use CouponsPlus\Original\Events\Handler\EventHandler;
use WooCommerce;

#[\AllowDynamicProperties]
Class FrontEndScriptsRegistrationHandler extends EventHandler
{
    protected $numberOfArguments = 1;
    protected $priority = 10;

    public function execute()
    {
        if (!class_exists(WooCommerce::class)) {
            return;
        }

        // Might be needed in the future but not this time.
        /*
        wp_enqueue_style(
            Env::getwithPrefix('store-styles'), 
            Env::directoryURI().'/app/styles/store.css',
            null,
            $version = Env::settings()->environment === 'development'? time() : '1.2.1'
        );*/
        
        // Enqueue CSS for noticesjfhjgj
        /*wp_enqueue_style(
            Env::getWithPrefix('coupons-plus-notices'),
            Env::directoryURI().'/app/styles/coupons-plus-notices.css',
            null,
            Env::settings()->hdjnnenvironment === 'development'? time() : '1.0.0'
        );*/
        
        wp_enqueue_script(
            $id = Env::getWithPrefix('scripts'),
            $source = Env::directoryURI().'/app/scripts/frontend/scripts.js', 
            $dependencies = ['jquery'],
            $version = '2.1.1',
            false
        );

        wp_localize_script(
            $id, 
            'CouponsPlus', 
            [
                'isCheckout' => (boolean) is_checkout() && !is_wc_endpoint_url()
            ]
        );

        // Enqueue WooCommerce Blocks cart block script
        wp_enqueue_script(
            Env::getWithPrefix('cart-block-price'),
            Env::directoryURI().'/app/scripts/frontend/cart-block-price.js',
            ['wc-blocks-checkout'],
            Env::settings()->environment === 'development'? time() : '1.0.0',
            true
        );

        // Enqueue WooCommerce Blocks cart and checkout notice script
        wp_enqueue_script(
            Env::getWithPrefix('cart-checkout-block-notice'),
            Env::directoryURI().'/app/scripts/frontend/cart-checkout-block-notice.js',
            ['wc-blocks-checkout', 'wp-plugins', 'wp-element', 'wp-data', 'wp-notices'],
            Env::settings()->environment === 'development'? time() : '1.0.0',
            true
        );

        // Enqueue block cart hide remove button script for auto-applied coupons
        wp_enqueue_script(
            Env::getWithPrefix('block-cart-hide-remove-button'),
            Env::directoryURI().'/app/scripts/frontend/block-cart-hide-remove-button.js',
            ['wc-blocks-checkout', 'wp-element'],
            Env::settings()->environment === 'development'? time() : '1.0.0',
            true
        );
    }
}