<?php
/**
 * Assets.
 *
 * @package ALFASMART
 */

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

add_action('wp_enqueue_scripts', function () {
    wp_enqueue_style('alfasmart-fonts', 'https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&family=Inter:wght@400;500;600;700;800;900&family=Montserrat:wght@400;500;600;700&family=Noto+Kufi+Arabic:wght@500;600;700;800&family=Space+Grotesk:wght@500;600;700&family=Unbounded:wght@700&display=swap', array(), null);
    wp_enqueue_style('bootstrap-grid', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap-grid.min.css', array(), '5.3.3');
    wp_enqueue_style('fontawesome', 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.css', array(), '6.5.2');
    wp_enqueue_style('swiper', 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css', array(), '11');
    wp_enqueue_style('fancybox', 'https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.css', array(), '5.0');

    $style_path = ALFASMART_DIR . '/assets/css/style.css';
    wp_enqueue_style('alfasmart-style', ALFASMART_URI . '/assets/css/style.css', array('bootstrap-grid', 'fontawesome', 'swiper', 'fancybox'), file_exists($style_path) ? filemtime($style_path) : ALFASMART_VERSION);

    wp_enqueue_script('jquery');
    wp_enqueue_script('gsap', 'https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js', array(), '3.12.5', true);
    wp_enqueue_script('gsap-scrolltrigger', 'https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/ScrollTrigger.min.js', array('gsap'), '3.12.5', true);
    wp_enqueue_script('swiper', 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js', array(), '11', true);
    wp_enqueue_script('fancybox', 'https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.umd.js', array(), '5.0', true);

    $script_path = ALFASMART_DIR . '/assets/js/plugin.js';
    wp_enqueue_script('alfasmart-plugin', ALFASMART_URI . '/assets/js/plugin.js', array('jquery', 'gsap', 'gsap-scrolltrigger', 'swiper', 'fancybox'), file_exists($script_path) ? filemtime($script_path) : ALFASMART_VERSION, true);
    wp_localize_script('alfasmart-plugin', 'alfasmartTheme', array(
        'homeUrl'       => function_exists('pll_home_url') ? pll_home_url(alfasmart_lang()) : home_url('/'),
        'assetsUrl'     => ALFASMART_URI . '/assets',
        'lightLogo'     => alfasmart_get_option_image_url('site_logo', 'logo.webp'),
        'darkLogo'      => alfasmart_get_option_image_url('footer_logo', 'logo-footer.webp'),
        'aboutUrl'      => alfasmart_url('about'),
        'companiesUrl'  => get_post_type_archive_link('companies') ?: home_url('/companies/'),
        'servicesUrl'   => get_post_type_archive_link('services') ?: home_url('/services/'),
        'contactUrl'    => alfasmart_url('contact'),
    ));
}, 20);

add_action('wp_enqueue_scripts', function () {
    wp_dequeue_style('wp-block-library');
    wp_dequeue_style('wp-block-library-theme');
    wp_dequeue_style('global-styles');
    wp_dequeue_style('classic-themes-styles');
}, 100);
