<?php

/**
 * Mediora functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Mediora
 * @since 1.0
 */


if (!function_exists('mediora_support')):

    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * @since Mediora 1.0
     *
     * @return void
     */
    function mediora_support()
    {
        add_filter('woocommerce_get_image_size_thumbnail', function ($size) {
            return array(
                'width' => 800,
                'height' => 800,
                'crop' => 1,
            );
        });
        // Load theme textdomain for translation-ready strings.
        load_theme_textdomain('mediora', get_template_directory() . '/languages');

        // Add support for block styles.
        add_theme_support('wp-block-styles');

        // Enqueue editor styles.
        add_editor_style('style.css');

        // Experimental support for adding blocks inside nav menus
        add_theme_support('block-nav-menus');

        // Add support for experimental link color control.
        add_theme_support('experimental-link-color');
    }

endif;

add_action('after_setup_theme', 'mediora_support');

if (!function_exists('mediora_styles')):

    /**
     * Enqueue styles.
     *
     * @since Mediora 1.0
     *
     * @return void
     */
    function mediora_styles()
    {
        // Enqueue theme stylesheet.
        wp_enqueue_style(
            'mediora-style',
            get_template_directory_uri() . '/style.css',
            array(),
            mediora_file_version('/style.css')
        );
    }

endif;

add_action('wp_enqueue_scripts', 'mediora_styles');

if (!function_exists('mediora_register_block_styles')):

    /**
     * Register custom block styles.
     *
     * @since Mediora 1.0
     *
     * @return void
     */
    function mediora_register_block_styles()
    {
        register_block_style(
            'core/group',
            array(
                'name' => 'mediora-card',
                'label' => __('Card', 'mediora'),
                'inline_style' => '.is-style-mediora-card{background:var(--wp--preset--color--background);border:1px solid var(--wp--preset--color--border-color,#e5e7eb);border-radius:12px;box-shadow:0 12px 30px rgba(0,0,0,.06);padding:clamp(1.25rem,2vw,2rem);}',
            )
        );

        register_block_style(
            'core/button',
            array(
                'name' => 'mediora-arrow',
                'label' => __('Arrow', 'mediora'),
                'inline_style' => '.is-style-mediora-arrow .wp-block-button__link{display:inline-flex;align-items:center;gap:.5rem;}.is-style-mediora-arrow .wp-block-button__link::after{content:"\\2192";font-weight:700;transition:transform .2s ease;}.is-style-mediora-arrow .wp-block-button__link:hover::after{transform:translateX(4px);}',
            )
        );

        register_block_style(
            'core/image',
            array(
                'name' => 'mediora-soft-shadow',
                'label' => __('Soft Shadow', 'mediora'),
                'inline_style' => '.is-style-mediora-soft-shadow img{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.12);}',
            )
        );
    }

endif;

add_action('init', 'mediora_register_block_styles');

/**
 * Get file version with respect to file modified date.
 */
function mediora_file_version($file_path)
{
    return gmdate('ymd-Gis', filemtime(get_theme_file_path($file_path)));
}

// Add block patterns
require get_theme_file_path('/inc/block-patterns.php');

/**
 * Load Theme About Page
 */
require get_theme_file_path('/inc/about-admin/theme-info.php');
