<?php

namespace Kanzu\StoreVoiceAI;

// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class Scripts
{

    public function enqueue_scripts()
    {

        if (!is_admin() && !is_shop()) {
            return;
        }

        wp_enqueue_style(
            'storevoiceai-call-widget',
            KANZU_STOREVOICEAI_PLUGIN_URL . 'assets/css/call-widget.css',
            [],
            '0.0.7'
        );

        wp_enqueue_script(
            'storevoiceai-eventemitter3',
            KANZU_STOREVOICEAI_PLUGIN_URL . 'assets/vendor/retell/eventemitter3.umd.min.js',
            [],
            '5.0.1',
            true
        );

        wp_enqueue_script(
            'storevoiceai-livekit-client',
            KANZU_STOREVOICEAI_PLUGIN_URL . 'assets/vendor/retell/livekit-client.umd.js',
            [],
            '2.5.1',
            true
        );

        wp_enqueue_script(
            'storevoiceai-retell-globals-shim',
            KANZU_STOREVOICEAI_PLUGIN_URL . 'assets/vendor/retell/retell-globals-shim.js',
            ['storevoiceai-eventemitter3', 'storevoiceai-livekit-client'],
            '0.0.7',
            true
        );

        wp_enqueue_script(
            'storevoiceai-retell-client',
            KANZU_STOREVOICEAI_PLUGIN_URL . 'assets/vendor/retell/retell-client.umd.js',
            ['storevoiceai-retell-globals-shim'],
            '2.0.7',
            true
        );

        wp_enqueue_script(
            'storevoiceai-call-widget',
            KANZU_STOREVOICEAI_PLUGIN_URL . 'assets/js/call-widget.js',
            ['storevoiceai-retell-client'],
            '0.0.7',
            true
        );

        wp_localize_script('storevoiceai-call-widget', 'storevoiceaiCallWidget', [
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce'    => wp_create_nonce('storevoiceai-for-woocommerce-nonce'),
            'i18n'     => [
                'callUs'     => __('Call us', 'storevoiceai-for-woocommerce'),
                'connecting' => __('Connecting…', 'storevoiceai-for-woocommerce'),
                'endCall'    => __('Tap to end call', 'storevoiceai-for-woocommerce'),
            ],
        ]);
    }
}
