<?php
/**
 * Warranty Product Data Panel Template
 *
 * @package WarrantyCart
 * @version 1.0.0
 */

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound,WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Template variables and WooCommerce hooks are local scope and don't need prefixing

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

$warranty_status        = $args['warranty_status'] ?? 'disabled';
$product_type           = $args['product_type'] ?? 'additional_service';
$warranty_duration      = $args['warranty_duration'] ?? '';
$warranty_duration_unit = $args['warranty_duration_unit'] ?? 'years';
$coverage_details       = $args['coverage_details'] ?? '';
$associated_warranty    = $args['associated_warranty'] ?? '';
$service_priority       = $args['service_priority'] ?? 'optional';
$main_warranties        = $args['main_warranties'] ?? array();
?>

<div id="warranty_product_data" class="panel woocommerce_options_panel">

	<div class="options_group">
		<?php
		woocommerce_wp_checkbox(
			array(
				'id'          => 'warranty_cart_product_status',
				'label'       => __( 'Enable warranty features', 'warranty-cart' ),
				'description' => __( 'Check this box to enable warranty functionality for this product.', 'warranty-cart' ),
				'cbvalue'     => 'yes',
				'value'       => 'enabled' === $warranty_status ? 'yes' : '',
			)
		);
		?>
	</div>

	<div class="warranty-fields" style="<?php echo 'enabled' === $warranty_status ? '' : 'display: none;'; ?>">
		<div class="options_group">
			<?php
			woocommerce_wp_select(
				array(
					'id'          => 'warranty_cart_product_type',
					'value'       => $product_type,
					'label'       => __( 'Warranty product type', 'warranty-cart' ),
					'options'     => array(
						'main_warranty'      => __( 'Main warranty', 'warranty-cart' ),
						'additional_service' => __( 'Additional service', 'warranty-cart' ),
					),
					'desc_tip'    => 'true',
					'description' => __( 'Choose "Main warranty" for primary warranty offerings that customers can purchase directly. Choose "Additional service" for complementary services that extend or enhance main warranties.', 'warranty-cart' ),
				)
			);

			woocommerce_wp_text_input(
				array(
					'id'                => 'warranty_cart_duration',
					'value'             => $warranty_duration,
					'label'             => __( 'Warranty duration', 'warranty-cart' ),
					'data_type'         => 'number',
					'custom_attributes' => array(
						'step' => '1',
						'min'  => '1',
					),
					'desc_tip'          => 'true',
					'description'       => __( 'Enter the duration value for this warranty coverage period.', 'warranty-cart' ),
				)
			);

			woocommerce_wp_select(
				array(
					'id'          => 'warranty_cart_duration_unit',
					'value'       => $warranty_duration_unit,
					'label'       => __( 'Duration unit', 'warranty-cart' ),
					'options'     => array(
						'days'   => __( 'Days', 'warranty-cart' ),
						'months' => __( 'Months', 'warranty-cart' ),
						'years'  => __( 'Years', 'warranty-cart' ),
					),
					'desc_tip'    => 'true',
					'description' => __( 'Select the time unit for the warranty duration. This determines when the warranty expires.', 'warranty-cart' ),
				)
			);
			?>
		</div>

		<div class="options_group show_if_additional_service<?php echo 'additional_service' === $product_type ? '' : ' hidden'; ?>">
			<?php
			woocommerce_wp_select(
				array(
					'id'          => 'warranty_cart_associated_warranty',
					'value'       => $associated_warranty,
					'label'       => __( 'Link to main warranty', 'warranty-cart' ),
					'options'     => $main_warranties,
					'class'       => 'wc-enhanced-select',
					'desc_tip'    => 'true',
					'description' => __( 'Connect this additional service to a main warranty. Customers who purchase the selected main warranty will see this service as an optional add-on during checkout.', 'warranty-cart' ),
				)
			);

			woocommerce_wp_select(
				array(
					'id'          => 'warranty_cart_service_priority',
					'value'       => $service_priority,
					'label'       => __( 'Service presentation', 'warranty-cart' ),
					'options'     => array(
						'optional'    => __( 'Optional add-on', 'warranty-cart' ),
						'recommended' => __( 'Recommended add-on', 'warranty-cart' ),
						'required'    => __( 'Required service', 'warranty-cart' ),
					),
					'desc_tip'    => 'true',
					'description' => __( 'Control how prominently this service is displayed to customers. "Required" services are automatically added to cart, "Recommended" services are highlighted, and "Optional" services are shown as standard add-ons.', 'warranty-cart' ),
				)
			);
			?>
		</div>

		<div class="options_group">
			<?php
			woocommerce_wp_textarea_input(
				array(
					'id'          => 'warranty_cart_coverage_details',
					'value'       => $coverage_details,
					'label'       => __( 'Coverage description', 'warranty-cart' ),
					'desc_tip'    => 'true',
					'description' => __( 'Provide detailed information about what this warranty or service covers. This description helps customers understand the value and scope of coverage. It will be displayed on the warranty selection page and included in warranty certificates.', 'warranty-cart' ),
				)
			);
			?>
		</div>

		<?php \do_action( 'warranty_cart_product_options_warranty' ); ?>
	</div>
</div>
<?php // phpcs:enable ?>
