<?php

if (! defined('ABSPATH')) {
    exit;
} class PufferGo_I18n_Loader
{
    public const JS_HANDLES = array('puffergo-dashboard', 'puffergo-ai-site-builder', 'puffergo-ai-admin-app', 'puffergo-ai-page-builder', 'puffergo-page-ai-chat', 'puffergo-tool', 'puffergo-settings', 'puffergo-site-profile', 'puffergo-wp-dashboard-banner', 'puffergo-inquiries', 'puffergo-commands', 'puffergo-translate-center', );

    public static function init()
    {
        $instance = new self();
        add_action('plugins_loaded', array($instance, 'load_php_translations'));
        add_action('admin_enqueue_scripts', array($instance, 'load_script_translations'), 100);
        add_action('enqueue_block_editor_assets', array($instance, 'load_script_translations'), 100);
    }

    public function load_php_translations()
    {
        if (! defined('PUFFERGO_PLUGIN_FILE')) {
            return;
        } $rel = dirname(plugin_basename(PUFFERGO_PLUGIN_FILE)) . '/languages';
        load_plugin_textdomain('puffergo', false, $rel);
        $locale = function_exists('determine_locale') ? determine_locale() : get_locale();
        $mofile = plugin_dir_path(PUFFERGO_PLUGIN_FILE) . 'languages/puffergo-' . $locale . '.mo';

        if (is_readable($mofile)) {
            load_textdomain('puffergo', $mofile, $locale);
        }
    }

    public function load_script_translations()
    {
        $plugin_rel_path = plugin_basename(dirname(dirname(__FILE__))) . '/languages';
        $languages_dir = plugin_dir_path(dirname(__FILE__)) . 'languages';

        foreach (self::JS_HANDLES as $handle) {
            wp_set_script_translations($handle, 'puffergo', $languages_dir);
        }
    }
}
