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

// === CONTENT TAB ===
$this->start_controls_section(
    'content_section',
    [
        'label' => 'Content',
        '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(
    'display_format',
    [
        'label' => __('Display Format', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'text_number',
        'options' => [
            'number_only' => __('Number Only (25)', 'ggm-commerce'),
            'text_number' => __('Text + Number (In Stock: 25)', 'ggm-commerce'),
            'status_only' => __('Status Only (In Stock)', 'ggm-commerce'),
        ],
    ]
);

$this->add_control(
    'in_stock_text',
    [
        'label' => __('In Stock Text', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => 'In Stock:',
        'placeholder' => 'e.g., Available:',
        'condition' => [
            'display_format!' => 'number_only',
        ],
    ]
);

$this->add_control(
    'low_stock_text',
    [
        'label' => __('Low Stock Text', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => 'Low Stock:',
        'placeholder' => 'e.g., Only a few left:',
        'condition' => [
            'display_format!' => 'number_only',
        ],
    ]
);

$this->add_control(
    'out_of_stock_text',
    [
        'label' => __('Out of Stock Text', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => 'Out of Stock',
        'placeholder' => 'e.g., Sold Out',
    ]
);

$this->add_control(
    'low_stock_threshold',
    [
        'label' => __('Low Stock Threshold', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::NUMBER,
        'default' => 10,
        'min' => 1,
        'description' => __('Stock quantity below this number will be shown as "Low Stock"', 'ggm-commerce'),
    ]
);

$this->add_control(
    'show_icon',
    [
        'label' => __('Show Status Icon', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SWITCHER,
        'label_on' => __('Yes', 'ggm-commerce'),
        'label_off' => __('No', 'ggm-commerce'),
        'return_value' => 'yes',
        'default' => 'yes',
    ]
);

$this->add_control(
    'in_stock_icon',
    [
        'label' => __('In Stock Icon', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::ICONS,
        'default' => [
            'value' => 'fas fa-check-circle',
            'library' => 'fa-solid',
        ],
        'condition' => [
            'show_icon' => 'yes',
        ],
    ]
);

$this->add_control(
    'low_stock_icon',
    [
        'label' => __('Low Stock Icon', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::ICONS,
        'default' => [
            'value' => 'fas fa-exclamation-triangle',
            'library' => 'fa-solid',
        ],
        'condition' => [
            'show_icon' => 'yes',
        ],
    ]
);

$this->add_control(
    'out_of_stock_icon',
    [
        'label' => __('Out of Stock Icon', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::ICONS,
        'default' => [
            'value' => 'fas fa-times-circle',
            'library' => 'fa-solid',
        ],
        'condition' => [
            'show_icon' => 'yes',
        ],
    ]
);

// === RESTOCK DATE CONTROLS ===
$this->add_control(
    'restock_heading',
    [
        'label' => __('Restock Date', 'goose-commerce'),
        'type' => \Elementor\Controls_Manager::HEADING,
        'separator' => 'before',
    ]
);

$this->add_control(
    'show_restock_date',
    [
        'label' => __('Show Restock Date', 'goose-commerce'),
        'type' => \Elementor\Controls_Manager::SWITCHER,
        'label_on' => __('Yes', 'goose-commerce'),
        'label_off' => __('No', 'goose-commerce'),
        'return_value' => 'yes',
        'default' => 'yes',
        'description' => __('When enabled, replaces "Out of Stock" with the expected restock message if a date is set.', 'goose-commerce'),
    ]
);

$this->add_control(
    'restock_display_format',
    [
        'label' => __('Restock Display Format', 'goose-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'descriptive',
        'options' => [
            'exact_date' => __('Exact Date (Expected 04/Aug)', 'goose-commerce'),
            'weeks' => __('Weeks (Expected in 2 to 3 weeks)', 'goose-commerce'),
            'descriptive' => __('Descriptive (Expected Soon / Imminent)', 'goose-commerce'),
        ],
        'condition' => [
            'show_restock_date' => 'yes',
        ],
    ]
);

$this->add_control(
    'restock_icon',
    [
        'label' => __('Restock Icon', 'goose-commerce'),
        'type' => \Elementor\Controls_Manager::ICONS,
        'default' => [
            'value' => 'fas fa-clock',
            'library' => 'fa-solid',
        ],
        'condition' => [
            'show_restock_date' => 'yes',
            'show_icon' => 'yes',
        ],
    ]
);

$this->end_controls_section();
