<?php
/**
 * @var array $args
 * @var float $default_weight
 * @var string $weight_unit
 * @var string $dimension_unit
 * @var \DhlPolska\Shipment\ShipmentTypes $shipment_types
 *
 * @package DhlPolska\Shipment\Metabox\Field
 */

use DhlPolska\Shipment\Metabox\Field\PackageRow;

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

?>

<div class="form-row packages">
	<div class="dhl-polska-packages-container js--packages-container">
		<?php
		foreach ( $args['packages'] as $package_number => $package ) {
			$package_row = new PackageRow( ( $package_number + 1 ), $package, $shipment_types, $args['disabled'], $weight_unit, $dimension_unit );

			echo $package_row->render(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		}
		?>
	</div>

	<?php if ( ! $args['disabled'] ) : ?>
		<div class="dhl-polska-add-package-buttons">
			<a href="#0"
				data-integration="dhl_polska"
				class="button js--add-package"><?php esc_html_e( 'Dodaj paczkę', 'dhl-polska' ); ?></a>
		</div>
	<?php endif; ?>

	<div class="new-text js--new-package-field hidden">
		<?php
		$package_row = new PackageRow(
			0,
			[
				'weight' => $default_weight,
				'type'   => \DhlPolska\Shipment\ShipmentTypes::TYPE_PACKAGE,
			],
			$shipment_types,
			false,
			$weight_unit,
			$dimension_unit
		);
		echo $package_row->render(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		?>
	</div>
</div>
