<?php

namespace CarDealerPress\templates\partials\inventory;

use CarDealerPress\Includes\Functions\Extender_Functions;
use CarDealerPress\Includes\Functions\Fn_Inventory;
use CarDealerPress\Includes\Helpers\Option;

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

// for non ajax themes.
class Extra_Boxes {

	public $fn_inventory;
	public $ext_functions;

	public function __construct() {
		$this->fn_inventory  = new Fn_Inventory();
		$this->ext_functions = new Extender_Functions();

	}

	public function boxes_horizontal( $vehicle, $page ): string {
		$boxes   = $this->ext_functions->extender_clean_box_data( $vehicle, $page );
		$tags    = $autocheck = $carfax = '';
		$content = '<div class="extra-boxes-container">';
		if ( 'on' === Option::check_for_option( 'cdp_theme_options', array(
				'theme',
				'inventory_display',
				'tags',
				'display_tags'
			) ) && ! empty( $vehicle['tags'] ) ) {
			$content .= '<div class="extra-box-item box-one-tags">';
			$tags    = $this->fn_inventory->build_tag_icons( $vehicle['tags'], $vehicle['vin'] );
			$content .= $tags;
			$content .= '</div>';
		} else {
			$content .= '<div class="extra-box-item box-one">' . ( $boxes['box_one'] ?? '' ) . '</div>';
		}
		$content .= '<div class="extra-box-item box-two">';
		if ( $vehicle['autocheck'] || $vehicle['carfax'] ) {
			$autocheck = ( $vehicle['autocheck'] ? $this->fn_inventory->display_autocheck_image( $vehicle['vin'], $vehicle['saleclass'], 'list' ) : '' );
			$content   .= $autocheck;
			if ( ! empty( $vehicle['carfax'] ) || 'used' === strtolower( $vehicle['saleclass'] ) ) {
				$carfax  = $this->fn_inventory->cdp_display_carfax( $vehicle['vin'], $vehicle['carfax'], $vehicle['carfax_image_url'], 'list' );
				$content .= $carfax;
			}
		} else {
			$content .= ( $boxes['box_two'] ?? '' );
		}
		$content .= '</div>';
		$content .= '<div class="extra-box-item box-three">' . ( $boxes['box_three'] ?? '' ) . '</div>';
		$content .= '<div class="extra-box-item box-four">' . ( $boxes['box_four'] ?? '' ) . '</div>';

		$content .= '</div>';
		if ( empty( array_filter( $boxes ) ) && empty( $tags ) && empty( $autocheck ) && empty( $carfax ) ) {
			$content = '';
		}

		return $content;
	}


}
