<?php
/**
 * @var WC_ORDER $order
 * @var array $alsendo_connect_metabox_order_data
 * @var array $sender_templates
 * @var array $sender_templates_json
 * @var array $package_properties_templates
 * @var array $package_properties_templates_json
 * @var array $package_properties_services
 * @var array $package_properties_parcel_types
 * @var array $package_properties_shipping_methods
 * @var array $package_properties_hours
 * @var bool $package_send
 * @var bool $alsendo_connect_delivery_point
 * @var mixed $alsendo_order_id
 */

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

if ( ! $order || is_wp_error( $order ) ) {
	return;
}


use Inspire_Labs\Alsendo_Connect\Global_Settings;
use Inspire_Labs\Alsendo_Connect\Plugin;
use Inspire_Labs\Alsendo_Connect\Service_Structure_Helper;
use Inspire_Labs\Alsendo_Connect\Zaslat; ?>

<?php
$custom_attributes = array();
if ( $package_send ) {
	$custom_attributes['disabled'] = 'disabled';
}

if ( is_a( $order, 'WC_Order' ) ) {
	$order_id = $order->get_id();
} elseif ( is_object( $order ) ) {
	$order_id = $order->ID;
}

$id = 'gateway';

$order_placed_data = alsendo_connect()->get_delivery_point_meta_data( $order_id );
$service_supplier  = ! empty( $order_placed_data['apm_supplier'] ) ? $order_placed_data['apm_supplier'] : null;
$api_type          = alsendo_connect()->get_main_settings_api();

$helper                 = new \Inspire_Labs\Alsendo_Connect\Helper();
$skip_valuation         = $helper->is_skip_valuation( $order_id );
$alsendo_api_carrier_id = $helper->get_linked_carrier_id( $order_id );

$valuate_button_text      = esc_html__( 'Calculate price', 'alsendo-connect' );
$valuate_button_text_full = esc_html__( 'Get all available services', 'alsendo-connect' );

if ( $skip_valuation /*&& ! empty( $alsendo_api_carrier_id)*/ ) {
	$current_plugin_version = alsendo_connect()->get_plugin_version();
	$skip_valuation_js_path = alsendo_connect()->get_plugin_dir() . 'assets/js/skip-valuation.js';
	$skip_valuation_js_ver  = file_exists( $skip_valuation_js_path ) ? filemtime( $skip_valuation_js_path ) : $current_plugin_version;
	wp_enqueue_script(
		'alsendo-connect-skip-valuation',
		alsendo_connect()->get_plugin_js_url() . '/skip-valuation.js',
		array( 'jquery' ),
		$skip_valuation_js_ver,
		array( 'in_footer' => true )
	);
	wp_localize_script(
		'alsendo-connect-skip-valuation',
		'alsendo_connect_skip_valuation',
		array(
			'ajaxurl'     => admin_url( 'admin-ajax.php' ),
			'toggle_text' => esc_html__( 'Show/Hide', 'alsendo-connect' ),
		)
	);
}

?>

