<?php
/**
 * @var array<string, mixed> $template
 * @var string              $weight_unit
 * @var string              $dimension_unit
 * @var array<string, string> $type_options
 */

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


$weight       = $template['weight'] ?? '';
$package_type = $template['type'] ?? '';
$length       = $template['dimensions']['length'] ?? '';
$width        = $template['dimensions']['width'] ?? '';
$height       = $template['dimensions']['height'] ?? '';
$cod          = (bool) ( $template['services']['cod'] ?? false );
$insurance    = (bool) ( $template['services']['insurance'] ?? false );

?>
<table class="form-table">
	<tbody>
		<tr>
			<th scope="row">
				<label for="dhl-polska-template-type">
					<?php esc_html_e( 'Typ przesyłki', 'dhl-polska' ); ?>
				</label>
			</th>
			<td>
				<select
					id="dhl-polska-template-type"
					name="<?php echo esc_attr( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::FIELD_TYPE ); ?>"
				>
					<?php foreach ( $type_options as $value => $label ) : ?>
						<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $package_type, $value ); ?>>
							<?php echo esc_html( $label ); ?>
						</option>
					<?php endforeach; ?>
				</select>
			</td>
		</tr>
		<tr>
			<th scope="row">
				<label for="dhl-polska-template-weight">
					<?php esc_html_e( 'Domyślna waga', 'dhl-polska' ); ?>
				</label>
				<span
					class="woocommerce-help-tip"
					data-tip="<?php echo esc_attr__( 'Domyślna waga zostanie użyta, gdy produkty w zamówieniu nie będą miały zdefiniowanej wagi i waga zamówienia będzie niemożliwa do obliczenia.', 'dhl-polska' ); ?>"
				></span>
			</th>
			<td>
				<input
					type="number"
					class="regular-text"
					id="dhl-polska-template-weight"
					name="<?php echo esc_attr( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::FIELD_WEIGHT ); ?>"
					value="<?php echo esc_attr( $weight ); ?>"
					min="0.01"
					step="0.01"
					required
				/>
				<span class="description"><?php echo esc_html( $weight_unit ); ?></span>
			</td>
		</tr>
		<tr>
			<th scope="row">
				<?php esc_html_e( 'Wymiary przesyłki', 'dhl-polska' ); ?>
			</th>
			<td>
				<label for="dhl-polska-template-length">
					<?php esc_html_e( 'Długość', 'dhl-polska' ); ?>
				</label>
				<input
					type="number"
					class="small-text"
					id="dhl-polska-template-length"
					name="<?php echo esc_attr( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::FIELD_LENGTH ); ?>"
					value="<?php echo esc_attr( $length ); ?>"
					min="1"
					step="1"
					required
				/>
				<label for="dhl-polska-template-width">
					<?php esc_html_e( 'Szerokość', 'dhl-polska' ); ?>
				</label>
				<input
					type="number"
					class="small-text"
					id="dhl-polska-template-width"
					name="<?php echo esc_attr( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::FIELD_WIDTH ); ?>"
					value="<?php echo esc_attr( $width ); ?>"
					min="1"
					step="1"
					required
				/>
				<label for="dhl-polska-template-height">
					<?php esc_html_e( 'Wysokość', 'dhl-polska' ); ?>
				</label>
				<input
					type="number"
					class="small-text"
					id="dhl-polska-template-height"
					name="<?php echo esc_attr( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::FIELD_HEIGHT ); ?>"
					value="<?php echo esc_attr( $height ); ?>"
					min="1"
					step="1"
					required
				/>
				<span class="description"><?php echo esc_html( $dimension_unit ); ?></span>
			</td>
		</tr>
		<tr>
			<th scope="row">
				<?php esc_html_e( 'Usługi dodatkowe', 'dhl-polska' ); ?>
			</th>
			<td>
				<label for="dhl-polska-template-cod">
					<input
						type="checkbox"
						id="dhl-polska-template-cod"
						name="<?php echo esc_attr( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::FIELD_COD ); ?>"
						<?php checked( $cod ); ?>
					/>
					<?php esc_html_e( 'Pobranie', 'dhl-polska' ); ?>
				</label>
				<label for="dhl-polska-template-insurance">
					<input
						type="checkbox"
						id="dhl-polska-template-insurance"
						name="<?php echo esc_attr( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::FIELD_INSURANCE ); ?>"
						<?php checked( $insurance ); ?>
					/>
					<?php esc_html_e( 'Ubezpieczenie', 'dhl-polska' ); ?>
				</label>
			</td>
		</tr>
	</tbody>
</table>

<?php wp_nonce_field( \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::NONCE_ACTION, \DhlPolska\ShipmentTemplates\ShipmentTemplateMetabox::NONCE_FIELD ); ?>
