<?php
/**
 * @var object $ecolet
 * @var int $order_id
 * @var string $id
 */

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


use Inspire_Labs\Alsendo_Connect\Service_Structure_Helper;
use Inspire_Labs\Alsendo_Connect\Shipping_Method_Alsendo_Connect;


$tracking_url    = '';
$package_number  = null;
$ecolet_order_id = '';
$operator        = false;
$preloader       = alsendo_connect()->get_plugin_img_url() . '/animation-round-small.gif';
$order_meta      = alsendo_connect()->get_order_meta_data( $order_id );
if ( ! empty( $order_meta['alsendo_order'] ) ) {

	$ecolet = new \Inspire_Labs\Alsendo_Connect\Ecolet();

	if ( is_array( $order_meta['alsendo_order'] ) ) {
		if ( ! empty( $order_meta['alsendo_order']['slug'] ) ) {
			$operator = $ecolet->get_operator_name( $order_meta['alsendo_order']['slug'] );
		}
		if ( ! empty( $order_meta['alsendo_order']['id'] ) ) {
			$ecolet_order_id = $order_meta['alsendo_order']['id'];
		}
		if ( ! empty( $order_meta['alsendo_order']['ecolet_awb_id'] ) ) {
			$package_number = $order_meta['alsendo_order']['ecolet_awb_id'];
		}

		$tracking_url = $ecolet->get_tracking_url( $package_number );
	}
}
?>
<h3>
	<?php esc_html_e( 'Your order has been placed on Ecolet.ro', 'alsendo-connect' ); ?>
</h3>

<h4><?php esc_html_e( 'The waybill number is:', 'alsendo-connect' ); ?>
	<strong>
		<a target="_blank" href="<?php echo esc_url( $tracking_url ); ?>">
			<?php
			if ( ! empty( $package_number ) ) {
				echo esc_attr( $package_number );
			} else {
				echo '<span id="ecolet_preloader_tracking" data-ecolet-id="' . esc_attr( $ecolet_order_id ) . '"><img src="' . esc_url( $preloader ) . '"></span>';
			}
			?>
		</a>
	</strong>
</h4>

<?php if ( $operator ) { ?>
	<h4><?php esc_html_e( 'Carrier:', 'alsendo-connect' ); ?>
		<strong id="ecolet_choosed_carrier_id" style="color:#36aa27">
			<?php echo esc_attr( $operator ); ?>
		</strong>
	</h4>
<?php } ?>
<br/>
<button
		class="button-primary"
		id="ecolet_get_waybill"
		data-ecolet-id="<?php echo esc_attr( $ecolet_order_id ); ?>">
		<?php
		esc_html_e( 'Download waybill', 'alsendo-connect' );
		?>
</button>
<br/>
<br/>
<button class="button-primary ecolet_cancel" id="ecolet_cancel"  data-ecolet-id="<?php echo esc_attr( $ecolet_order_id ); ?>">
		<?php esc_html_e( 'Cancel parcel', 'alsendo-connect' ); ?>
</button>
<button class="button-primary ecolet_get_order_details"
		id="ecolet_get_order_details"
		data-ecolet-id="<?php echo esc_attr( $ecolet_order_id ); ?>">
		<?php
		esc_html_e(
			'Get package details',
			'alsendo-connect'
		);
		?>
</button>
<span style="margin-top: 10px;" id="alsendo_connect_preloader">
	<img src="<?php echo esc_url( $preloader ); ?>">
</span>
<input type="hidden" id="ecolet_wc_order_id" data-id="<?php echo esc_attr( $order_id ); ?>">
<input type="hidden" id="ecolet_api_order" value="1">
<pre id="json-display-alsendo"></pre>
<?php
