<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

use Gigneo\Theme_Option;
use Carbon_Fields\Field\Field;
use Gigneo\Theme_Option\Serialized;

//Tab Main Heading
$gigneo_general_main_heading = Theme_Option::render_heading_markup(
	esc_html__( 'General', 'gigneo' ),
	esc_html__( 'Manage your platform core settings.', 'gigneo' )
);

$gigneo_general_fields[] =
	Field::make( 'html', 'gigneo_general_main_heading' )
		->set_html( $gigneo_general_main_heading )
		->set_classes( 'gn-ts-main-heading' );

//Basic - Sections
$gigneo_general_basic_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Basic', 'gigneo' ),
	esc_html__( 'Manage and customize the core system features.', 'gigneo' )
);

$gigneo_general_basic_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_general_basic' )
		->set_html( $gigneo_general_basic_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_general_basic_fields[] =
	Field::make( 'image', 'gigneo_ts_main_icon', esc_html__( 'Platform icon', 'gigneo' ) );

$gigneo_general_basic_fields[] =
	Field::make( 'select', 'gigneo_ts_platform_type', esc_html__( 'Platform type', 'gigneo' ) )
		->set_options(
			array(
				'both'     => esc_html__( 'Both', 'gigneo' ),
				'services' => esc_html__( 'Services', 'gigneo' ),
				'jobs'     => esc_html__( 'Jobs', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( 'both' );

$gigneo_general_basic_fields[] =
	Field::make( 'select', 'gigneo_ts_default_user_role', esc_html__( 'Default user role', 'gigneo' ) )
		->set_options(
			array(
				'freelancer' => gigneo_freelancer_singular(),
				'employer'   => gigneo_employer_singular(),
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( 'employer' );

$gigneo_general_basic_fields[] =
	Field::make( 'select', 'gigneo_ts_display_user_name', esc_html__( 'Display user name', 'gigneo' ) )
		->set_options(
			array(
				'full'  => esc_html__( 'Full name', 'gigneo' ),
				'first' => esc_html__( 'First name', 'gigneo' ),
				'nick'  => esc_html__( 'Nickname', 'gigneo' ),
				'short' => esc_html__( 'Short name', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( 'full' );

$gigneo_general_basic_fields[] =
	Field::make( 'select', 'gigneo_ts_countries', esc_html__( 'Countries', 'gigneo' ) )
		->set_options(
			array(
				'all'        => esc_html__( 'All countries', 'gigneo' ),
				'all_except' => esc_html__( 'All countries, except...', 'gigneo' ),
				'specific'   => esc_html__( 'Specific countries', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( 'specific' );

$country_list = function_exists( 'WC' ) && WC()->countries ? WC()->countries->get_countries() : array();

$gigneo_general_basic_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_except_countries', esc_html__( 'All countries, except', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( $country_list )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_countries',
					'value' => 'all_except',
				),
			)
		);

$gigneo_general_basic_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_specific_countries', esc_html__( 'Specific countries', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( $country_list )
		->set_default_value( 'US' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_countries',
					'value' => 'specific',
				),
			)
		);

$gigneo_general_basic_fields[] =
	Field::make( 'checkbox', 'gigneo_ts_disable_cities', esc_html__( 'Disable cities', 'gigneo' ) )
		->set_help_text( esc_html__( 'Remove city-specific options from the platform by disabling the cities feature.', 'gigneo' ) )
		->set_classes( 'gn-switch' )
		->set_default_value( false );

$gigneo_general_basic_fields = apply_filters( 'gigneo_ts_tab_general_section_basic_fields', $gigneo_general_basic_fields );
$gigneo_general_fields       = array_merge( $gigneo_general_fields, $gigneo_general_basic_fields );

//Dashboard
$gigneo_general_dashboard_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_dashboard' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_general_dashboard_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Dashboard', 'gigneo' ),
	esc_html__( 'Configure and customize your dashboard layout.', 'gigneo' )
);

$gigneo_general_dashboard_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_dashboard' )
		->set_html( $gigneo_general_dashboard_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_general_dashboard_fields[] =
	Field::make( 'image', 'gigneo_ts_main_logo', esc_html__( 'Dashboard logo', 'gigneo' ) );

$gigneo_general_dashboard_fields[] =
	Field::make( 'select', 'gigneo_ts_dashboard_menu_layout', esc_html__( 'Dashboard layout', 'gigneo' ) )
		->set_default_value( 'side' )
		->set_options(
			array(
				'side' => esc_html__( 'Side Panel', 'gigneo' ),
				'top'  => esc_html__( 'Top Header', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' );

$gigneo_general_dashboard_fields[] =
	Field::make( 'select', 'gigneo_ts_dashboard_menu_style', esc_html__( 'Layout style', 'gigneo' ) )
		->set_default_value( '1' )
		->set_options(
			array(
				'1' => esc_html__( 'Classic', 'gigneo' ),
				'2' => esc_html__( 'Modern', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' );

$gigneo_general_dashboard_fields[] =
	Field::make( 'select', 'gigneo_ts_dashboard_sidebar_behaviour', esc_html__( 'Sidebar behaviour', 'gigneo' ) )
		->set_default_value( 'expand' )
		->set_options(
			array(
				'expand'   => esc_html__( 'Expand', 'gigneo' ),
				'collapse' => esc_html__( 'Collapse', 'gigneo' ),
			)
		)
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_dashboard_menu_layout',
					'value' => 'side',
				),
			)
		)
		->set_classes( 'gn-select2' );

$gigneo_general_dashboard_fields[] =
	Field::make( 'select', 'gigneo_ts_dashboard_menu_scheme', esc_html__( 'Menu scheme', 'gigneo' ) )
		->set_default_value( 'default' )
		->set_options(
			array(
				'default' => esc_html__( 'Default', 'gigneo' ),
				'dark'    => esc_html__( 'Dark', 'gigneo' ),
				'light'   => esc_html__( 'Light', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' );

$gigneo_general_dashboard_fields[] =
	Field::make( 'color', 'gigneo_ts_dashboard_layout_background', esc_html__( 'Menu background', 'gigneo' ) )
		->set_alpha_enabled( false )
		->set_conditional_logic(
			array(
				array(
					'field'   => 'gigneo_ts_dashboard_menu_scheme',
					'value'   => array( 'light', 'dark' ),
					'compare' => 'IN',
				),
			)
		);

$gigneo_general_dashboard_fields = apply_filters( 'gigneo_ts_tab_general_section_dashboard_fields', $gigneo_general_dashboard_fields );
$gigneo_general_fields           = array_merge( $gigneo_general_fields, $gigneo_general_dashboard_fields );

//Appearance
$gigneo_general_appearance_fields[] =
	Field::make( 'html', 'gigneo_ts_general_appearance_separator' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_general_appearance_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Appearance', 'gigneo' ),
	esc_html__( 'Customize the look and feel with styling options.', 'gigneo' )
);

$gigneo_general_appearance_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_appearance' )
		->set_html( $gigneo_general_appearance_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_general_appearance_fields[] =
	Field::make( 'checkbox', 'gigneo_ts_load_google_fonts', esc_html__( 'Load Google Fonts', 'gigneo' ) )
		->set_help_text( esc_html__( 'Enable to load selected fonts on the user dashboard only.', 'gigneo' ) )
		->set_classes( 'gn-switch' )
		->set_default_value( false );

$gigneo_general_appearance_fields[] =
	Field::make( 'select', 'gigneo_ts_primary_font', esc_html__( 'Primary font', 'gigneo' ) )
		->set_options( gigneo_google_font_list() )
		->set_classes( 'gn-select2' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_load_google_fonts',
					'value' => true,
				),
			)
		);

$gigneo_general_appearance_fields[] =
	Field::make( 'color', 'gigneo_ts_primary_color', esc_html__( 'Primary color', 'gigneo' ) )
		->set_alpha_enabled( false );

$gigneo_general_appearance_fields[] =
	Field::make( 'select', 'gigneo_ts_secondary_font', esc_html__( 'Secondary font', 'gigneo' ) )
		->set_options( gigneo_google_font_list() )
		->set_classes( 'gn-select2' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_load_google_fonts',
					'value' => true,
				),
			)
		);

$gigneo_general_appearance_fields[] =
	Field::make( 'color', 'gigneo_ts_secondary_color', esc_html__( 'Secondary color', 'gigneo' ) )
		->set_alpha_enabled( false );

$gigneo_general_appearance_fields = apply_filters( 'gigneo_ts_tab_general_section_appearance_fields', $gigneo_general_appearance_fields );
$gigneo_general_fields            = array_merge( $gigneo_general_fields, $gigneo_general_appearance_fields );

//Deactivate Account
if ( in_array( 'deactivate_account', gigneo_active_modules(), true ) || in_array( 'close_account', gigneo_active_modules(), true ) ) {
	$gigneo_general_account_fields[] =
		Field::make( 'html', 'gigneo_ts_separator_account' )
			->set_html( '<hr>' )
			->set_classes( 'gn-separator' );

	$gigneo_general_account_heading = Theme_Option::render_heading_markup(
		esc_html__( 'Account', 'gigneo' ),
		esc_html__( 'Manage account preferences security and options.', 'gigneo' )
	);

	$gigneo_general_account_fields[] =
		Field::make( 'html', 'gigneo_ts_heading_account' )
			->set_html( $gigneo_general_account_heading )
			->set_classes( 'gn-ts-field-heading' );

	if ( in_array( 'deactivate_account', gigneo_active_modules(), true ) ) {
		$gigneo_general_account_fields[] =
			Field::make( 'complex', 'gigneo_ts_deactivate_account_reasons', esc_html__( 'Deactivation reasons', 'gigneo' ) )
				->set_datastore( new Serialized() )
				->add_fields(
					array(
						Field::make( 'text', 'reason', esc_html__( 'Reason', 'gigneo' ) ),
					)
				)
				->set_header_template( '<%- reason %>' )
				->set_default_value(
					array(
						array(
							'reason' => esc_html__( 'Privacy concerns', 'gigneo' ),
						),
						array(
							'reason' => esc_html__( 'Reduced usage', 'gigneo' ),
						),
						array(
							'reason' => esc_html__( 'Security issues', 'gigneo' ),
						),
					)
				)
				->set_collapsed( true );
	}

	if ( in_array( 'close_account', gigneo_active_modules(), true ) ) {

		$gigneo_general_account_fields[] =
			Field::make( 'complex', 'gigneo_ts_close_account_reasons', esc_html__( 'Closure reasons', 'gigneo' ) )
				->set_datastore( new Serialized() )
				->add_fields(
					array(
						Field::make( 'text', 'reason', esc_html__( 'Reason', 'gigneo' ) ),
					)
				)
				->set_header_template( '<%- reason %>' )
				->set_default_value(
					array(
						array(
							'reason' => esc_html__( 'Privacy concerns', 'gigneo' ),
						),
						array(
							'reason' => esc_html__( 'Reduced usage', 'gigneo' ),
						),
						array(
							'reason' => esc_html__( 'Security issues', 'gigneo' ),
						),
					)
				)
				->set_collapsed( true );
	}


	$gigneo_general_account_fields = apply_filters( 'gigneo_ts_tab_general_section_account_fields', $gigneo_general_account_fields );
	$gigneo_general_fields         = array_merge( $gigneo_general_fields, $gigneo_general_account_fields );
}
