<?php

if (!defined('ABSPATH')) {
    exit;
}

class AIEO_Script_Translations {

    
    private static function handles() {
        return array(
            'aieo-address-autocomplete-wc-provider',
            'aieo-admin-navigator',
            'aieo-attribution-admin',
            'aieo-brand-archive-hero-view-script',
            'aieo-brand-gifts',
            'aieo-chat-frontend',
            'aieo-checkout-modal',
            'aieo-command-palette',
            'aieo-complementary',
            'aieo-dmm',
            'aieo-dmm-category-extras-admin',
            'aieo-dmm-navigator',
            'aieo-dmm-related-tab',
            'aieo-export-progress',
            'aieo-google-reviews-editor',
            'aieo-promo-surface-editor',
            'aieo-side-cart',
            'aieo-sticky-atc',
            'aieo-tools-brand-metabox',
            'aieo-variations-gallery-admin',
            'aieo-waitlist',
            'aieo-wishlist-heart',
        );
    }

    public static function init() {
        $cb = array(__CLASS__, 'register');
        add_action('wp_enqueue_scripts',           $cb, PHP_INT_MAX);
        add_action('admin_enqueue_scripts',        $cb, PHP_INT_MAX);
        add_action('enqueue_block_editor_assets',  $cb, PHP_INT_MAX);
        add_action('enqueue_block_assets',         $cb, PHP_INT_MAX);
    }

    public static function register() {
        $languages_path = plugin_dir_path(AIEO_FILE) . 'languages';
        foreach (self::handles() as $handle) {
            if (wp_script_is($handle, 'registered')) {
                wp_set_script_translations($handle, 'ai-eshop-optimizer', $languages_path);
            }
        }
    }
}

AIEO_Script_Translations::init();
