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

// === STYLE TAB - Container ===
$this->start_controls_section(
    'stock_container_section',
    [
        'label' => __('Container', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_control(
    'alignment',
    [
        'label' => __('Alignment', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::CHOOSE,
        'options' => [
            'left' => ['title' => __('Left', 'ggm-commerce'), 'icon' => 'eicon-text-align-left'],
            'center' => ['title' => __('Center', 'ggm-commerce'), 'icon' => 'eicon-text-align-center'],
            'right' => ['title' => __('Right', 'ggm-commerce'), 'icon' => 'eicon-text-align-right'],
        ],
        'default' => 'left',
        'selectors' => [
            '{{WRAPPER}}' => 'text-align: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'display_inline',
    [
        'label' => __('Display Inline', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SWITCHER,
        'label_on' => __('Yes', 'ggm-commerce'),
        'label_off' => __('No', 'ggm-commerce'),
        'return_value' => 'yes',
        'default' => '',
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock' => 'display: inline-flex;',
        ],
    ]
);

$this->add_responsive_control(
    'stock_padding',
    [
        'label' => __('Padding', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'default' => [
            'top' => '8',
            'right' => '12',
            'bottom' => '8',
            'left' => '12',
            'unit' => 'px',
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->add_responsive_control(
    'stock_margin',
    [
        'label' => __('Margin', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', 'em'],
        'default' => [
            'top' => '0',
            'right' => '0',
            'bottom' => '12',
            'left' => '0',
            'unit' => 'px',
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->add_control(
    'stock_border_radius',
    [
        'label' => __('Border Radius', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::DIMENSIONS,
        'size_units' => ['px', '%'],
        'default' => [
            'top' => '4',
            'right' => '4',
            'bottom' => '4',
            'left' => '4',
            'unit' => 'px',
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();

// === STYLE TAB - In Stock ===
$this->start_controls_section(
    'in_stock_style_section',
    [
        'label' => __('In Stock Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_control(
    'stock_color',
    [
        'label' => __('Text Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.in-stock' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'stock_background_color',
    [
        'label' => __('Background Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.in-stock' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Border::get_type(),
    [
        'name' => 'stock_border',
        'label' => __('Border', 'ggm-commerce'),
        'selector' => '{{WRAPPER}} .ggmc-product-stock.in-stock',
        'fields_options' => [
            'border' => [
                'default' => 'solid',
            ],
            'width' => [
                'default' => [
                    'top' => '1',
                    'right' => '1',
                    'bottom' => '1',
                    'left' => '1',
                    'isLinked' => true,
                ],
            ],
            'color' => [
            ],
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Typography::get_type(),
    [
        'name' => 'stock_typography',
        'selector' => '{{WRAPPER}} .ggmc-product-stock',
    ]
);

$this->end_controls_section();

// === STYLE TAB - Low Stock ===
$this->start_controls_section(
    'low_stock_style_section',
    [
        'label' => __('Low Stock Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_control(
    'low_stock_color',
    [
        'label' => __('Text Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.low-stock' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'low_stock_background_color',
    [
        'label' => __('Background Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.low-stock' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'low_stock_border_color',
    [
        'label' => __('Border Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.low-stock' => 'border-color: {{VALUE}};',
        ],
    ]
);

$this->end_controls_section();

// === STYLE TAB - Out of Stock ===
$this->start_controls_section(
    'out_of_stock_style_section',
    [
        'label' => __('Out of Stock Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
    ]
);

$this->add_control(
    'out_of_stock_color',
    [
        'label' => __('Text Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.out-of-stock' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'out_of_stock_background_color',
    [
        'label' => __('Background Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.out-of-stock' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'out_of_stock_border_color',
    [
        'label' => __('Border Color', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.out-of-stock' => 'border-color: {{VALUE}};',
        ],
    ]
);

$this->end_controls_section();

// === STYLE TAB - Restock Expected ===
$this->start_controls_section(
    'restock_style_section',
    [
        'label' => __('Restock Expected Style', 'goose-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_restock_date' => 'yes',
        ],
    ]
);

$this->add_control(
    'restock_color',
    [
        'label' => __('Text Color', 'goose-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.restock-expected' => 'color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'restock_background_color',
    [
        'label' => __('Background Color', 'goose-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.restock-expected' => 'background-color: {{VALUE}};',
        ],
    ]
);

$this->add_control(
    'restock_border_color',
    [
        'label' => __('Border Color', 'goose-commerce'),
        'type' => \Elementor\Controls_Manager::COLOR,
        'selectors' => [
            '{{WRAPPER}} .ggmc-product-stock.restock-expected' => 'border-color: {{VALUE}};',
        ],
    ]
);

$this->add_group_control(
    \Elementor\Group_Control_Typography::get_type(),
    [
        'name' => 'restock_typography',
        'selector' => '{{WRAPPER}} .ggmc-product-stock.restock-expected',
    ]
);

$this->end_controls_section();

// === STYLE TAB - Icon ===
$this->start_controls_section(
    'icon_style_section',
    [
        'label' => __('Icon Style', 'ggm-commerce'),
        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        'condition' => [
            'show_icon' => 'yes',
        ],
    ]
);

$this->add_responsive_control(
    'icon_size',
    [
        'label' => __('Icon Size', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
            'px' => [
                'min' => 10,
                'max' => 40,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 16,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-stock-icon' => 'font-size: {{SIZE}}{{UNIT}}; width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->add_responsive_control(
    'icon_spacing',
    [
        'label' => __('Icon Spacing', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SLIDER,
        'size_units' => ['px'],
        'range' => [
            'px' => [
                'min' => 0,
                'max' => 20,
            ],
        ],
        'default' => [
            'unit' => 'px',
            'size' => 6,
        ],
        'selectors' => [
            '{{WRAPPER}} .ggmc-stock-icon' => 'margin-right: {{SIZE}}{{UNIT}};',
        ],
    ]
);

$this->end_controls_section();
