<?php
/**
 * Flavor – Restaurant Menu
 *
 * WPBakery element (Free version) — Card Grid layout, Elegant Dark theme.
 *
 * @package    FlavorMenu
 * @copyright  Copyright (c) 2024 Flavor Studio
 * @license    GPL-2.0-or-later
 * @link       https://flavor-menu.com
 */

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

class Flavor_WPBakery_Element {

    public static function init() {
        add_action( 'vc_before_init', array( __CLASS__, 'map_element' ) );
    }

    /**
     * Map the WPBakery element with all params.
     */
    public static function map_element() {

        $cats = get_terms( array(
            'taxonomy'   => 'flavor_menu_cat',
            'hide_empty' => false,
        ) );

        $cat_options = array(
            __( 'All Categories', 'flavor-restaurant-menu' ) => '',
        );
        if ( ! is_wp_error( $cats ) && ! empty( $cats ) ) {
            foreach ( $cats as $cat ) {
                $cat_options[ $cat->name ] = $cat->slug;
            }
        }

        vc_map( array(
            'name'        => __( 'Menu Card', 'flavor-restaurant-menu' ),
            'base'        => 'flavor_menu',
            'description' => __( 'Elegant restaurant menu card', 'flavor-restaurant-menu' ),
            'category'    => __( 'Restaurant', 'flavor-restaurant-menu' ),
            'icon'        => FLAVOR_MENU_URL . 'assets/images/icon-flavor.png',
            'params'      => array(

                // --- General ---
                array(
                    'type'        => 'textfield',
                    'heading'     => __( 'Heading', 'flavor-restaurant-menu' ),
                    'param_name'  => 'title',
                    'value'       => __( 'Our Menu', 'flavor-restaurant-menu' ),
                    'admin_label' => true,
                    'group'       => __( 'General', 'flavor-restaurant-menu' ),
                ),
                array(
                    'type'       => 'textarea',
                    'heading'    => __( 'Description', 'flavor-restaurant-menu' ),
                    'param_name' => 'description',
                    'value'      => '',
                    'group'      => __( 'General', 'flavor-restaurant-menu' ),
                ),
                array(
                    'type'       => 'dropdown',
                    'heading'    => __( 'Filter by Category', 'flavor-restaurant-menu' ),
                    'param_name' => 'category',
                    'value'      => $cat_options,
                    'group'      => __( 'General', 'flavor-restaurant-menu' ),
                ),
                array(
                    'type'        => 'textfield',
                    'heading'     => __( 'Max. Items', 'flavor-restaurant-menu' ),
                    'param_name'  => 'limit',
                    'value'       => '12',
                    'description' => __( 'Maximum number of menu items to display.', 'flavor-restaurant-menu' ),
                    'group'       => __( 'General', 'flavor-restaurant-menu' ),
                ),

                // --- Display ---
                array(
                    'type'       => 'checkbox',
                    'heading'    => __( 'Show Category Filter', 'flavor-restaurant-menu' ),
                    'param_name' => 'show_filter',
                    'value'      => array(
                        __( 'Yes', 'flavor-restaurant-menu' ) => 'yes',
                    ),
                    'std'        => 'yes',
                    'group'      => __( 'Display', 'flavor-restaurant-menu' ),
                ),
                array(
                    'type'        => 'checkbox',
                    'heading'     => __( 'Hide "All" Button', 'flavor-restaurant-menu' ),
                    'param_name'  => 'hide_all_btn',
                    'value'       => array(
                        __( 'Yes', 'flavor-restaurant-menu' ) => 'yes',
                    ),
                    'std'         => '',
                    'description' => __( 'Hides the "All" filter button. Only works when a default category is set.', 'flavor-restaurant-menu' ),
                    'dependency'  => array(
                        'element' => 'show_filter',
                        'value'   => array( 'yes' ),
                    ),
                    'group'       => __( 'Display', 'flavor-restaurant-menu' ),
                ),
                array(
                    'type'        => 'dropdown',
                    'heading'     => __( 'Default Category (Preselect)', 'flavor-restaurant-menu' ),
                    'param_name'  => 'default_category',
                    'value'       => $cat_options,
                    'std'         => '',
                    'description' => __( 'This category will be preselected on load instead of "All".', 'flavor-restaurant-menu' ),
                    'dependency'  => array(
                        'element' => 'show_filter',
                        'value'   => array( 'yes' ),
                    ),
                    'group'       => __( 'Display', 'flavor-restaurant-menu' ),
                ),

                // --- Advanced ---
                array(
                    'type'       => 'textfield',
                    'heading'    => __( 'Currency Symbol', 'flavor-restaurant-menu' ),
                    'param_name' => 'currency',
                    'value'      => '€',
                    'group'      => __( 'Advanced', 'flavor-restaurant-menu' ),
                ),
                array(
                    'type'       => 'textfield',
                    'heading'    => __( 'Additional CSS Class', 'flavor-restaurant-menu' ),
                    'param_name' => 'el_class',
                    'value'      => '',
                    'group'      => __( 'Advanced', 'flavor-restaurant-menu' ),
                ),
            ),
        ) );
    }
}
