<?php
/**
 * Product Image Widget
 *
 * Displays the main image for a product. Supports current-product auto-detection
 * and explicit product selection via Elementor controls.
 *
 * @package GGM_Commerce
 */

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

require_once __DIR__ . '/widget-product-image/elementor-render.php';

class GGM_Commerce_Widget_Product_Image extends \GGM_Commerce_Base_Widget
{
	public function get_name()
	{
		return 'ggmc-product-image';
	}

	public function get_title()
	{
		return 'Product Image';
	}

	public function get_icon()
	{
		return 'eicon-image';
	}

	protected function register_controls()
	{
		require __DIR__ . '/widget-product-image/elementor-controls.php';
		require __DIR__ . '/widget-product-image/elementor-controls-style.php';
	}

	protected function render()
	{
		ggmc_product_image_render( $this );
	}

	/**
	 * Get default styles for this widget.
	 *
	 * @return array
	 */
	public static function get_static_default_styles() {
		// Check if defaults have been cleared globally
		if (get_option('ggm_commerce_defaults_cleared', false)) {
			return []; // Return empty array so widget starts with no styling
		}

		$defaults = [
			// === IMAGE CONTAINER ===
			'image_background_color' => '#FFFFFF',
			'image_padding' => [
				'top' => '12',
				'right' => '12',
				'bottom' => '12',
				'left' => '12',
				'unit' => 'px',
				'isLinked' => true
			],
			'image_border_border' => 'solid',
			'image_border_width' => [
				'top' => '1',
				'right' => '1',
				'bottom' => '1',
				'left' => '1',
				'unit' => 'px',
				'isLinked' => true
			],
			'image_border_color' => '#E5E7EB',
			'image_border_radius' => [
				'top' => '8',
				'right' => '8',
				'bottom' => '8',
				'left' => '8',
				'unit' => 'px',
				'isLinked' => true
			],

			// === IMAGE DIMENSIONS ===
			'image_width' => [
				'size' => '100',
				'unit' => '%'
			],
			'image_height' => [
				'size' => '300',
				'unit' => 'px'
			],
			'image_object_fit' => 'cover',
			'image_object_position' => 'center center',

			// === HOVER EFFECTS ===
			'image_hover_border_color' => '#2563eb',
			'image_css_filters_hover_saturate' => [
				'size' => '1.05',
				'unit' => 'px'
			],
			'image_hover_transition' => [
				'size' => '0.3',
				'unit' => 's'
			],

			// === BOX SHADOW ===
			'image_box_shadow_box_shadow_type' => 'yes',
			'image_box_shadow_box_shadow' => [
				'horizontal' => '0',
				'vertical' => '2',
				'blur' => '6',
				'spread' => '0',
				'color' => 'rgba(0, 0, 0, 0.06)'
			],
			'image_hover_box_shadow_box_shadow' => [
				'horizontal' => '0',
				'vertical' => '4',
				'blur' => '12',
				'spread' => '0',
				'color' => 'rgba(44, 95, 65, 0.12)'
			],

			// === SPACING ===
			'image_margin' => [
				'top' => '0',
				'right' => '0',
				'bottom' => '16',
				'left' => '0',
				'unit' => 'px',
				'isLinked' => false
			],

			// === RESPONSIVE ===
			'image_height_tablet' => [
				'size' => '250',
				'unit' => 'px'
			],
			'image_height_mobile' => [
				'size' => '200',
				'unit' => 'px'
			],
			'image_padding_tablet' => [
				'top' => '10',
				'right' => '10',
				'bottom' => '10',
				'left' => '10',
				'unit' => 'px',
				'isLinked' => true
			],
			'image_padding_mobile' => [
				'top' => '8',
				'right' => '8',
				'bottom' => '8',
				'left' => '8',
				'unit' => 'px',
				'isLinked' => true
			]
		];

		// Apply filter to allow clearing defaults globally
		return apply_filters('ggm_commerce_widget_default_styles', $defaults, 'ggmc-product-image');
	}
}
