<?php

defined('ABSPATH') or die('No script kiddies please!!');
if (!class_exists('CIWS_Enqueue')) {
    class CIWS_Enqueue
    {
        function __construct()
        {
            add_action('wp_enqueue_scripts', [$this, 'register_ciws_frontend_assets']);
            add_action('admin_enqueue_scripts', [$this, 'register_ciws_admin_assets']);
            add_action('enqueue_block_editor_assets', [$this, 'ciws_register_whatsapp_block']);
        }


        function register_ciws_admin_assets()
        {

            wp_enqueue_style('wp-color-picker');
            wp_enqueue_media();
            wp_enqueue_style('ciws-backend-style', CIWS_URL . '/assets/css/ciws-backend.css', array(), CIWS_VERSION);
            wp_enqueue_script('ciws-backend-script', CIWS_URL . '/assets/js/ciws-backend.js', array('jquery', 'wp-color-picker'), filemtime(CIWS_PATH . '/assets/js/ciws-backend.js'));

            wp_enqueue_style(
                'ciws-fontawesome-style',
                CIWS_URL . '/assets/css/ciws-fontawesome.css',
                array(),
                CIWS_VERSION
            );
        }
        
        function register_ciws_frontend_assets()
        {
            wp_enqueue_script('ciws-frontend-script', CIWS_URL . '/assets/js/ciws-frontend.js', array('jquery'), filemtime(CIWS_PATH . '/assets/js/ciws-frontend.js'));
            wp_enqueue_style('ciws-frontend-style', CIWS_URL . '/assets/css/ciws-frontend.css', array(), CIWS_VERSION);
        }

        function ciws_register_whatsapp_block()
        {
            

            wp_enqueue_script(
                'ciws-whatsapp-block',
                CIWS_URL . '/assets/js/ciws-whatsapp-block.js',
                array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components'),
                filemtime(CIWS_PATH . '/assets/js/ciws-whatsapp-block.js')
            );


            wp_localize_script('ciws-whatsapp-block', 'ciwsData', array(
                'pluginURL' => CIWS_URL,
                'imageUrl' => CIWS_IMG_DIR
            ));
        }
    }

    new CIWS_Enqueue();
}
