<?php
/**
 * @var array $calculate
 * @var mixed $calculate_response
 * @var mixed $order_id
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}


$order_placed_data = alsendo_connect()->get_delivery_point_meta_data( $order_id );
$supplier          = ! empty( $order_placed_data['apm_supplier'] ) ? $order_placed_data['apm_supplier'] : null;
$single_offer = false;
if( is_array($calculate) && 1 === count($calculate) ) {
    $single_offer = true;
}
?>

<fieldset id="apaczka_calculate_radio">
	<?php $first = true; ?>
	<?php $i = 0; ?>
	<?php foreach ( $calculate as $k => $service ) : ?>
		<?php
        if( $single_offer ) {
            $selected = ' selected';
        } else {
            $selected = '';
            if ( $supplier === $service['supplier'] ) {
                $selected = ' selected';
            }
        }
		?>
		<label class="apaczka-calculate-item <?php echo esc_attr( $selected ); ?>"
				data-item="<?php echo esc_attr( $i ); ?>"
				data-pickup_courier="<?php echo esc_attr( $service['pickup_courier'] ); ?>"
				data-service_id="<?php echo esc_attr( $k ); ?>"
				data-supplier="<?php echo esc_attr( $service['supplier'] ); ?>">
			<p class="apaczka-logo-wrapper <?php echo 'service_id_' . esc_attr( $k ); ?>">
				<?php
				$logo     = alsendo_connect()->get_logo_zaslat( $k );
				$logo_src = '';
				if ( $logo ) {
					$logo_src = alsendo_connect()->get_plugin_img_url() . '/' . $logo . '.png';
				}
				?>
				<img class="apaczka-service-logo" src="<?php echo esc_url( $logo_src ); ?>" style="">
			</p>
			<p>
				<?php
				echo esc_attr( $service['name'] );
				?>
			</p>
			<div class="apaczka-calculate-item-price-wrapper">
				<p>
					<?php echo esc_html( $service['price'] ); ?>
					<?php echo esc_html( $service['currency'] ); ?> netto
				</p>
				<p>
					<?php echo esc_html( $service['price_gross'] ); ?>
					<?php echo esc_html( $service['currency'] ); ?> brutto
				</p>
				<input
						type="radio"
						value="<?php echo esc_attr( $k ); ?>"
						id="apaczka_calculate_radio_<?php echo esc_attr( $k ); ?>"
						data-supplier="<?php echo esc_attr( $service['supplier'] ); ?>"
						class="apaczka_calculate_radio"
						name="apaczka_calculate_radio"
				>
				<?php ++$i; ?>
			</div>
		</label>
		<?php $first = false; ?>
	<?php endforeach; ?>

</fieldset>
<?php