<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

$img_kses = apply_filters(
    'dokan_product_image_attributes', [
        'img' => [
            'alt'         => [],
            'class'       => [],
            'height'      => [],
            'src'         => [],
            'width'       => [],
            'srcset'      => [],
            'data-srcset' => [],
            'data-src'    => [],
        ],
    ]
);
if(class_exists('Pixad_Booking_AUTO') && class_exists('Pix_Autos')){
    if ( $_product ){
        $catalog_item_id = get_post_meta($_product->get_id(), 'pixba_sim_product_id', true);
    }
}

?>
<tr class="item <?php echo ! empty( $class ) ? esc_attr( $class ) : ''; ?>" data-order_item_id="<?php echo esc_attr( $item_id ); ?>">
    <td class="thumb" style="width: 10%">
        <?php if ( $_product ) : ?>
            <?php if(class_exists('Pixad_Booking_AUTO') && class_exists('Pix_Autos') && isset($catalog_item_id) && $catalog_item_id != ''){
                $featured_image =  get_the_post_thumbnail_url($catalog_item_id);
                ?>
                <a href="<?php echo esc_url( get_permalink($catalog_item_id) ); ?>">
                    <img src="<?php echo esc_url($featured_image)?>"/>
                </a>
            <?php } else { ?>
                <a href="<?php echo esc_url( get_permalink( $_product->get_id() ) ); ?>">
                    <?php echo wp_kses( $_product->get_image( 'shop_thumbnail', [ 'title' => '' ] ), $img_kses ); ?>
                </a>
            <?php } ?>
        <?php else : ?>
            <?php echo wp_kses_post( wc_placeholder_img( 'shop_thumbnail' ) ); ?>
        <?php endif; ?>
    </td>

    <td class="name" style="width: 65%">

        <?php if(class_exists('Pixad_Booking_AUTO') && class_exists('Pix_Autos') && isset($catalog_item_id) && $catalog_item_id != ''){ ?>
            <a target="_blank" href="<?php echo esc_url( get_permalink( $catalog_item_id ) ); ?>">
                <?php echo esc_html( $item['name'] ); ?>
            </a>

            <?php $start_location = $item->get_meta('Start location');
            if(isset($start_location) && $start_location != ''){ ?>
                <div class="tm_order_meta"><?php echo __("Start location: " , "autozone") . $start_location?></div>
            <?php } ?>


            <?php $sfinish_location = $item->get_meta('Finish location');
            if(isset($sfinish_location) && $sfinish_location != ''){ ?>
                <div class="tm_order_meta"><?php echo __("Finish location: " , "autozone") . $sfinish_location?></div>
            <?php } ?>

            <?php $start_time = $item->get_meta('Start time');
            if(isset($start_time) && $start_time != ''){ ?>
                <div class="tm_order_meta"><?php echo __("Start time: " , "autozone") . $start_time?></div>
            <?php } ?>


            <?php $end_time = $item->get_meta('Finish time');
            if(isset($end_time) && $end_time != ''){ ?>
                <div class="tm_order_meta"><?php echo __("Finish time: " , "autozone") . $end_time?></div>
            <?php } ?>


            <?php $extra = $item->get_meta('Extra Resource');
            if(isset($extra) && $extra != ''){ ?>
                <div class="tm_order_meta"><?php echo __("Extra Resource: " , "autozone") . $extra?></div>
            <?php } ?>





        <?php } else { ?>
            <?php if ( $_product ) : ?>
                <a target="_blank" href="<?php echo esc_url( get_permalink( $_product->get_id() ) ); ?>">
                    <?php echo esc_html( $item['name'] ); ?>
                </a>
            <?php else : ?>
                <?php echo esc_html( $item['name'] ); ?>
            <?php endif; ?>
        <?php } ?>


        <small>
            <?php
            if ( $_product && $_product->get_sku() ) {
                echo '<br>' . esc_html( $_product->get_sku() );
            }
            ?>
        </small>
    </td>

    <?php do_action( 'woocommerce_admin_order_item_values', $_product, $item, absint( $item_id ) ); ?>

    <td style="width: 1%">
        <?php
        if ( isset( $item['qty'] ) ) {
            echo esc_html( $item['qty'] );
        }
        ?>
    </td>

    <td class="line_cost" style="width: 1%">
        <?php
        if ( isset( $item['line_total'] ) ) {
            if ( isset( $item['line_subtotal'] ) && $item['line_subtotal'] !== $item['line_total'] ) {
                echo wp_kses_post( '<del>' . wc_price( $item['line_subtotal'] ) . '</del> ' );
            }

            echo wp_kses_post( wc_price( $item['line_total'], [ 'currency' => $order->get_currency() ] ) );
        }
        ?>
    </td>
</tr>
