<?php
if (!defined('ABSPATH')) {
    exit;
}

add_action('after_setup_theme', function () {
    add_theme_support('title-tag');
    add_theme_support('post-thumbnails');

    register_nav_menus([
        'primary' => __('Primary Menu', 'xkater'),
        'footer'  => __('Footer Menu', 'xkater'),
    ]);
});

add_action('wp_enqueue_scripts', function () {
    $compiled_css_rel_path = '/assets/css/main.css';
    $compiled_css_abs_path = get_template_directory() . $compiled_css_rel_path;

    if (file_exists($compiled_css_abs_path)) {
        wp_enqueue_style(
            'xkater-main',
            get_template_directory_uri() . $compiled_css_rel_path,
            [],
            (string) filemtime($compiled_css_abs_path)
        );

        wp_enqueue_script(
            'xkater-main',
            get_template_directory_uri() . '/assets/js/main.js',
            ['jquery'],
            wp_get_theme()->get('Version'),
            true
        );

        wp_enqueue_script(
            'xkater-dropdown',
            get_template_directory_uri() . '/assets/js/dropdown.js',
            ['jquery'],
            wp_get_theme()->get('Version'),
            true
        );

        return;
    }

    wp_enqueue_style(
        'xkater-style',
        get_stylesheet_uri(),
        [],
        wp_get_theme()->get('Version')
    );
});

add_filter('acf/settings/save_json', function () {
    return get_template_directory() . '/acf-json';
});

add_filter('acf/settings/load_json', function ($paths) {
    $paths[] = get_template_directory() . '/acf-json';
    return $paths;
});
