<?php
/**
 * Field content tab controls
 * @var string $prefix
 * @var string $widget_id
 * @var Repeater $field
 * @var Field $this
 */

use Elementor\Controls_Manager;
use Elementor\Repeater;
use HulkPlugins\ElementorPro\Forms\InternationalTelephoneField\Field;
use HulkPlugins\ElementorPro\Forms\InternationalTelephoneField\Utils\Helper;
use const HulkPlugins\ElementorPro\Forms\InternationalTelephoneField\DOCUMENTATION;

defined( 'ABSPATH' ) || exit;

$field->add_control(
	$prefix . 'placeholder',
	[
		'label'       => esc_html__( 'Placeholder', 'international-telephone-field-for-elementor-form' ),
		'description' => esc_html__( 'Use this {{country}} placeholder for the selected country.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'placeholder' => 'e.g. {{country}}',
	]
);

$field->add_control(
	$prefix . 'initialCountry',
	[
		'label'       => esc_html__( 'Default Country', 'international-telephone-field-for-elementor-form' ),
		'description' => esc_html__( 'Set default country code in telephone field.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::SELECT2,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => false,
		'multiple'    => false,
		'options'     => Helper::getCountries(),
		'default'     => 'us',
	]
);

$field->add_control(
	$prefix . 'onlyCountries',
	[
		'label'       => esc_html__( 'Only Countries', 'international-telephone-field-for-elementor-form' ),
		'description' => esc_html__( 'In the dropdown, display only the countries you specify.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::SELECT2,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'multiple'    => true,
		'options'     => Helper::getCountries(),
		'default'     => [],
	]
);

$field->add_control(
	$prefix . 'excludeCountries',
	[
		'label'       => esc_html__( 'Exclude Countries', 'international-telephone-field-for-elementor-form' ),
		'description' => esc_html__( 'In the dropdown, display all countries except the ones you specify here.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::SELECT2,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'multiple'    => true,
		'options'     => Helper::getCountries(),
		'default'     => [],
	]
);

$field->add_control(
	$prefix . 'countryOrder',
	[
		'label'       => esc_html__( 'Country Order', 'international-telephone-field-for-elementor-form' ),
		'description' => esc_html__( 'Specify the countries to appear at the top of the list, add comma separated - us, bg. Check country codes list here', 'international-telephone-field-for-elementor-form' ) . ' <a href="https://www.iban.com/country-codes" target="_blank">https://www.iban.com/country-codes</a>',
		'placeholder' => esc_html__( 'us,gb', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'default'     => '',
		'label_block' => true,
	]
);

$field->add_control(
	$prefix . 'nationalMode',
	[
		'label'        => esc_html__( 'National Mode', 'international-telephone-field-for-elementor-form' ),
		'description'  => esc_html__( 'Format numbers in the national format, rather than the international format.', 'international-telephone-field-for-elementor-form' ),
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'yes',
	]
);

$field->add_control(
	$prefix . 'strictMode',
	[
		'label'        => esc_html__( 'Strict Mode', 'international-telephone-field-for-elementor-form' ),
		'description'  => esc_html__( 'As the user types in the input, ignore any irrelevant characters. Basically, the user can only enter numeric characters, and an optional plus at the beginning. Cap the length at the maximum valid number length.', 'international-telephone-field-for-elementor-form' ),
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'yes',
	]
);

$field->add_control(
	$prefix . 'autoCountry',
	[
		'label'        => esc_html__( 'Auto Detect Country', 'international-telephone-field-for-elementor-form' ),
		'description'  => esc_html__( 'Auto-select the user country using an IP address.', 'international-telephone-field-for-elementor-form' ) . Helper::fsNotice(),
		'classes'      => Helper::isFsNotice() ? 'hulk-epfitf-notice' : '',
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'yes',
	]
);

$field->add_control(
	$prefix . 'showFlags',
	[
		'label'        => esc_html__( 'Show Flags', 'international-telephone-field-for-elementor-form' ),
		'description'  => esc_html__( 'Set this to false to hide the flags.', 'international-telephone-field-for-elementor-form' ) . Helper::fsNotice(),
		'classes'      => Helper::isFsNotice() ? 'hulk-epfitf-notice' : '',
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'yes',
	]
);

$field->add_control(
	$prefix . 'separateDialCode',
	[
		'label'        => esc_html__( 'Separate Dial Code', 'international-telephone-field-for-elementor-form' ),
		'description'  => esc_html__( 'Display the selected country dial code next to the input.', 'international-telephone-field-for-elementor-form' ) . Helper::fsNotice(),
		'classes'      => Helper::isFsNotice() ? 'hulk-epfitf-notice' : '',
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'no',
	]
);

$field->add_control(
	$prefix . 'fullPhone',
	[
		'label'        => esc_html__( 'Send as Full Phone', 'international-telephone-field-for-elementor-form' ),
		'description'  => esc_html__( 'Decide whether to send the full phone number (example: +12015550123) or the formatted number (example: (201) 555-0123).', 'international-telephone-field-for-elementor-form' ) . Helper::fsNotice(),
		'classes'      => Helper::isFsNotice() ? 'hulk-epfitf-notice' : '',
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'no',
	]
);

$field->add_control(
	$prefix . 'internationalisation',
	[
		'label'       => esc_html__( 'Internationalisation', 'international-telephone-field-for-elementor-form' ),
		'description' => Helper::fsNotice(),
		'classes'     => Helper::isFsNotice() ? 'hulk-epfitf-notice' : '',
		'type'        => Controls_Manager::SELECT2,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => false,
		'multiple'    => false,
		'options'     => Helper::getI18nLanguages(),
		'default'     => 'en',
	]
);

$field->add_control(
	$prefix . 'enableValidation',
	[
		'label'        => esc_html__( 'Enable Validation', 'international-telephone-field-for-elementor-form' ),
		'description'  => esc_html__( 'Validate the user input before submitting the form', 'international-telephone-field-for-elementor-form' ),
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'yes',
	]
);

$field->add_control(
	$prefix . 'customMessages',
	[
		'label'        => esc_html__( 'Custom Messages', 'international-telephone-field-for-elementor-form' ),
		'description'  => Helper::fsNotice(),
		'classes'      => Helper::isFsNotice() ? 'hulk-epfitf-notice' : '',
		'type'         => Controls_Manager::SWITCHER,
		'control_tab'  => Controls_Manager::TAB_CONTENT,
		'return_value' => 'yes',
		'default'      => 'no',
		'condition'    => [
			$prefix . 'enableValidation' => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'TOO_SHORT',
	[
		'label'       => esc_html__( 'TOO_SHORT', 'international-telephone-field-for-elementor-form' ),
		'placeholder' => esc_attr__( 'The phone number is too short.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'condition'   => [
			$prefix . 'enableValidation' => 'yes',
			$prefix . 'customMessages'   => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'TOO_LONG',
	[
		'label'       => esc_html__( 'TOO_LONG', 'international-telephone-field-for-elementor-form' ),
		'placeholder' => esc_attr__( 'The phone number is too long.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'condition'   => [
			$prefix . 'enableValidation' => 'yes',
			$prefix . 'customMessages'   => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'INVALID_BUT_POSSIBLE',
	[
		'label'       => esc_html__( 'INVALID_BUT_POSSIBLE', 'international-telephone-field-for-elementor-form' ),
		'placeholder' => esc_attr__( 'The phone number is invalid but might still be possible.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'condition'   => [
			$prefix . 'enableValidation' => 'yes',
			$prefix . 'customMessages'   => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'INVALID_COUNTRY_CODE',
	[
		'label'       => esc_html__( 'INVALID_COUNTRY_CODE', 'international-telephone-field-for-elementor-form' ),
		'placeholder' => esc_attr__( 'The phone number has an invalid country code.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'condition'   => [
			$prefix . 'enableValidation' => 'yes',
			$prefix . 'customMessages'   => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'INVALID_LENGTH',
	[
		'label'       => esc_html__( 'INVALID_LENGTH', 'international-telephone-field-for-elementor-form' ),
		'placeholder' => esc_attr__( 'The phone number has an invalid length.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'condition'   => [
			$prefix . 'enableValidation' => 'yes',
			$prefix . 'customMessages'   => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'NOT_A_NUMBER',
	[
		'label'       => esc_html__( 'NOT_A_NUMBER', 'international-telephone-field-for-elementor-form' ),
		'placeholder' => esc_attr__( 'The input is not a valid phone number.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'condition'   => [
			$prefix . 'enableValidation' => 'yes',
			$prefix . 'customMessages'   => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'UNKNOWN',
	[
		'label'       => esc_html__( 'UNKNOWN', 'international-telephone-field-for-elementor-form' ),
		'placeholder' => esc_attr__( 'Unknown error.', 'international-telephone-field-for-elementor-form' ),
		'type'        => Controls_Manager::TEXT,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'label_block' => true,
		'condition'   => [
			$prefix . 'enableValidation' => 'yes',
			$prefix . 'customMessages'   => 'yes',
		],
	]
);

$field->add_control(
	$prefix . 'documentation',
	[
		'type'        => Controls_Manager::NOTICE,
		'control_tab' => Controls_Manager::TAB_CONTENT,
		'notice_type' => 'info',
		'dismissible' => false,
		'heading'     => '',
		'content'     => Helper::docNoticeControlContent( DOCUMENTATION ),
	]
);
