<?php
/**
 * Custom Attributes Widget - Content Controls
 *
 * @package GGM_Commerce
 */

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

// $this is the GGM_Commerce_Widget_Custom_Attributes instance.

$this->start_controls_section(
	'section_content',
	array(
		'label' => 'Content',
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$this->add_control(
	'title',
	array(
		'label'       => 'Title',
		'type'        => \Elementor\Controls_Manager::TEXT,
		'default'     => 'Specifications',
		'placeholder' => 'Specifications',
	)
);

$this->add_control(
	'layout',
	array(
		'label'   => 'Layout',
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'table',
		'options' => array(
			'table'  => 'Table',
			'list'   => 'List',
			'grid'   => 'Grid',
			'inline' => 'Inline',
		),
	)
);

$this->add_control(
	'columns',
	array(
		'label'     => 'Columns',
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => '2',
		'options'   => array(
			'1' => '1',
			'2' => '2',
			'3' => '3',
			'4' => '4',
		),
		'condition' => array(
			'layout' => 'grid',
		),
	)
);

// Build attribute options for the selector
$attr_options = array();
if ( class_exists( 'GGM_Commerce_Attributes' ) ) {
	$all_attrs = GGM_Commerce_Attributes::get_instance()->get_all_attributes();
	foreach ( $all_attrs as $attr ) {
		$label = $attr->name;
		if ( ! empty( $attr->group_name ) ) {
			$label .= ' (' . $attr->group_name . ')';
		}
		$attr_options[ $attr->id ] = $label;
	}
}

$this->add_control(
	'selected_attributes',
	array(
		'label'       => __( 'Attributes to Display', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SELECT2,
		'multiple'    => true,
		'options'     => $attr_options,
		'default'     => array(),
		'description' => __( 'Select which attributes to show. Leave empty to show all.', 'ggm-commerce' ),
		'label_block' => true,
	)
);

$this->add_control(
	'show_units',
	array(
		'label'        => 'Show Units',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'label_on'     => 'Show',
		'label_off'    => 'Hide',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'show_empty',
	array(
		'label'        => 'Show Empty Attributes',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'label_on'     => 'Show',
		'label_off'    => 'Hide',
		'return_value' => 'yes',
		'description'  => 'Show attributes even if they have no value set',
	)
);

$this->add_control(
	'show_icons',
	array(
		'label'        => 'Show Icons',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'label_on'     => 'Show',
		'label_off'    => 'Hide',
		'return_value' => 'yes',
		'description'  => 'Display attribute icons if available',
	)
);

$this->add_control(
	'group_by_group',
	array(
		'label'        => 'Group by Attribute Group',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'label_on'     => 'Yes',
		'label_off'    => 'No',
		'return_value' => 'yes',
		'description'  => 'Organize attributes by their groups',
	)
);

$this->add_control(
	'hide_if_empty',
	array(
		'label'        => 'Hide if No Attributes',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'label_on'     => 'Yes',
		'label_off'    => 'No',
		'return_value' => 'yes',
	)
);

$this->end_controls_section();
