<?php
/**
 * Product Price Widget
 *
 * Displays the price of a product, with support for sale prices,
 * tax suffixes, and variable product price ranges.
 *
 * @package GGM_Commerce
 */

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

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

class GGM_Commerce_Widget_Product_Price extends \GGM_Commerce_Base_Widget
{

	public function get_name()
	{
		return 'ggmc-product-price';
	}

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

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

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

	/**
	 * The output function for the widget.
	 */
	protected function render()
	{
		ggmc_product_price_render( $this );
	}

	/**
	 * Get default styles for this widget.
	 */
	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 = [
			// Alignment
			'alignment' => 'left',

			// Typography (handled by fields_options in control definition)
			'price_typography' => 'custom',

			// Colors
			'price_color' => '#0f172a',
			'sale_price_color' => '#059669',
			'original_price_color' => '#94a3b8',

			// Variable Price
			'variable_price_format' => 'from',
			'from_label_text' => 'From',
			'range_separator' => ' - ',
			'from_label_color' => '#64748b',
			'range_separator_color' => '#94a3b8',

			// Spacing
			'margin' => [
				'top' => '0',
				'right' => '0',
				'bottom' => '16',
				'left' => '0',
				'unit' => 'px',
				'isLinked' => false
			],
			'padding' => [
				'top' => '0',
				'right' => '0',
				'bottom' => '0',
				'left' => '0',
				'unit' => 'px',
				'isLinked' => false
			],
		];

		return apply_filters('ggm_commerce_widget_default_styles', $defaults, 'ggmc-product-price');
	}
}