<?php if ( ! $package_send ) : ?>

	<div id="apaczka_panel_sender"
		class="panel woocommerce_options_panel apaczka_panel">

		<h4>
			<?php esc_html_e( 'Sender', 'alsendo-connect' ); ?>
		</h4>

		<div class="options_group">
			<div class="apaczka-sender-template-wrapper">
				<?php
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}
				if ( ! $package_send ) :

					woocommerce_wp_select(
						array(
							'id'                => '_apaczka[sender_template]',
							'label'             => esc_html__(
								'Sender template',
								'alsendo-connect'
							),
							'desc_tip'          => false,
							'type'              => 'number',
							'options'           => $sender_templates,
							'value'             => ! empty( get_option( 'alsendo_connect_settings_general_select_sender_template' ) ) ? get_option( 'alsendo_connect_settings_general_select_sender_template' ) : '',
							'custom_attributes' => array( 'data-raw-id' => 'test' ),
						)
					);
					?>

				<p class="alsendo_connect_load_template_wrap">
					<button id="alsendo_connect_load_sender_settings_btn"
							class='alsendo_connect_load_sender_settings_btn'>
						<?php
						esc_html_e(
							'Get sender data from selected template',
							'alsendo-connect'
						)
						?>
					</button>
				</p>
				<?php endif; ?>
			</div>


			<?php

			$key                           = 'country';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_country = ! empty( get_option( 'alsendo_connect_settings_general_sender_country' ) ) ? get_option( 'alsendo_connect_settings_general_sender_country' ) : 'RO';
			$sender_country = strtoupper( $sender_country );

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Country',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_country,
				)
			);
			?>

			<?php
			$key                           = 'is_residential';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			woocommerce_wp_select(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Address type',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'options'           => array(
						'0' => esc_html__( 'Company', 'alsendo-connect' ),
						'1' => esc_html__( 'Private', 'alsendo-connect' ),
					),
					'value'             => isset( $alsendo_connect_metabox_order_data['sender'][ $key ] )
						? $alsendo_connect_metabox_order_data['sender'][ $key ]
						: '0',
					'custom_attributes' => $custom_attributes,
				)
			);

			?>

			<?php
			$key                           = 'company_name';
			$custom_attributes             = array( 'maxlength' => '50' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Company name',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '',
				)
			);
			?>

			<?php
			$key                           = 'first_name';
			$custom_attributes             = array( 'maxlength' => '50' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_first_name = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'First name',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_first_name,
				)
			);
			?>

			<?php
			$key                           = 'last_name';
			$custom_attributes             = array( 'maxlength' => '50' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_last_name = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Last name',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_last_name,
				)
			);
			?>

			<?php
			$key                           = 'street';
			$custom_attributes             = array( 'maxlength' => '50' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			$sender_street = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'Street name', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_street,
				)
			);
			?>

			<?php
			$key                           = 'building_number';
			$custom_attributes             = array( 'maxlength' => '10' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_building_number = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Street number',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_building_number,
				)
			);
			?>

			<?php
			$key                           = 'block';
			$custom_attributes             = array( 'maxlength' => '10' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_block = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'Block', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_block,
				)
			);
			?>

			<?php
			$key                           = 'entrance';
			$custom_attributes             = array( 'maxlength' => '10' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_entrance = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'Entrance', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_entrance,
				)
			);
			?>

			<?php
			$key                           = 'floor';
			$custom_attributes             = array( 'maxlength' => '10' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_floor = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'Floor', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_floor,
				)
			);
			?>

			<?php
			$key                           = 'apartment_number';
			$custom_attributes             = array( 'maxlength' => '10' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_apartment_number = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Apartment',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_apartment_number,
				)
			);
			?>

			<?php
			$key                           = 'postal_code';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_postal_code = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Postal code',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_postal_code,
				)
			);
			?>

			<?php
			$key                           = 'city';
			$custom_attributes             = array( 'maxlength' => '50' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_city = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'City', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_city,
				)
			);


			$province_from_default_settings = get_option( ( new Global_Settings() )->get_setting_id( 'sender_province' ) );

			$key                           = 'province';
			$custom_attributes             = array( 'maxlength' => '50' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'County', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : $province_from_default_settings,
				)
			);
			?>

			<?php
			$key                           = 'contact_person';
			$custom_attributes             = array( 'maxlength' => '50' );
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$sender_contact_person = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Contact person',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $sender_contact_person,
				)
			);
			?>

			<?php
			$key                           = 'phone';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$value = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'Phone', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $value,
				)
			);
			?>

			<?php
			$key                           = 'email';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$value = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__( 'E-mail', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'email',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $value,
				)
			);
			?>

			<?php
			$key                           = 'bank_account_number';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$value = ! empty( $alsendo_connect_metabox_order_data['sender'][ $key ] ) ? $alsendo_connect_metabox_order_data['sender'][ $key ] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[sender][%s]',
						$key
					),
					'label'             => esc_html__(
						'Bank account number',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $value,
				)
			);
			?>

			<input type="hidden"
					data-key="foreign_address_id"
					id="_apaczka[sender][apm_foreign_access_point_id]"
					name="_apaczka[sender][apm_foreign_access_point_id]"/>

		</div>


	</div>


	<div id="apaczka_panel_receiver"
		class="panel woocommerce_options_panel apaczka_panel">
		<h4>
			<?php esc_html_e( 'Receiver', 'alsendo-connect' ); ?>
		</h4>

		<div class="options_group">

			<?php
			$key                           = 'is_residential';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}
			?>

			<?php
			$key                           = 'country_code';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$country_code = $order->get_shipping_country();

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'Country', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $country_code,
					'placeholder'       => esc_html__( 'Country', 'alsendo-connect' ),
				)
			);
			?>


			<?php
			$key                           = 'name';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => ! empty( $order->get_billing_company() ) || ! empty( $order->get_shipping_company() )
							? esc_html__( 'Company name', 'alsendo-connect' )
							: esc_html__( 'First name', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => ! empty( $order->get_shipping_company() ) ? $order->get_shipping_company() : $alsendo_connect_metabox_order_data['receiver'][ $key ],
					'placeholder'       => ! empty( $order->get_billing_company() ) || ! empty( $order->get_shipping_company() )
							? esc_html__( 'Company name', 'alsendo-connect' )
							: esc_html__( 'First name', 'alsendo-connect' ),
				)
			);
			?>

			<?php
			$ecolet = new \Inspire_Labs\Alsendo_Connect\Ecolet();

			$line_1 = $order->get_shipping_address_1();
			$line_2 = $order->get_shipping_address_2();

			$street_name   = '';
			$street_number = '';

			if ( ! empty( $line_1 ) ) {
				$ecolet_address_street = $ecolet::split_line_one( $line_1, $order_id );
			}
			if ( ! empty( $line_2 ) ) {
				$ecolet_line_2 = $ecolet::split_line_two( $line_2, $line_1, $order_id );
			} else {
				$ecolet_line_2 = $ecolet::split_line_two( '', $line_1, $order_id );
			}

			$key                           = 'line1';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$args = array(
				'id'                => sprintf(
					'_apaczka[receiver][%s]',
					$key
				),
				'desc_tip'          => false,
				'type'              => 'text',
				'custom_attributes' => $custom_attributes,
				'data_type'         => 'text',
				'value'             => ! empty( $ecolet_address_street['name'] ) ? $ecolet_address_street['name'] : '',
			);

			$args['label']       = esc_html__( 'Street name', 'alsendo-connect' );
			$args['placeholder'] = esc_html__( 'Street name', 'alsendo-connect' );

			woocommerce_wp_text_input( $args );
			?>

			<?php
			$key                           = 'line2';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$args = array(
				'id'                => sprintf(
					'_apaczka[receiver][%s]',
					$key
				),
				'desc_tip'          => false,
				'type'              => 'text',
				'custom_attributes' => $custom_attributes,
				'data_type'         => 'text',
				'value'             => ! empty( $ecolet_address_street['number'] ) ? $ecolet_address_street['number'] : '',
			);

			$args['label']       = esc_html__( 'Street number', 'alsendo-connect' );
			$args['placeholder'] = esc_html__( 'Street number', 'alsendo-connect' );

			woocommerce_wp_text_input( $args );

			$key                           = 'block';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$block = ! empty( $ecolet_line_2['block'] ) ? $ecolet_line_2['block'] : '';


			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'Block', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $block,
					'placeholder'       => esc_html__( 'Block', 'alsendo-connect' ),
				)
			);


			$key                           = 'entrance';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			$entrance = ! empty( $ecolet_line_2['entrance'] ) ? $ecolet_line_2['entrance'] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'Entrance', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $entrance,
					'placeholder'       => esc_html__( 'Entrance', 'alsendo-connect' ),
				)
			);


			$key                           = 'floor';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			$floor = ! empty( $ecolet_line_2['floor'] ) ? $ecolet_line_2['floor'] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'Floor', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $floor,
					'placeholder'       => esc_html__( 'Floor', 'alsendo-connect' ),
				)
			);

			$key                           = 'apartment';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			$flat = ! empty( $ecolet_line_2['flat'] ) ? $ecolet_line_2['flat'] : '';

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'Apartment', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $flat,
					'placeholder'       => esc_html__( 'Apartment', 'alsendo-connect' ),
				)
			);
			?>

			<?php
			$key                           = 'postal_code';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'Postcode', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $alsendo_connect_metabox_order_data['receiver'][ $key ],
					'placeholder'       => esc_html__( 'Postcode', 'alsendo-connect' ),
				)
			);
			?>

			<?php
			$key                           = 'city';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'City', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => ! empty( $alsendo_connect_metabox_order_data['receiver'][ $key ] ) ? $alsendo_connect_metabox_order_data['receiver'][ $key ] : '',
					'placeholder'       => esc_html__( 'City', 'alsendo-connect' ),
				)
			);
			?>

			<?php
			$key                           = 'contact_person';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__(
						'Contact person',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $alsendo_connect_metabox_order_data['receiver'][ $key ],
					'placeholder'       => esc_html__( 'Contact person', 'alsendo-connect' ),
				)
			);
			?>

			<?php
			$key                           = 'phone';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$receiver_phone = '';
			if ( ! empty( $order->get_shipping_phone() ) ) {
				$receiver_phone = $order->get_shipping_phone();
			} elseif ( ! empty( $order->get_billing_phone() ) ) {
				$receiver_phone = $order->get_billing_phone();
			} elseif ( ! empty( $alsendo_connect_metabox_order_data['receiver'][ $key ] ) ) {
					$receiver_phone = $alsendo_connect_metabox_order_data['receiver'][ $key ];
			}

			$receiver_phone = $helper->ecolet_phone_validation( $receiver_phone, $country_code );

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'Phone', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $receiver_phone,
					'placeholder'       => esc_html__( 'Phone', 'alsendo-connect' ),
				)
			);
			?>

			<?php
			$key                           = 'email';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[receiver][%s]',
						$key
					),
					'label'             => esc_html__( 'E-mail', 'alsendo-connect' ),
					'desc_tip'          => false,
					'type'              => 'email',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $alsendo_connect_metabox_order_data['receiver'][ $key ],
					'placeholder'       => esc_html__( 'E-mail', 'alsendo-connect' ),
				)
			);
			?>

		</div>
	</div>

	<div id="apaczka_panel_properties"
		class="panel woocommerce_options_panel apaczka_panel">

		<h4>
			<?php esc_html_e( 'Package properties', 'alsendo-connect' ); ?>
		</h4>

		<div class="options_group">

			<div class="apaczka-sender-template-wrapper">
				<?php
				$selected_template_in_settings = get_option( ( new Global_Settings() )->get_setting_id( 'select_package_template' ) );

				$key                           = 'selected_template';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}
				woocommerce_wp_select(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Package properties template',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'options'           => $package_properties_templates,
						'value'             => $selected_template_in_settings,
						'custom_attributes' => $custom_attributes,
					)
				);
				?>

				<?php if ( ! $package_send ) : ?>
					<p class="alsendo_connect_load_template_wrap">
						<button id="alsendo_connect_load_package_properties_settings_btn"
								class='alsendo_connect_load_package_properties_settings_btn'>
							<?php
							esc_html_e(
								'Get data from selected template',
								'alsendo-connect'
							)
							?>
						</button>
					</p>
				<?php endif; ?>

			</div>

			<?php
			$key                           = 'parcel_type';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$parcel_types_apaczka = $package_properties_parcel_types;
			$parcel_types_ecolet  = array(
				'package'         => esc_html__(
					'Package',
					'alsendo-connect'
				),
				'envelope'        => esc_html__(
					'Envelope',
					'alsendo-connect'
				),
				'europalette'     => esc_html__(
					'Euro palette 120x80',
					'alsendo-connect'
				),
				'palette_60x80'   => esc_html__(
					'Half palette 80x60',
					'alsendo-connect'
				),
				'palette_120x100' => esc_html__(
					'Industrial palette 120x100',
					'alsendo-connect'
				),
				'palette_120x120' => esc_html__(
					'Industrial palette 120x120',
					'alsendo-connect'
				),
			);

			$parcel_types_options = $parcel_types_ecolet;

			woocommerce_wp_select(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Parcel type',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'options'           => $parcel_types_options,
					'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : '',
					'custom_attributes' => $custom_attributes,
				)
			);
			?>

			<?php
			$key                           = 'is_nstd';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}
			woocommerce_wp_select(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Non standard package',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'options'           => array(
						'yes' => esc_html__( 'Yes', 'alsendo-connect' ),
						'no'  => esc_html__( 'No', 'alsendo-connect' ),
					),
					'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : '',
					'custom_attributes' => $custom_attributes,
				)
			);
			?>

			<div class="ecolet-cloned-fields-wrapper default-wrapper" data-wrap-id="parcel_wrap_0">

			<?php
			$key                           = 'package_length';
			$custom_attributes             = array();
			$custom_attributes['min']      = 0;
			$custom_attributes['max']      = 10000;
			$custom_attributes['step']     = 1;
			$custom_attributes['required'] = 0;
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			$input_value = ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : 0;
			if ( empty( $input_value ) ) {
				$input_value = ! empty( get_option( 'alsendo_connect_settings_general_package_length' ) ) ? get_option( 'alsendo_connect_settings_general_package_length' ) : 0;
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Package length',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'value'             => $input_value,
					'custom_attributes' => $custom_attributes,
				)
			);
			?>



			<?php
			$key                           = 'package_width';
			$custom_attributes['min']      = 0;
			$custom_attributes['max']      = 10000;
			$custom_attributes['step']     = 1;
			$custom_attributes['required'] = 0;
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			$input_value = ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : 0;
			if ( empty( $input_value ) ) {
				$input_value = ! empty( get_option( 'alsendo_connect_settings_general_package_width' ) ) ? get_option( 'alsendo_connect_settings_general_package_width' ) : 0;
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Package width',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'value'             => $input_value,
					'custom_attributes' => $custom_attributes,
				)
			);
			?>



			<?php
			$key                           = 'package_height';
			$custom_attributes             = array();
			$custom_attributes['min']      = 0;
			$custom_attributes['max']      = 10000;
			$custom_attributes['step']     = 1;
			$custom_attributes['required'] = 0;
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}
			$input_value = ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : 0;
			if ( empty( $input_value ) ) {
				$input_value = ! empty( get_option( 'alsendo_connect_settings_general_package_height' ) ) ? get_option( 'alsendo_connect_settings_general_package_height' ) : 0;
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Package height',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'value'             => $input_value,
					'custom_attributes' => $custom_attributes,
				)
			);
			?>

			<?php
			$key                           = 'package_weight';
			$custom_attributes             = array();
			$custom_attributes['min']      = 0;
			$custom_attributes['max']      = 10000;
			$custom_attributes['step']     = 1;
			$custom_attributes['required'] = 0;
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}
			$input_value = ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : 0;
			if ( empty( $input_value ) ) {
				$input_value = ! empty( get_option( 'alsendo_connect_settings_general_package_weight' ) ) ? get_option( 'alsendo_connect_settings_general_package_weight' ) : 0;
			}
			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Package weight',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'value'             => $input_value,
					'custom_attributes' => $custom_attributes,
				)
			);
			?>

			<?php
			$key                           = 'package_contents';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}
			$input_value = ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : '';

			if ( ! empty( $input_value ) ) {
				if ( 'custom_text' === $input_value ) {
					$input_value = get_option( 'alsendo_connect_settings_general_custom_text_content' );
				}
				if ( 'order_id' === $input_value || 'product_id' === $input_value || 'product_name' === $input_value ) {
					$custom_attributes['disabled'] = 'disabled';
					if ( 'order_id' === $input_value ) {
						$input_value = esc_html__( 'Order ID', 'alsendo-connect' );
					}
					if ( 'product_id' === $input_value ) {
						$input_value = esc_html__( 'Product ID', 'alsendo-connect' );
					}
					if ( 'product_name' === $input_value ) {
						$input_value = esc_html__( 'Product Name', 'alsendo-connect' );
					}
				}
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Package contents',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'text',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $input_value,
				)
			);
			?>



			<?php
			$key                           = 'declared_content';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			$custom_attributes['min']      = 0;
			$custom_attributes['step']     = 0.01;

			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}
			
			if( 'yes' === get_option( 'alsendo_connect_settings_general_declared_content_auto' ) ) {
                $input_value = $order->get_total();
            } else {
                $input_value = ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : 0;
            }

			$args = array(
				'id'                => sprintf(
					'_apaczka[package_properties][%s]',
					$key
				),
				'value'             => $input_value,
				'label'             => esc_html__(
					'Declared value',
					'alsendo-connect'
				),
				'custom_attributes' => $custom_attributes,
				'class'             => '',
			);

			$args['type'] = 'number';
			
			woocommerce_wp_text_input( $args );
			?>

			</div>

			<?php
			woocommerce_wp_text_input(
				array(
					'id'       => 'ecolet_add_parcel',
					'class'    => 'button-primary',
					'label'    => esc_html__(
						'Add parcel',
						'alsendo-connect'
					),
					'desc_tip' => false,
					'type'     => 'button',
					'value'    => esc_html__( 'Add new parcel', 'alsendo-connect' ),
				)
			);

			?>

			<?php
			$key               = 'cod_amount';
			$custom_attributes = array();

			$custom_attributes['min']  = 0;
			$custom_attributes['step'] = 0.01;

			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$cod_amount = ! empty( $alsendo_connect_metabox_order_data['additional_options'][ $key ] ) ? $alsendo_connect_metabox_order_data['additional_options'][ $key ] : 0;

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[additional_options][%s]',
						$key
					),
					'label'             => esc_html__(
						'COD amount',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'custom_attributes' => $custom_attributes,
					'data_type'         => 'text',
					'value'             => $cod_amount,
				)
			);
			?>


			<?php
			$key                           = 'comment';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[additional_options][%s]',
						$key
					),
					'value'             => $alsendo_connect_metabox_order_data['additional_options'][ $key ] ?? '',
					'label'             => esc_html__(
						'Comment',
						'alsendo-connect'
					),
					'custom_attributes' => $custom_attributes,
					'class'             => '',
				)
			);
			?>

			<?php
			$key                           = 'shipping_method';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}


			$wc_order = wc_get_order( $order_id );
			if ( 'RO' === $wc_order->get_shipping_country() ) {
				unset( $package_properties_shipping_methods['POINT'] );
			}

			$shipping_method_from_settings = get_option( ( new Global_Settings() )->get_setting_id( 'shipping_method' ) );

			$selected_value = '';
			if ( isset( $alsendo_connect_metabox_order_data['package_properties'][ $key ] )
				&& ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ) {
				$selected_value = $alsendo_connect_metabox_order_data['package_properties'][ $key ];
			} else {
				$selected_value = $shipping_method_from_settings;
			}



			$package_properties_shipping_methods = array(
				'COURIER'          => esc_html__( 'Courier pickup request', 'alsendo-connect' ),
				'SELF_GLS'         => esc_html__( 'Pickup self GLS', 'alsendo-connect' ),
				'SELF_SAMEDAY'     => esc_html__( 'Pickup self SAMEDAY', 'alsendo-connect' ),
				'SELF_DPD'         => esc_html__( 'Pickup self DPD', 'alsendo-connect' ),
				'SELF_CARGUS'      => esc_html__( 'Pickup self CARGUS', 'alsendo-connect' ),
				'SELF_FAN_COURIER' => esc_html__( 'Pickup self FAN COURIER', 'alsendo-connect' ),
			);


			if ( $service_supplier ) {
				if ( 'CARGUS' === $service_supplier ) {
					$package_properties_shipping_methods = array(
						'COURIER'     => esc_html__( 'Courier pickup request', 'alsendo-connect' ),
						'SELF_CARGUS' => esc_html__( 'Pickup self CARGUS', 'alsendo-connect' ),
					);
				} elseif ( 'FAN_COURIER' === $service_supplier ) {
					$package_properties_shipping_methods = array(
						'COURIER'          => esc_html__( 'Courier pickup request', 'alsendo-connect' ),
						'SELF_FAN_COURIER' => esc_html__( 'Pickup self FAN COURIER', 'alsendo-connect' ),
					);
				} elseif ( 'SAMEDAY' === $service_supplier ) {
					$package_properties_shipping_methods = array(
						'COURIER'      => esc_html__( 'Courier pickup request', 'alsendo-connect' ),
						'SELF_SAMEDAY' => esc_html__( 'Pickup self SAMEDAY', 'alsendo-connect' ),
					);
				} elseif ( 'DPD' === $service_supplier ) {
					$package_properties_shipping_methods = array(
						'COURIER'  => esc_html__( 'Courier pickup request', 'alsendo-connect' ),
						'SELF_DPD' => esc_html__( 'Pickup self DPD', 'alsendo-connect' ),
					);
				} elseif ( 'GLS' === $service_supplier ) {
					$package_properties_shipping_methods = array(
						'COURIER'  => esc_html__( 'Courier pickup request', 'alsendo-connect' ),
						'SELF_GLS' => esc_html__( 'Pickup self GLS', 'alsendo-connect' ),

					);
				}
			}


			if ( ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ) {
				$selected_value = $alsendo_connect_metabox_order_data['package_properties'][ $key ];
			} elseif ( $service_supplier ) {

				if ( 'CARGUS' === $service_supplier ) {
					$selected_value = 'SELF_CARGUS';

				} elseif ( 'FAN_COURIER' === $service_supplier ) {
					$selected_value = 'SELF_FAN_COURIER';

				} elseif ( 'SAMEDAY' === $service_supplier ) {
					$selected_value = 'SELF_SAMEDAY';

				} elseif ( 'DPD' === $service_supplier ) {
					$selected_value = 'SELF_DPD';

				} elseif ( 'GLS' === $service_supplier ) {
					$selected_value = 'SELF_GLS';
				}
			} else {
				$selected_value = $shipping_method_from_settings;
			}


			woocommerce_wp_select(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Shipping method',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'options'           => $package_properties_shipping_methods,
					'value'             => $selected_value,
					'custom_attributes' => $custom_attributes,
				)
			);

			?>


			<?php
			$key                           = 'pickup_hour_from';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}
			woocommerce_wp_select(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Pickup hour from',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'options'           => $package_properties_hours,
					'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : '',
					'custom_attributes' => $custom_attributes,
				)
			);
			?>

			<?php
			$key                           = 'pickup_hour_to';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			woocommerce_wp_select(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Pickup hour to',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'number',
					'options'           => $package_properties_hours,
					'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : '',
					'custom_attributes' => $custom_attributes,
				)
			);
			?>

			<?php
			$key                           = 'pickup_date';
			$custom_attributes             = array();
			$custom_attributes['data-key'] = $key;
			if ( $package_send ) {
				$custom_attributes['disabled'] = 'disabled';
			}

			$pickup_date = ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : null;
			if ( $pickup_date && strtotime( $pickup_date ) !== false ) {
				if ( strtotime( $pickup_date ) < strtotime( 'today' ) ) {
					$new_date    = gmdate( 'Y-m-d' );
					$pickup_date = $new_date;
				}
			} else {
				$pickup_date = gmdate( 'Y-m-d' );
			}

			woocommerce_wp_text_input(
				array(
					'id'                => sprintf(
						'_apaczka[package_properties][%s]',
						$key
					),
					'label'             => esc_html__(
						'Pickup date',
						'alsendo-connect'
					),
					'desc_tip'          => false,
					'type'              => 'date',
					'value'             => $pickup_date,
					'custom_attributes' => $custom_attributes,
				)
			);
			?>

		</div>


	</div>

