<?php

namespace CarDealerPress\templates\admin\theme\inventory_display\detail;

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

use CarDealerPress\Includes\Helpers\Option;
use CarDealerPress\templates\partials\admin\Table_Rows;

function detail_general(): string {
	$content         = '<section id="detail-options">';
	$content         .= '<div><h3>Detail Options</h3></div>';
	$content         .= '<table id="detail-options-table" class="">';
	$content         .= '<tbody>';
	$display_options = array(
		'display_dealer_name',
		'display_dealer_phone',
	);
	foreach ( $display_options as $key ) {
		$checked = Option::check_for_option(
			'cdp_theme_options',
			array(
				'theme',
				'inventory_display',
				'detail',
				'general',
				$key,
			)
		);
		$label   = '';
		foreach ( explode( '_', $key ) as $word ) {
			$label .= ucfirst( $word );
			$label .= ' ';
		}
		$content .= table_rows::tr_setting_checkbox(
			array(
				'id'      => 'inventory_display_' . $key,
				'label'   => $label,
				'name'    => 'cdp_theme_options[theme][inventory_display][detail][general][' . $key . ']',
				'checked' => $checked,
			)
		);
	}
	$address_options    = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'detail',
			'general',
			'display_address_options',
		)
	);
	$no_address         = false;
	$full_address       = false;
	$city_state_address = false;
	if ( 'no_address' === $address_options ) {
		$no_address = true;
	}
	if ( 'full' === $address_options ) {
		$full_address = true;
	}
	if ( 'city_state' === $address_options ) {
		$city_state_address = true;
	}
	$content .= '<tr class="cdp-row">';
	$content .= '<th><label>Address Options</label></th>';
	$content .= '<td>';
	$content .= table_rows::tr_setting_radio(
		array(
			'id'    => '',
			'label' => 'No Address',
			'for'   => 'address',
			'name'  => 'cdp_theme_options[theme][inventory_display][detail][general][display_address_options]',
			'value' => 'no_address',
			'var'   => $no_address,
		)
	);
	$content .= '</td>';
	$content .= '<td>';
	$content .= table_rows::tr_setting_radio(
		array(
			'id'    => '',
			'label' => 'Full',
			'for'   => 'address',
			'name'  => 'cdp_theme_options[theme][inventory_display][detail][general][display_address_options]',
			'value' => 'full',
			'var'   => $full_address,
		)
	);
	$content .= '</td>';
	$content .= '<td>';
	$content .= table_rows::tr_setting_radio(
		array(
			'id'    => '',
			'label' => 'City and State',
			'for'   => 'address',
			'name'  => 'cdp_theme_options[theme][inventory_display][detail][general][display_address_options]',
			'value' => 'city_state',
			'var'   => $city_state_address,
		)
	);
	$content .= '</td></tr>';
	// TODO - probably should remove this. deprecated feature, for vehicles post 2019.
	$checked = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'detail',
			'general',
			'show_standard_eq',
		)
	);
	$content .= table_rows::tr_setting_checkbox(
		array(
			'id'      => 'show_standard_eq',
			'label'   => 'Standard Equipment',
			'name'    => 'cdp_theme_options[theme][inventory_display][detail][general][show_standard_eq]',
			'checked' => $checked,
		)
	);

	$value   = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'detail',
			'general',
			'default_image_tab',
		)
	);
	$content .= table_rows::tr_select_dropown(
		array(
			'label' => 'Default Photo/Video Tab',
			'id'    => 'default_image_tab',
			'name'  => 'cdp_theme_options[theme][inventory_display][detail][general][default_image_tab]',
			'value' => $value,
			'list'  => array( 'Photo', 'Video' ),
			'notes' => 'not Flamingo',
		)
	);

	$value   = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'detail',
			'general',
			'default_info_tab',
		)
	);
	$content .= table_rows::tr_select_dropown(
		array(
			'label' => 'Default Vehicle Info',
			'id'    => 'theme-detail-default_info_tab',
			'name'  => 'cdp_theme_options[theme][inventory_display][detail][general][default_info_tab]',
			'value' => $value,
			'list'  => array( 'Description', 'Options' ),
		)
	);

	// TODO Future: should probably be it's own Social section under Detail.
	$checked = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'detail',
			'general',
			'social',
			'facebook',
			'enable',
		)
	);
	$content .= table_rows::tr_setting_checkbox(
		array(
			'id'      => 'theme-facebook-enable',
			'label'   => 'Enable Facebook Share',
			'name'    => 'cdp_theme_options[theme][inventory_display][detail][general][social][facebook][enable]',
			'checked' => $checked,
		)
	);

	$content .= '<tr><td><hr></td></tr>';
	$value   = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'detail',
			'general',
			'vehicle_sold_form_id',
		)
	);
	$content .= table_rows::tr_setting_text(
		array(
			'id'    => 'theme-sold-form',
			'label' => 'Vehicle Sold Form ID',
			'name'  => 'cdp_theme_options[theme][inventory_display][detail][general][vehicle_sold_form_id]',
			'value' => $value,
			'type'  => 'number',
		)
	);

	$value   = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'detail',
			'general',
			'vehicle_sold_form_text',
		)
	);
	$content .= table_rows::tr_setting_text(
		array(
			'id'          => 'theme-sold-form-text',
			'class'       => 'input-long',
			'label'       => 'Vehicle Sold Form Text',
			'name'        => 'cdp_theme_options[theme][inventory_display][detail][general][vehicle_sold_form_text]',
			'value'       => $value,
			'placeholder' => 'This vehicle is no longer available.',
		)
	);

	$content .= '</tbody>';
	$content .= '</table>';
	$content .= '</section>';

	return $content;
}
