<?php
defined('ABSPATH') || exit;

define('MOMENTRY_THEME_VERSION', '1.0.0');
define('MOMENTRY_THEME_DIR', get_template_directory());
define('MOMENTRY_THEME_URI', get_template_directory_uri());

require_once MOMENTRY_THEME_DIR . '/inc/api/class-identity-api.php';
require_once MOMENTRY_THEME_DIR . '/inc/api/class-database.php';

add_action('after_setup_theme', 'momentry_theme_setup');
function momentry_theme_setup(): void {
    add_theme_support('title-tag');
    add_theme_support('post-thumbnails');
    add_theme_support('html5', ['search-form', 'comment-form', 'comment-list', 'gallery', 'caption']);
    
    load_theme_textdomain('momentry', MOMENTRY_THEME_DIR . '/languages');
}

add_action('wp_enqueue_scripts', 'momentry_enqueue_scripts');
function momentry_enqueue_scripts(): void {
    wp_enqueue_style(
        'momentry-style',
        MOMENTRY_THEME_URI . '/style.css',
        [],
        MOMENTRY_THEME_VERSION
    );
    
    wp_enqueue_script(
        'momentry-script',
        MOMENTRY_THEME_URI . '/assets/js/main.js',
        ['jquery'],
        MOMENTRY_THEME_VERSION,
        true
    );
    
    wp_localize_script('momentry-script', 'momentryApi', [
        'root' => esc_url_raw(rest_url()),
        'nonce' => wp_create_nonce('wp_rest'),
    ]);
}

add_action('rest_api_init', 'momentry_register_api_routes');
function momentry_register_api_routes(): void {
    $identity_api = new Momentry\Identity_API();
    $identity_api->register_routes();
}