<?php

/**
 * @var int $order_id
 * @var bool $disabled
 * @var mixed $package_created
 */

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

$helper         = \Ilabs\Inpost_International\Helpers\Helper::init();
$input_disabled = '';
?>

<p>
<?php
if ( $disabled ) {
	$input_disabled = ' disabled ';
	?>
	<label disabled style="display: block" for="insurance_amounts" class="graytext">
		<?php esc_html_e( 'Insurance amount: ', 'inpost-international' ); ?>
	</label>
	<?php
} else {
	?>
	<label style="display: block" for="insurance_amounts">
		<?php esc_html_e( 'Insurance amount: ', 'inpost-international' ); ?>
	</label>
	<?php
}

if ( $package_created && ! empty( $package_created['creating_args']['shipment']['valueAddedServices']['insurance'] ) ) {
	$insurance = ! empty( $package_created['creating_args']['shipment']['valueAddedServices']['insurance']['value'] )
		? $package_created['creating_args']['shipment']['valueAddedServices']['insurance']['value']
		: '0.00';
	?>

	<input <?php echo esc_attr( $input_disabled ); ?>
		class="inpost_intl_insurance_amount"
		type="number"
		style=""
		value="<?php echo esc_attr( $insurance ); ?>"
		placeholder="0.00"
		step="any"
		min="0"
		id="inpost_intl_insurance_amount"
		name="inpost_intl_insurance_amount[]">
	<?php
} else {

	$insurance = $helper->get_insurance_amount( $order_id );
	?>
	<input <?php echo esc_attr( $input_disabled ); ?>
		class="inpost_intl_insurance_amount inpost_intl_validated_input"
		type="number" style=""
		value="<?php echo esc_attr( $insurance ); ?>"
		placeholder="0.00"
		step="any"
		min="0"
		max="5000"
		id="inpost_intl_insurance_amount"
		name="inpost_intl_insurance_amount[]<?php echo esc_attr( $input_disabled ); ?>">
	<?php
}
?>
</p>
