<?php

#/usr/bin/chromium-browser --ignore-certificate-errors

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

// default server address, port, and entry point can be customized in vite.config.js
define('VITE_SERVER', 'https://vetandlife.ru:5443'); //http://185.175.44.194:5173/src/main.js
define('VITE_ENTRY_POINT', '/src/main.js');

// Define dist directory, base uri, and path
define('DIST_DIR', 'dist');
define('DIST_URI', get_template_directory_uri() . '/' . DIST_DIR);
define('DIST_PATH', get_template_directory() . '/' . DIST_DIR);


add_action( 'wp_enqueue_scripts', function () {
    
    if (defined('VITE_ENV') && VITE_ENV === 'dev') {
        function vite_head_module_hook() {
            echo '<script type="module" crossorigin src="'. VITE_SERVER .'/@vite/client"></script>';
            echo '<script type="module" crossorigin src="'. VITE_SERVER . VITE_ENTRY_POINT . '"></script>';
        }
        add_action( 'wp_head', 'vite_head_module_hook' );
    } else {

        $fstyle = '/frontend/dist/assets/style.css';
        $fscript = '/frontend/dist/assets/main.js';

        // Production version
        $style_ver = filemtime(get_template_directory() . $fstyle);
        $script_ver = filemtime(get_template_directory() . $fscript);
        
        wp_enqueue_style('vij-style', get_template_directory_uri() . $fstyle, array(), $style_ver);
        wp_enqueue_script('vij-script', get_template_directory_uri() . $fscript, array(), $script_ver);
    
    }
});






