<?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_auth_main_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Auth', 'gigneo' ),
	esc_html__( 'Manage authentication and security options.', 'gigneo' )
);

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

//Basic - Sections
$gigneo_auth_general_heading = Theme_Option::render_heading_markup(
	esc_html__( 'General', 'gigneo' ),
	esc_html__( 'Configure authentication settings for secure user access.', 'gigneo' )
);

$gigneo_auth_general[] =
	Field::make( 'html', 'gigneo_ts_heading_auth_general' )
		->set_html( $gigneo_auth_general_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_auth_general[] =
	Field::make( 'checkbox', 'gigneo_ts_auth_popup', esc_html__( 'Popup', 'gigneo' ) )
		->set_help_text( esc_html__( 'Enable to display the user authentication modal popup.', 'gigneo' ) )
		->set_default_value( true )
		->set_classes( 'gn-switch' );

$gigneo_auth_general[] =
	Field::make( 'select', 'gigneo_ts_auth_popup_layout', esc_html__( 'Popup layout', 'gigneo' ) )
		->set_options(
			apply_filters(
				'gigneo_ts_auth_popup_layout_options',
				array(
					'1' => esc_html__( 'Style 1', 'gigneo' ),
					'2' => esc_html__( 'Style 2', 'gigneo' ),
				)
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( '1' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_auth_popup',
					'value' => true,
				),
				array(
					'field'   => 'gigneo_ts_auth_popup_image',
					'compare' => '>',
					'value'   => 0,
				),
			)
		);

$gigneo_auth_general[] = Field::make( 'image', 'gigneo_ts_auth_popup_image', esc_html__( 'Popup image', 'gigneo' ) )
	->set_conditional_logic(
		array(
			array(
				'field' => 'gigneo_ts_auth_popup',
				'value' => true,
			),
		)
	);

$gigneo_auth_general[] =
	Field::make( 'checkbox', 'gigneo_ts_auth_user_menu', esc_html__( 'User menu', 'gigneo' ) )
		->set_help_text( esc_html__( 'Enable to display the user action menu in the header. ', 'gigneo' ) )
		->set_default_value( true )
		->set_classes( 'gn-switch' );

$gigneo_auth_general[] =
	Field::make( 'text', 'gigneo_ts_auth_login_button', esc_html__( 'Login button text', 'gigneo' ) )
		->set_default_value( esc_html__( 'Sign in', 'gigneo' ) )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_auth_user_menu',
					'value' => true,
				),
			)
		);

$gigneo_auth_general[] =
	Field::make( 'text', 'gigneo_ts_auth_login_button_icon', esc_html__( 'Login button icon', 'gigneo' ) )
		->set_attribute( 'placeholder', 'hi hi-arrow-up-right' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_auth_user_menu',
					'value' => true,
				),
				array(
					'field'   => 'gigneo_ts_auth_login_button',
					'value'   => '',
					'compare' => '!=',
				),
			)
		);

$gigneo_auth_general[] =
	Field::make( 'text', 'gigneo_ts_auth_register_button', esc_html__( 'Register button text', 'gigneo' ) )
		->set_default_value( esc_html__( 'Sign up', 'gigneo' ) )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_auth_user_menu',
					'value' => true,
				),
				array(
					'field' => 'gigneo_ts_disable_registration',
					'value' => false,
				),
			)
		);

$gigneo_auth_general[] =
	Field::make( 'text', 'gigneo_ts_auth_register_button_icon', esc_html__( 'Register button icon', 'gigneo' ) )
		->set_attribute( 'placeholder', 'hi hi-arrow-up-right' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_auth_user_menu',
					'value' => true,
				),
				array(
					'field' => 'gigneo_ts_disable_registration',
					'value' => false,
				),
				array(
					'field'   => 'gigneo_ts_auth_register_button',
					'value'   => '',
					'compare' => '!=',
				),
			)
		);

	$gigneo_auth_general = apply_filters( 'gigneo_ts_tab_auth_section_general_fields', $gigneo_auth_general );
	$gigneo_auth_fields  = array_merge( $gigneo_auth_fields, $gigneo_auth_general );

	//Register - Sections
	$gigneo_auth_register[] =
		Field::make( 'html', 'gigneo_ts_separator_auth_register' )
			->set_html( '<hr>' )
			->set_classes( 'gn-separator' );

	$gigneo_auth_register_heading = Theme_Option::render_heading_markup(
		esc_html__( 'Register', 'gigneo' ),
		esc_html__( 'Manage and configure user sign-up options.', 'gigneo' )
	);

	$gigneo_auth_register[] =
		Field::make( 'html', 'gigneo_ts_heading_auth_register' )
			->set_html( $gigneo_auth_register_heading )
			->set_classes( 'gn-ts-field-heading' );

	$gigneo_auth_register[] =
		Field::make( 'checkbox', 'gigneo_ts_disable_registration', esc_html__( 'Disable registration', 'gigneo' ) )
			->set_help_text( esc_html__( 'Disable the registration feature on the platform.', 'gigneo' ) )
			->set_classes( 'gn-switch' );

	$gigneo_auth_register[] =
		Field::make( 'multiselect', 'gigneo_ts_password_strength', esc_html__( 'Password strength', 'gigneo' ) )
			->set_datastore( new Serialized() )
			->set_options( gigneo_password_strength_options() )
			->set_default_value( 'length' )
			->set_conditional_logic(
				array(
					array(
						'field' => 'gigneo_ts_disable_registration',
						'value' => false,
					),
				)
			);

	$gigneo_auth_register[] =
		Field::make( 'checkbox', 'gigneo_ts_registration_role', esc_html__( 'Registration role', 'gigneo' ) )
			->set_help_text( esc_html__( 'Enable to show the role option on the registration form.', 'gigneo' ) )
			->set_classes( 'gn-switch' )
			->set_default_value( true )
			->set_conditional_logic(
				array(
					array(
						'field' => 'gigneo_ts_disable_registration',
						'value' => false,
					),
				)
			);

	$gigneo_auth_register = apply_filters( 'gigneo_ts_tab_auth_section_register_fields', $gigneo_auth_register );
	$gigneo_auth_fields   = array_merge( $gigneo_auth_fields, $gigneo_auth_register );
