<?php
// If this file is called directly, abort.
if (! defined('ABSPATH')) {
    exit;
}

// === CONTENT TAB ===
$this->start_controls_section(
    'content_section',
    [
        'label' => __('Cart Settings', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    ]
);

$this->add_control(
    'product_source',
    [
        'label' => __('Product Source', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'current',
        'options' => [
            'current' => __('Current Product (Auto-detect)', 'ggm-commerce'),
            'custom' => __('Select Product', 'ggm-commerce'),
        ],
    ]
);

$this->add_control(
    'product_id',
    [
        'label' => __('Product', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::NUMBER,
        'default' => '',
        'condition' => [
            'product_source' => 'custom',
        ],
        'description' => __('Start typing product name to search', 'ggm-commerce'),
    ]
);

$this->add_control(
    'button_text',
    [
        'label' => __('Button Text', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => __('Add to Cart', 'ggm-commerce'),
        'placeholder' => __('Enter button text', 'ggm-commerce'),
    ]
);

$this->add_control(
    'layout',
    [
        'label' => __('Layout', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'horizontal',
        'options' => [
            'horizontal' => __('Horizontal', 'ggm-commerce'),
            'vertical' => __('Vertical', 'ggm-commerce'),
        ],
    ]
);

// Variable Product Settings
$this->add_control(
    'variable_product_heading',
    [
        'label' => __('Variable Products', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::HEADING,
        'separator' => 'before',
    ]
);

$this->add_control(
    'variable_button_text',
    [
        'label' => __('Variable Product Button Text', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => 'Select Options',
        'placeholder' => __('Text when variation selection needed', 'ggm-commerce'),
        'description' => __('Button text when product has variations but none selected', 'ggm-commerce'),
    ]
);

$this->add_control(
    'variable_product_behavior',
    [
        'label' => __('Variable Product Behavior', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'link_to_product',
        'options' => [
            'link_to_product' => __('Link to Product Page', 'ggm-commerce'),
            'disabled' => __('Disabled (wait for selection)', 'ggm-commerce'),
            'show_selector' => __('Show Variation Selector', 'ggm-commerce'),
        ],
        'description' => __('What happens when button clicked without variation selected', 'ggm-commerce'),
    ]
);

$this->add_control(
    'show_quantity',
    [
        'label' => __('Show Quantity Selector', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SWITCHER,
        'label_on' => __('Show', 'ggm-commerce'),
        'label_off' => __('Hide', 'ggm-commerce'),
        'return_value' => 'yes',
        'default' => 'yes',
    ]
);

$this->add_control(
    'quantity_label',
    [
        'label' => __('Quantity Label', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => __('Quantity:', 'ggm-commerce'),
        'condition' => [
            'show_quantity' => 'yes',
        ],
    ]
);

$this->add_control(
    'quantity_controls_style',
    [
        'label' => __('Quantity Controls Style', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'both',
        'options' => [
            'both' => __('Input Controls & Buttons', 'ggm-commerce'),
            'input_only' => __('Input Controls Only', 'ggm-commerce'),
        ],
        'condition' => [
            'show_quantity' => 'yes',
        ],
    ]
);

// Price Display Settings
$this->add_control(
    'price_display_heading',
    [
        'label' => __('Price Display', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::HEADING,
        'separator' => 'before',
    ]
);

$this->add_control(
    'show_price',
    [
        'label' => __('Show Price', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SWITCHER,
        'label_on' => __('Show', 'ggm-commerce'),
        'label_off' => __('Hide', 'ggm-commerce'),
        'return_value' => 'yes',
        'default' => 'no',
        'description' => __('Display the product price. Updates dynamically when a variation is selected.', 'ggm-commerce'),
    ]
);

$this->add_control(
    'price_prefix_text',
    [
        'label' => __('Variable Price Prefix', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => 'From',
        'description' => __('Text shown before the price for variable products when no variation is selected.', 'ggm-commerce'),
        'condition' => [
            'show_price' => 'yes',
        ],
    ]
);

$this->end_controls_section();
