<?php
/**
 * Checkout Widget - Complete checkout form with order creation.
 *
 * @package GGM_Commerce
 */

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

// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
// phpcs:disable PluginCheck.Security.DirectDB.UnescapedDBParameter

require_once __DIR__ . '/widget-checkout/elementor-render.php';

/**
 * Class GGM_Commerce_Widget_Checkout
 *
 * Elementor widget for the complete checkout form with order creation.
 */
class GGM_Commerce_Widget_Checkout extends \GGM_Commerce_Base_Widget {

	/**
	 * Get widget name.
	 *
	 * @return string
	 */
	public function get_name() {
		return 'ggmc-checkout';
	}

	/**
	 * Get widget title.
	 *
	 * @return string
	 */
	public function get_title() {
		return __( 'Checkout', 'ggm-commerce' );
	}

	/**
	 * Get widget icon.
	 *
	 * @return string
	 */
	public function get_icon() {
		return 'eicon-form-horizontal';
	}

	/**
	 * Get widget categories.
	 *
	 * @return array
	 */
	public function get_categories() {
		return [ 'ggmc-widgets' ];
	}

	/**
	 * Get widget keywords.
	 *
	 * @return array
	 */
	public function get_keywords() {
		return [ 'checkout', 'form', 'order', 'billing', 'shipping' ];
	}

	/**
	 * Get script dependencies.
	 *
	 * @return array
	 */
	public function get_script_depends() {
		$scripts = [ 'ggmc-checkout' ];

		// Add payment gateway scripts if available.
		if ( function_exists( 'ggm_commerce_gateways' ) ) {
			$gateway_manager = ggm_commerce_gateways();
			foreach ( $gateway_manager->get_available_gateways() as $gateway ) {
				$gateway_scripts = $gateway->get_scripts();
				if ( ! empty( $gateway_scripts ) ) {
					foreach ( $gateway_scripts as $script ) {
						if ( isset( $script['handle'] ) ) {
							$scripts[] = $script['handle'];
						}
					}
				}
			}
		}

		return $scripts;
	}

	/**
	 * Register widget controls.
	 */
	protected function register_controls() {
		require __DIR__ . '/widget-checkout/elementor-controls.php';
		require __DIR__ . '/widget-checkout/elementor-controls-style.php';
	}

	/**
	 * Render the widget output.
	 */
	protected function render() {
		ggmc_checkout_render( $this );
	}

	/**
	 * Get default styles for this widget.
	 * Uses centralized configuration from default-widget-styles.php.
	 *
	 * @return array
	 */
	public static function get_static_default_styles() {
		return self::get_defaults_from_config();
	}
}
