<?php
/**
 * WE88 Fiesta — Theme functions
 *
 * @package WE88_Fiesta
 */

defined( 'ABSPATH' ) || exit;

if ( ! defined( 'WE88_FIESTA_VERSION' ) ) {
	define( 'WE88_FIESTA_VERSION', '1.0.2' );
}

if ( file_exists( __DIR__ . '/inc/provisioner.php' ) ) {
	require_once __DIR__ . '/inc/provisioner.php';
}

/**
 * Theme setup: declare feature support and add image sizes.
 */
function we88_fiesta_setup(): void {
	load_theme_textdomain( 'we88-fiesta', get_template_directory() . '/languages' );

	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'editor-styles' );
	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'custom-logo', [
		'height'      => 80,
		'width'       => 240,
		'flex-height' => true,
		'flex-width'  => true,
	] );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'html5', [ 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script' ] );

	add_editor_style( 'assets/css/style.css' );

	register_nav_menus( [
		'primary' => __( 'Primary Menu', 'we88-fiesta' ),
		'footer'  => __( 'Footer Menu', 'we88-fiesta' ),
	] );
}
add_action( 'after_setup_theme', 'we88_fiesta_setup' );

/**
 * Enqueue front-end styles. Fonts are bundled woff2 files loaded via
 * theme.json fontFace entries (file:./assets/fonts/…) — no external hosts.
 */
function we88_fiesta_enqueue(): void {
	wp_enqueue_style(
		'we88-fiesta-main',
		get_theme_file_uri( 'assets/css/style.css' ),
		[],
		WE88_FIESTA_VERSION
	);
}
add_action( 'wp_enqueue_scripts', 'we88_fiesta_enqueue' );

/**
 * Register block patterns category for WE88 Portal.
 */
function we88_fiesta_register_pattern_category(): void {
	if ( function_exists( 'register_block_pattern_category' ) ) {
		register_block_pattern_category(
			'we88-portal',
			[
				'label'       => __( 'WE88 Portal', 'we88-fiesta' ),
				'description' => __( 'Patterns built around the WE88 Portal plugin blocks.', 'we88-fiesta' ),
			]
		);
	}
}
add_action( 'init', 'we88_fiesta_register_pattern_category' );