<?php endif ?>

<div class="panel woocommerce_options_panel apaczka_panel">
	<?php if ( $package_send == false ) : ?>
		<div class="apaczka-actions-wrapper">
			<div class="options_panel-button-wrapper">
				<button class="button-primary apaczka_calculate_price" id="apaczka_calculate_price_btn">
					<?php echo esc_html( $valuate_button_text ); ?>
				</button>
				<?php if ( $skip_valuation || ! empty( $alsendo_api_carrier_id ) ) { ?>
					<button class="button-primary apaczka_calculate_price alsendo_full" id="apaczka_calculate_price_btn_full">
						<?php echo esc_html( $valuate_button_text_full ); ?>
					</button>
				<?php } ?>
			</div>
			<div style="padding-top:5px"></div>

			<div id="apaczka-calculate-wrapper"></div>

			<div id="deliver_to_any_shipping_point" style="display:none">
				<p>
					<?php echo esc_html__( 'Deliver the shipment to any shipping point of the selected carrier', 'alsendo-connect' ); ?>
				</p>
			</div>

			<div class="apaczka-hidden" id="dispath_point_cargus_wrapper">
				<?php
				$key                           = 'dispath_point_cargus';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => get_option( 'alsendo_connect_settings_general_dispath_point_cargus' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);
				?>
			</div>

			<div class="apaczka-hidden" id="dispath_point_gls_wrapper">
				<?php
				$key                           = 'dispath_point_gls';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => get_option( 'alsendo_connect_settings_general_dispath_point_gls' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);
				?>
			</div>

			<div class="apaczka-hidden" id="dispath_point_fancourier_wrapper">
				<?php
				$key                           = 'dispath_point_fancourier';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => get_option( 'alsendo_connect_settings_general_dispath_point_fan_courier' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);
				?>
			</div>


			<div class="apaczka-hidden" id="dispath_point_sameday_wrapper">
				<?php
				$key                           = 'dispath_point_sameday';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => get_option( 'alsendo_connect_settings_general_dispath_point_sameday' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);
				?>
			</div>

			<div class="apaczka-hidden" id="dispath_point_inpost_wrapper">
				<?php
				$key                           = 'dispath_point_inpost';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : get_option( 'alsendo_connect_settings_general_dispath_point_inpost' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);
				?>
			</div>

			<div class="apaczka-hidden" id="dispath_point_kurier48_wrapper">
				<?php
				$key                           = 'dispath_point_kurier48';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : get_option( 'alsendo_connect_settings_general_dispath_point_kurier48' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);
				?>
			</div>
			<div class="apaczka-hidden" id="dispath_point_ups_wrapper">
				<?php
				$key                           = 'dispath_point_ups';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : get_option( 'alsendo_connect_settings_general_dispath_point_ups' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);

				?>
			</div>

			<div class="apaczka-hidden" id="dispath_point_dpd_wrapper">
				<?php
				$key                           = 'dispath_point_dpd';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[package_properties][%s]',
							$key
						),
						'label'             => esc_html__(
							'Dispath point',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => ! empty( $alsendo_connect_metabox_order_data['package_properties'][ $key ] ) ? $alsendo_connect_metabox_order_data['package_properties'][ $key ] : get_option( 'alsendo_connect_settings_general_dispath_point_dpd' ),
						'placeholder'       => esc_html__( 'Dispath point', 'alsendo-connect' ),
					)
				);
				?>
			</div>


			<div class="apaczka-hidden" id="apaczka_delivery_point_id_wrapper">
				<?php
				$key                           = 'delivery_point_id';
				$custom_attributes             = array();
				$custom_attributes['data-key'] = $key;
				if ( $package_send ) {
					$custom_attributes['disabled'] = 'disabled';
				}

				woocommerce_wp_text_input(
					array(
						'id'                => sprintf(
							'_apaczka[delivery_point_id]',
							$key
						),
						'label'             => esc_html__(
							'Delivery point id',
							'alsendo-connect'
						),
						'desc_tip'          => false,
						'type'              => 'text',
						'custom_attributes' => $custom_attributes,
						'data_type'         => 'text',
						'value'             => isset( $alsendo_connect_delivery_point['apm_foreign_access_point_id'] ) ? $alsendo_connect_delivery_point['apm_foreign_access_point_id'] : '',
						'placeholder'       => esc_html__( 'Delivery point id', 'alsendo-connect' ),
					)
				);

				?>


				<input data-key="apm_access_point_id" type="hidden"
						id="_apaczka_apm_access_point_id"
						name="_apaczka[delivery_point][apm_access_point_id]"/>
				<input data-key="apm_supplier" type="hidden"
						id="_apaczka_apm_supplier"
						name="_apaczka[delivery_point][apm_supplier"/>
				<input data-key="apm_name" type="hidden" id="_apaczka_apm_name"
						name="_apaczka[delivery_point][apm_name]"/>
				<input data-key="apm_foreign_access_point_id" type="hidden"
						id="_apaczka_apm_foreign_access_point_id"
						name="_apaczka[delivery_point][apm_foreign_access_point_id]"/>
				<input data-key="apm_street" type="hidden"
						id="_apaczka_apm_street"
						name="_apaczka[delivery_point][apm_street]"/>
				<input data-key="apm_city" type="hidden" id="_apaczka_apm_city"
						name="_apaczka[delivery_point][apm_city]"/>
				<input data-key="apm_postal_code" type="hidden"
						id="_apaczka_apm_postal_code"
						name="_apaczka[delivery_point][apm_postal_code]"/>
				<input data-key="apm_country_code" type="hidden"
						id="_apaczka_apm_country_code"
						name="_apaczka[delivery_point][apm_country_code]"/>

			</div>

			<div class="options_panel-button-wrapper">

				<?php $send_order_preloader = alsendo_connect()->get_plugin_img_url() . '/animation-round-small.gif'; ?>
				<button disabled class="button-primary apaczka_send"
						id="apaczka_send"
						data-apaczka-id="<?php echo esc_attr( $id ); ?>">
					<?php esc_html_e( 'Send', 'alsendo-connect' ); ?></button>
				<span id="alsendo_connect_preloader"><img src="<?php echo esc_url( $send_order_preloader ); ?>"></span>

			</div>

			<br>
			<!--<span style="float:none;"
					class="spinner spinner_courier"></span>
			<div style="padding-top:5px"></div>-->
			<!--<span style="float:none;" class="spinner spinner_self"></span>-->
		</div>
	<?php endif; ?>
	<div class="apaczka_error" id="apaczka_error">
		<?php
		if ( ! empty( $alsendo_connect_metabox_order_data['error_messages'] ) ) {
			?>
			<hr/>
			<?php echo esc_html( $alsendo_connect_metabox_order_data['error_messages'] ); ?>
		<?php } ?>
	</div>

	<div class="apaczka_success" style="color: lawngreen"
		id="apaczka_success">
	</div>

	<?php
	if ( true === $package_send ) {
		$api_used = alsendo_connect()->get_api_used( $alsendo_connect_metabox_order_data );
		if ( 'apaczka' === $api_used ) {
			include alsendo_connect()->get_plugin_templates_dir()
					. DIRECTORY_SEPARATOR
					. 'html-order-metabox-package-sent-apaczka.php';
		}
		if ( 'ecolet' === $api_used ) {
			include alsendo_connect()->get_plugin_templates_dir()
					. DIRECTORY_SEPARATOR
					. 'html-order-metabox-package-sent-ecolet.php';
		}
		if ( 'zaslat' === $api_used ) {
			include alsendo_connect()->get_plugin_templates_dir()
					. DIRECTORY_SEPARATOR
					. 'html-order-metabox-package-sent-zaslat.php';
		}
	}
	?>
</div>
<input type="hidden" id="alsendo_connect_wc_order_id" value="<?php echo esc_attr( $order_id ); ?>">
<input type="hidden" id="alsendo_connect_order_created" value="<?php echo esc_attr( $alsendo_order_id ); ?>">
<input type="hidden" id="alsendo_connect_buyer_supplier" value="<?php echo esc_attr( $service_supplier ); ?>">
<input type="hidden" name="_apaczka[delivery_point]" value="<?php echo esc_attr( wp_json_encode( $order_placed_data ) ); ?>">
<input type="hidden" id="alsendo_connect_calculated" value="<?php echo esc_attr( alsendo_connect()->get_is_order_calculated( $order_id ) ); ?>">
<?php
