<?php
namespace CarDealerPress\Templates\Inventory;

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

use CarDealerPress\includes\helpers\helpers;
use CarDealerPress\Includes\Helpers\Option;

sort( $vehicle['dealer_options'] );

?>


<div id="inventory-wrapper"> <!-- 2nd Wrapper -->
    <?php
    $banners = Option::check_for_option( 'cdp_theme_options', array( 'theme', 'inventory_display', 'banners' ) );
    if ( ! empty( $banners ) ) {
        $content        = '<div id="cdp-banner-top-container">';
        $banner_results = $fn_inventory->cdp_get_banners( 'detail', 'top', $banners, $this->parameters );
        foreach ( $banner_results as $banner ) {
            $content .= $banner;
        }
        $content .= '</div>';
        echo wp_kses( $content, 'post' );
    }
    ?>
    <div id="inventory-detail"> <!-- Detail Body -->
        <div id="inventory-top"> <!-- Detail Top -->
            <div class="inventory-breadcrumb-wrapper"> <!-- SEO/Taxonomy -->
                <div class="breadcrumbs"><?php helpers::output_wp_kses( $fn_inventory->display_breadcrumb( $this->parameters, $this->company, $this->theme_options['theme']['overrides']['custom_contact'], $saleclass ) ); ?></div>
                <!-- Breadcrumbs -->
                <div class="inventory-print"> <!-- Print -->
                    <a id="friendly-print"
                       onclick="window.open('?print_page','popup','width=800,height=900,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=yes,status=no,left=0,top=0'); return false">Print</a>
                </div>
            </div>
            <?php
            helpers::output_wp_kses( $ext_functions->detail_page_sold_vehicle( $vehicle ) );
            ?>
            <div id="inventory-headline"> <!-- Headline -->
                <h2>
                    <span class="inventory-saleclass"><?php echo esc_html( $vehicle['saleclass'] ); ?></span>
                    <span class="inventory-year"><?php echo esc_html( $vehicle['year'] ); ?></span>
                    <span class="inventory-make"><?php echo esc_html( $vehicle['make'] ); ?></span>
                    <span class="inventory-model"><?php echo esc_html( $vehicle['model'] ); ?></span>
                    <span class="inventory-trim"><?php echo esc_html( $vehicle['trim'] ); ?></span>
                    <span class="inventory-drive-train"><?php echo esc_html( $vehicle['drivetrain'] ); ?></span>
                    <span class="inventory-body-style"><?php echo esc_html( $vehicle['body'] ); ?></span>

                </h2>
                <?php
                if ( ! empty( $vehicle['headline'] ) ) {
                    $value = '<div id="inventory-headline-text">' . $vehicle['headline'] . '</div>';
                    helpers::output_wp_kses( $value );
                }
                ?>

            </div>
        </div> <!-- Detail Top End-->
        <div id="inventory-media-wrapper">
            <div id="inventory-contact-information"> <!-- Contact Information -->
                <?php
                $value = '<div id="inventory-contact-details">';
                $value .= '<span id="inventory-contact-greeting">' . $contact_info['greeting'] . '</span><br/><strong id="inventory-contact-dealer">' . $fn_inventory->get_custom_contact_setting( $saleclass, $vehicle['dealer_id'], 'name' ) . ' </strong>';
                $value .= ' <span id="inventory-contact-phone">: <strong>' . $fn_inventory->get_custom_contact_setting( $saleclass, $vehicle['dealer_id'], 'phone' ) . '</strong></span>';
                $value .= '</div>';
                helpers::output_wp_kses( $value );
                ?>
            </div> <!-- Contact Information End -->
        </div>
        <div id="inventory-detail-information"> <!-- Detail Information -->
            <div id="inventory-column-left"> <!-- Column Left -->
                <div id="inventory-slideshow-text">
                    Click Image to Enlarge
                </div>
                <div id="inventory-slideshow">
                    <?php
                    helpers::output_wp_kses( $fn_inventory->get_photo_detail_display( $vehicle, $this->theme_options['theme']['inventory_display']['detail']['general']['default_image_tab'], '' ) );
                    if ( count( $vehicle['photos_raw'] ) > 1 ) {
                        helpers::output_wp_kses( '<div id="inventory-nav-button" class="' . ( count( $vehicle['photos_raw'] ) > 6 ? 'active' : 'hidden' ) . '">View All Images</div>' );
                    }
                    ?>
                </div>
                <?php
                if ( $this->theme_options['theme']['inventory_display']['tags']['display_tags'] ) {
                    if ( ! empty( $vehicle['tags'] ) ) {
                        echo '<div class="inventory-detail-tags">';
                        $tag_icons = $fn_inventory->build_tag_icons( $vehicle['tags'], $vehicle['vin'] );
                        helpers::output_wp_kses( $tag_icons );
                        echo '</div>';
                    }
                }
                ?>

                <?php
                if ( ! empty( $vehicle['carfax'] ) && 'used' === strtolower( $vehicle['saleclass'] ) ) {
                    helpers::output_wp_kses( $fn_inventory->cdp_display_carfax( $vehicle['vin'], $vehicle['carfax'], $vehicle['carfax_image_url'] ) );
                }

                if ( $vehicle['autocheck'] ) {
                    helpers::output_wp_kses( $fn_inventory->display_autocheck_image( $vehicle['vin'], $vehicle['saleclass'], 'detail' ) );
                }
                ?>
            </div> <!-- Column Left End -->
            <div id="inventory-column-middle"> <!-- Column Middle -->
                <div id="inventory-price-wrapper">
                    <?php
                    helpers::output_wp_kses( $price['hidden_prices'] );
                    helpers::output_wp_kses( $price['primary_text'] . $price['compare_price_text'] . $price['msrp_text'] . $price['expire_text'] );
                    helpers::output_wp_kses( $fn_inventory->get_loan_value( $this->theme_options['theme']['inventory_display']['payment_calculator'], $price['primary_price'], $loan_parameters ) );
                    ?>
                </div>
                <div id="inventory-vehicle-overview">
                    <?php
                    $vehicle_info = '';
                    if ( 'false' !== $vehicle['certified'] ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Certified:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">Yes</div>';
                        $vehicle_info .= '</div>';

                    }

                    if ( ! empty( $vehicle['body'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Body Style:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['body'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['exterior'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Ext. Color:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['exterior'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['interior'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Int. color:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['interior'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['engine'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Engine:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['engine'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['fuel_type'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Fuel Type:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['fuel_type'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['transmission'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Transmission:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['transmission'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['drivetrain'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Drivetrain:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['drivetrain'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['odometer'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Odometer:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['odometer'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle_info ) ) {
                        $vehicle_info .= '<br>';
                    }

                    if ( ! empty( $vehicle['vin'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Vin:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['vin'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    if ( ! empty( $vehicle['stock'] ) ) {
                        $vehicle_info .= '<div class="inventory-vehicle-overview-wrap">';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-left">Stock #:</div>';
                        $vehicle_info .= '<div class="inventory-vehicle-overview-right">' . $vehicle['stock'] . '</div>';
                        $vehicle_info .= '</div>';
                    }

                    helpers::output_wp_kses( $vehicle_info );

                    ?>
                </div>
                <?php
                $fuel_info = $fn_inventory->get_fuel_economy_display( $fuel_economy, $country_code, 1 );
                if ( ! empty( $fuel_info ) ) {
                    helpers::output_wp_kses( $fuel_info );
                }

                ?>
            </div> <!-- Column Middle End -->
            <div id="inventory-column-right"> <!-- Column Right -->
                <?php
                $forms = $this->theme_options['theme']['inventory_display']['detail']['forms'];
                if ( function_exists( 'gravity_form' ) && ! empty( $forms ) ) {
                    $form_id = $forms[0]['id'];
                    $form    = '<div id="content-inner-form">';
                    $form    .= '<div class="form-wrapper"><div id="info-form-id-' . $form_id . '" class="inventory-form form-display-wrap form-' . $form_id . '" data-name="form-id-' . $form_id . '">';
                    $form    .= do_shortcode( '[gravityform id=' . $form_id . ' title=true description=false]' );
                    $form    .= '</div></div></div>';
                    helpers::output_wp_kses( $form );
                }
                if ( function_exists( 'gravity_form' ) && count( $forms ) >= 1 ) {
                    array_shift( $forms ); // skip the first one
                    $gform_buttons = $fn_inventory->get_gform_button_display( $forms, $vehicle['saleclass'] );
                    helpers::output_wp_kses( $gform_buttons );
                }
                helpers::output_wp_kses( $fn_inventory->get_loan_calculator( $this->theme_options['theme']['inventory_display']['payment_calculator'], $vehicle['primary_price'], true, $loan_parameters ) );
                ?>
            </div> <!-- Column Right End -->
            <div id="inventory-detail-specs"> <!-- Detail Specs -->
                <?php
                helpers::output_wp_kses( $fn_inventory->get_vehicle_detail_display( $vehicle['dealer_options'], $vehicle['description'], $this->theme_options['theme']['inventory_display']['detail']['general']['show_standard_eq'], $vehicle['standard_equipment'], $this->theme_options['theme']['inventory_display']['detail']['general']['default_info_tab'] ) );
                ?>
            </div>  <!-- Detail Specs End -->

            <?php
            // inventory Similar Vehicles.
            if ( $this->theme_options['theme']['inventory_display']['detail']['similar_vehicles']['display_similar'] ) {
                echo '<div id="detail-similar-wrapper">';
                helpers::output_wp_kses( $fn_inventory->get_similar_vehicles(
                        $this->vms,
                        $vehicle['vin'],
                        $vehicle['saleclass'],
                        $vehicle['vehicleclass'],
                        $price['primary_price'],
                        $vehicle['make'],
                        $this->theme_options['theme']['overrides']['makes_new']['included'],
                        array(
                                'city'  => $city,
                                'state' => $state,
                        )
                ) );
                echo '</div>';
            }
            ?>

            <div id="inventory-disclaimer">
                <p>
                    <?php
                    helpers::output_wp_kses( $fn_inventory->get_disclaimer() );
                    ?>
                </p>
            </div>
            <?php helpers::output_wp_kses( $fn_inventory->cdp_hidden_vehicle_data( $vehicle ) ); ?>
            <?php
            if ( is_active_sidebar( 'vehicle-detail-page' ) ) :
                echo '<div id="inventory-widget-area" class="sidebar">';
                dynamic_sidebar( 'vehicle-detail-page' );
                echo '</div>';
            endif;
            ?>
        </div> <!-- Detail Information End -->
    </div> <!-- Detail Body End-->
</div>  <!-- 2nd Wrapper End -->
