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

// === CONTENT TAB ===
$this->start_controls_section(
    'content_section',
    [
        'label' => __('Content', '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(
    'layout',
    [
        'label' => __('Layout', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'table',
        'options' => [
            'table' => __('Table', 'ggm-commerce'),
            'list' => __('Vertical List', 'ggm-commerce'),
            'inline' => __('Inline', 'ggm-commerce'),
            'grid' => __('Grid (2 columns)', 'ggm-commerce'),
        ],
    ]
);

$this->add_control(
    'show_weight',
    [
        'label' => __('Show Weight', '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(
    'show_dimensions',
    [
        'label' => __('Show Dimensions', '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(
    'dimensions_format',
    [
        'label' => __('Dimensions Format', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'combined',
        'options' => [
            'combined' => __('Combined (L × W × H)', 'ggm-commerce'),
            'separate' => __('Separate rows/items', 'ggm-commerce'),
        ],
        'condition' => [
            'show_dimensions' => 'yes',
        ],
    ]
);

$this->add_control(
    'show_labels',
    [
        'label' => __('Show Labels', '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(
    'show_units',
    [
        'label' => __('Show Units', '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(
    'weight_label',
    [
        'label' => __('Weight Label', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => __('Weight', 'ggm-commerce'),
        'condition' => [
            'show_labels' => 'yes',
        ],
    ]
);

$this->add_control(
    'dimensions_label',
    [
        'label' => __('Dimensions Label', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => __('Dimensions', 'ggm-commerce'),
        'condition' => [
            'show_labels' => 'yes',
            'dimensions_format' => 'combined',
        ],
    ]
);

$this->add_control(
    'hide_empty',
    [
        'label' => __('Hide if Empty', 'ggm-commerce'),
        'type' => \Elementor\Controls_Manager::SWITCHER,
        'label_on' => __('Yes', 'ggm-commerce'),
        'label_off' => __('No', 'ggm-commerce'),
        'return_value' => 'yes',
        'default' => 'yes',
        'description' => __('Hide the widget if no weight/dimensions are set', 'ggm-commerce'),
    ]
);

// Custom Attributes control (premium feature)
if (class_exists('GGM_Commerce_License') && GGM_Commerce_License::is_premium_active()) {
    $this->add_control(
        'custom_attributes_heading',
        [
            'label' => __('Custom Attributes', 'ggm-commerce'),
            'type' => \Elementor\Controls_Manager::HEADING,
            'separator' => 'before',
        ]
    );

    $this->add_control(
        'show_custom_attributes',
        [
            'label' => __('Show Custom Attributes', 'ggm-commerce'),
            'type' => \Elementor\Controls_Manager::SWITCHER,
            'label_on' => __('Yes', 'ggm-commerce'),
            'label_off' => __('No', 'ggm-commerce'),
            'return_value' => 'yes',
            'default' => 'yes',
            'description' => __('Display custom attributes assigned to this product', 'ggm-commerce'),
        ]
    );

    $this->add_control(
        'custom_attributes_position',
        [
            'label' => __('Position', 'ggm-commerce'),
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'after',
            'options' => [
                'before' => __('Before Weight/Dimensions', 'ggm-commerce'),
                'after' => __('After Weight/Dimensions', 'ggm-commerce'),
            ],
            'condition' => [
                'show_custom_attributes' => 'yes',
            ],
        ]
    );
}

$this->end_controls_section();
