<?php

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

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

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

function list_general(): string {
	$content         = '<section id="list-options">';
	$content         .= '<div><h3>List Options</h3></div>';
	$content         .= '<table id="list-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',
				'list',
				'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][list][general][' . $key . ']',
				'checked' => $checked,
			)
		);
	}
	$address_options    = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'list',
			'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][list][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][list][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][list][general][display_address_options]',
			'value' => 'city_state',
			'var'   => $city_state_address,
		)
	);
	$content .= '</td></tr>';

	$content       .= '<tr><td><hr></td></tr>';
	$vdp_link_name = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'list',
			'general',
			'buttons',
			'vdp_link',
			'name',
		)
	);
	$form_name     = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'list',
			'general',
			'buttons',
			'form',
			'name',
		)
	);
	$form_id       = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'list',
			'general',
			'buttons',
			'form',
			'gform_id',
		)
	);
	if ( Display::theme_check() ) {
		$value       = Option::check_for_option(
			'cdp_theme_options',
			array(
				'theme',
				'inventory_display',
				'list',
				'general',
				'list_title_heading',
			)
		);
		$content     .= table_rows::tr_setting_text(
			array(
				'label'       => 'Title heading',
				'id'          => 'list_title_heading',
				'class'       => 'input-long',
				'name'        => 'cdp_theme_options[theme][inventory_display][list][general][list_title_heading]',
				'value'       => $value,
				'placeholder' => 'Select from any of our vehicles!',
			)
		);
		$content     .= '<tr><td><hr></td></tr>';
		$box_content = Option::check_for_option(
			'cdp_theme_options',
			array(
				'theme',
				'inventory_display',
				'list',
				'general',
				'buttons',
				'box',
				'content',
			)
		);
		$content     .= table_rows::tr_setting_textarea(
			array(
				'id'      => 'extra-button-box',
				'label'   => 'Box Content',
				'name'    => 'cdp_theme_options[theme][inventory_display][list][general][buttons][box][content]',
				'value'   => $box_content,
				'notes'   => '(Allowable merge tags: [VIN], [STOCK])',
				'tooltip' => array(
					'text'     => 'No Javascipt allowed.',
					'position' => 'right'
				),
			)
		);
	}
	$content .= table_rows::tr_setting_text(
		array(
			'id'    => 'link-to-vdp-name',
			'class' => 'input-long',
			'label' => 'Link to VDP Button',
			'name'  => 'cdp_theme_options[theme][inventory_display][list][general][buttons][vdp_link][name]',
			'value' => $vdp_link_name,
		)
	);
	$content .= '<tr class="cdp-row">';
	$content .= '<th><label>Form Button</label></th>';
	$content .= '<td class="td-text">Name:</td>';
	$content .= table_rows::td_setting_text(
		array(
			'id'       => 'list-form-button-name',
			'class'    => 'input-long',
			'td_class' => 'td-text',
			'name'     => 'cdp_theme_options[theme][inventory_display][list][general][buttons][form][name]',
			'value'    => $form_name,
		)
	);
	$content .= '<td class="td-text">Form Id:</td>';
	$content .= table_rows::td_setting_text(
		array(
			'td_class' => 'td-text',
			'name'     => 'cdp_theme_options[theme][inventory_display][list][general][buttons][form][gform_id]',
			'value'    => $form_id,
			'type'     => 'number',
			'min'      => 0,
		)
	);
	$content .= '</tr>';

	$content .= '<tr><td><hr></td></tr>';
	$value   = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'list',
			'general',
			'no_results_form',
		)
	);
	$content .= table_rows::tr_setting_text(
		array(
			'id'    => 'theme-no-results-form',
			'label' => 'No Results Form ID',
			'name'  => 'cdp_theme_options[theme][inventory_display][list][general][no_results_form]',
			'value' => $value,
			'type'  => 'number',
		)
	);

	$value   = Option::check_for_option(
		'cdp_theme_options',
		array(
			'theme',
			'inventory_display',
			'list',
			'general',
			'no_results_form_text',
		)
	);
	$content .= table_rows::tr_setting_text(
		array(
			'id'          => 'theme-no-results-form-text',
			'class'       => 'input-long',
			'label'       => 'No Results Form Text',
			'name'        => 'cdp_theme_options[theme][inventory_display][list][general][no_results_form_text]',
			'value'       => $value,
			'placeholder' => 'Sorry, no results found. Please modify your selection in the filters above, remove existing filters',
		)
	);

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

	return $content;
}
