<?php

namespace CarDealerPress\Templates\Admin\Theme\Navigation;

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

use CarDealerPress\Includes\Database\Requests;
use CarDealerPress\includes\helpers\helpers as helpers;
use CarDealerPress\Templates\Admin as templates;
use CarDealerPress\templates\partials\admin\Display;

function search_filters_nav() {
	$automall_check = false;
	$company_db     = ( new Requests() )->cdp_db_init( 'company' )[0];
	$dealers        = empty( $company_db['automalls'] ) ? array() : $company_db['automalls'];
	if ( count( $dealers ) > 1 ) {
		$automall_check = true;
	}
	// @codingStandardsIgnoreStart
	$safe = helpers::sanitize_get( $_GET );
	// @codingStandardsIgnoreEnd
	$section2 = $safe['section2'] ?? 'general';

	$content = '<div id="cdp-detail-wrapper" class="settings-wrapper display">';
	$content .= '<div class="wrap">';
	$content .= '<nav class="nav-tab-wrapper">';
	$content .= '<a href="?page=cardealerpress_theme&tab=inventory_display&section=list&section1=search_filters&section2=general" class="nav-tab ' . ( 'general' === $section2 ? 'nav-tab-active' : '' ) . '">General</a>';
	if ( $automall_check ) {
		$content .= '<a href="?page=cardealerpress_theme&tab=inventory_display&section=list&section1=search_filters&section2=geo_search" class="nav-tab ' . ( 'geo_search' === $section2 ? 'nav-tab-active' : '' ) . '">Geo Search</a>';
	}
	if ( Display::theme_check() ) {
		$content .= '<a href="?page=cardealerpress_theme&tab=inventory_display&section=list&section1=search_filters&section2=color_mapping" class="nav-tab ' . ( 'color_mapping' === $section2 ? 'nav-tab-active' : '' ) . '">Color Mapping</a>';
	}
	$content .= '</nav>';
	$content .= '<div class="tab-content">';
	switch ( $section2 ) :
		case 'general':
			$content .= templates\Theme\inventory_display\vehicle_filtering();
			break;
		case 'geo_search':
			$content .= templates\Theme\inventory_display\geo_settings();
			break;
		case 'color_mapping':
			$content .= templates\Theme\color_mapping();
			break;
	endswitch;
	$content .= '</div>';

	return $content;
}
