<?php
/**
 * Online menu (dish menu) display themes for website and QR.
 *
 * @package Maca_Menu_List_Pro
 */

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

/**
 * Available online menu themes.
 *
 * @return array<string, string>
 */
function maca_menulist_get_dish_menu_themes() {
    return apply_filters(
        'maca_menulist_dish_menu_themes',
        array(
            'light'   => __('Light', 'maca-restu-pro'),
            'dark'    => __('Dark', 'maca-restu-pro'),
            'classic' => __('Classic', 'maca-restu-pro'),
            'modern'  => __('Modern', 'maca-restu-pro'),
            'minimal' => __('Minimal', 'maca-restu-pro'),
            'premium' => __('Premium', 'maca-restu-pro'),
        )
    );
}

/**
 * Active online menu theme key.
 *
 * @param string $override Optional override (preview).
 * @return string
 */
function maca_menulist_get_dish_menu_theme($override = '') {
    $themes = maca_menulist_get_dish_menu_themes();
    $override = sanitize_key($override);

    if ($override !== '' && isset($themes[ $override ])) {
        return $override;
    }

    $theme = sanitize_key(get_option('maca_menulist_dish_menu_theme', 'light'));

    if (!isset($themes[ $theme ])) {
        $theme = 'light';
    }

    return $theme;
}

/**
 * CSS class for the themed menu shell wrapper.
 *
 * @param string $override Optional theme override.
 * @return string
 */
function maca_menulist_get_dish_menu_theme_shell_class($override = '', $layout_override = '') {
    $theme = maca_menulist_get_dish_menu_theme($override);
    $layout = maca_menulist_get_dish_menu_layout($layout_override);

    return 'maca-dish-menu-shell maca-dish-menu-shell--theme-' . $theme . ' maca-dish-menu-shell--layout-' . $layout;
}

/**
 * Available online menu dish layouts.
 *
 * @return array<string, string>
 */
function maca_menulist_get_dish_menu_layouts() {
    return apply_filters(
        'maca_menulist_dish_menu_layouts',
        array(
            'rows' => __('Rows (list)', 'maca-restu-pro'),
            'grid' => __('Grid (cards)', 'maca-restu-pro'),
        )
    );
}

/**
 * Active online menu dish layout key.
 *
 * @param string $override Optional override (preview).
 * @return string
 */
function maca_menulist_get_dish_menu_layout($override = '') {
    $layouts = maca_menulist_get_dish_menu_layouts();
    $override = sanitize_key($override);

    if ($override !== '' && isset($layouts[ $override ])) {
        return $override;
    }

    $layout = sanitize_key(get_option('maca_menulist_dish_menu_layout', 'rows'));

    if (!isset($layouts[ $layout ])) {
        $layout = 'rows';
    }

    return $layout;
}

/**
 * Body class for standalone QR / takeaway dish pages.
 *
 * @param string $override Optional theme override.
 * @return string
 */
function maca_menulist_get_dish_menu_theme_body_class($override = '') {
    $theme = maca_menulist_get_dish_menu_theme($override);

    return 'maca-dish-menu-theme-' . $theme;
}

/**
 * Stylesheet URL for dish menu themes.
 *
 * @return string
 */
function maca_menulist_get_dish_menu_themes_stylesheet_url() {
    return MACA_MENULIST_PLUGIN_URL . 'assets/css/dish-menu-themes.css?ver=' . MACA_MENULIST_VERSION;
}

/**
 * Sample dish menu markup for admin theme preview.
 *
 * @param string $theme Theme key.
 * @return void
 */
function maca_menulist_render_dish_menu_theme_preview($theme = '', $layout = '') {
    $shell_class = maca_menulist_get_dish_menu_theme_shell_class($theme, $layout);
    $currency = function_exists('maca_menulist_get_price_currency')
        ? maca_menulist_get_price_currency()
        : 'kr';

    ?>
    <div class="maca-dish-menu-theme-preview" id="maca-dish-menu-theme-preview">
        <div class="<?php echo esc_attr($shell_class); ?>" id="maca-dish-menu-theme-preview-shell">
            <div class="maca-dish-menu">
                <div class="maca-filter-bar maca-dish-filters" role="group" aria-label="<?php esc_attr_e('Categories', 'maca-restu-pro'); ?>">
                    <button type="button" class="maca-dish-filter active"><?php esc_html_e('All', 'maca-restu-pro'); ?></button>
                    <button type="button" class="maca-dish-filter"><?php esc_html_e('Main course', 'maca-restu-pro'); ?></button>
                    <button type="button" class="maca-dish-filter"><?php esc_html_e('Drinks', 'maca-restu-pro'); ?></button>
                </div>
                <section class="maca-dish-category">
                    <?php
                    if (function_exists('maca_menulist_render_dish_category_heading')) {
                        maca_menulist_render_dish_category_heading(__('Main course', 'maca-restu-pro'));
                    } else {
                        ?>
                        <h3 class="maca-dish-category-title"><?php esc_html_e('Main course', 'maca-restu-pro'); ?></h3>
                        <?php
                    }
                    ?>
                    <ul class="maca-dish-list">
                        <li class="maca-dish-item">
                            <div class="maca-dish-image" aria-hidden="true"></div>
                            <div class="maca-dish-details">
                                <div class="maca-dish-header">
                                    <h4 class="maca-dish-title"><?php esc_html_e('Beef tartare', 'maca-restu-pro'); ?></h4>
                                    <span class="maca-dish-price">189 <?php echo esc_html($currency); ?></span>
                                </div>
                                <p class="maca-dish-description"><?php esc_html_e('Classic tartare with capers, shallot, and egg yolk.', 'maca-restu-pro'); ?></p>
                            </div>
                        </li>
                        <li class="maca-dish-item">
                            <div class="maca-dish-details">
                                <div class="maca-dish-header">
                                    <h4 class="maca-dish-title"><?php esc_html_e('Grilled salmon', 'maca-restu-pro'); ?></h4>
                                    <span class="maca-dish-price">215 <?php echo esc_html($currency); ?></span>
                                </div>
                                <p class="maca-dish-description"><?php esc_html_e('Served with seasonal vegetables and lemon butter.', 'maca-restu-pro'); ?></p>
                            </div>
                        </li>
                        <li class="maca-dish-item">
                            <div class="maca-dish-image" aria-hidden="true"></div>
                            <div class="maca-dish-details">
                                <div class="maca-dish-header">
                                    <h4 class="maca-dish-title"><?php esc_html_e('Chocolate mousse', 'maca-restu-pro'); ?></h4>
                                    <span class="maca-dish-price">95 <?php echo esc_html($currency); ?></span>
                                </div>
                                <p class="maca-dish-description"><?php esc_html_e('Dark chocolate with vanilla cream.', 'maca-restu-pro'); ?></p>
                            </div>
                        </li>
                    </ul>
                </section>
            </div>
            <footer class="maca-menu-footer" aria-hidden="true">
                <div class="maca-menu-footer-inner">
                    <section class="maca-menu-footer-block">
                        <h4 class="maca-menu-footer-heading"><?php esc_html_e('Prices', 'maca-restu-pro'); ?></h4>
                        <p class="maca-menu-footer-text"><?php esc_html_e('All prices include VAT.', 'maca-restu-pro'); ?></p>
                    </section>
                </div>
            </footer>
        </div>
    </div>
    <?php
}
