<?php

/**
 * Campos personalizados.
 * copyright Simple Direct Plugins - support@simpledirectplugins.com
 *
 * @author 			Simple Direct Plugins
 * @link			https://simpledirectplugins.com
 * @since 			1.0.0
 * @package 		SCOSWoo
 *
 */

defined ('ABSPATH') or exit;

if (!class_exists ('SCOS_Fields')) :

	Class SCOS_Fields {

		public function __construct () {

			//Si no se puede cargar ACF da error y sale.
			if (!function_exists ('acf_add_local_field_group') && !function_exists ('register_field_group')) {

				add_action ('admin_notices', [$this, 'error_acf'], 10);
				return;
				}

			$this->inserta_campos();

			add_filter ('acf/settings/remove_wp_meta_box', '__return_false');
			}

		public function error_acf () {

			echo '<div class="notice notice-error is-dismissible"><p>';
			/* translators: the name of the plugin */
			printf (esc_html__('%s couldn\'t retrieve the list of custom fields. Please contact support.', 'sdp-custom-order-status-for-woocommerce'), '<i>SDP Custom Order Status for WooCommerce</i>');
			echo '</p></div>';
			}

		public function inserta_campos () {

			$fields = array_merge (
				$this->campos_tab_aspecto(),
				$this->campos_tab_caracteristicas(),
				$this->campos_tab_notificaciones(),
				$this->campos_tab_telegram(),
				$this->campos_tab_automatizaciones(),
				);

			$campos = [
				'key' 		=> 'group_scos_settings',
				'title' 	=> esc_html__('Order status settings', 'sdp-custom-order-status-for-woocommerce'),
				'fields' 	=> $fields,
				'location'	=> [
					[
						[
							'param' 	=> 'post_type',
							'operator' 	=> '==',
							'value' 	=> SCOS_CPT::CPT,
							],
						],
					],
				'menu_order' 			=> 0,
				'position' 				=> 'normal',
				'style' 				=> 'default',
				'label_placement' 		=> 'top',
				'instruction_placement' => 'label',
				'hide_on_screen' 		=> '',
				'active' 				=> 1,
				'description' 			=> '',
				];

			function_exists ('acf_add_local_field_group') ? acf_add_local_field_group ($campos) : register_field_group ($campos);
			}

		private function campos_tab_aspecto () {

			return [

				[//Pestaña "Aspecto".
					'key' 				=> 'field_scos_appearance_tab',
					'label' 			=> esc_html__('Appearance', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> '',
					'type' 				=> 'tab',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'placement' 		=> 'top',
					'endpoint' 			=> 0,
					],
		
				[//Campo de color del estado.
					'key' 				=> 'field_scos_appearance_color',
					'label' 			=> esc_html__('Color for the order status', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_color',
					'type' 				=> 'color_picker',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'default_value' 	=> '#1e73be',
					],

				[//Campo de color del texto.
					'key' 				=> 'field_scos_appearance_text_color',
					'label' 			=> esc_html__('Text color of the label', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_color_label',
					'type' 				=> 'color_picker',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'default_value' 	=> '#fff',
					],

				[//Campo de icono.
					'key' 				=> 'field_scos_appearance_icon',
					'label' 			=> esc_html__('Icon', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_icono',
					'type' 				=> 'radio',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'choices' 			=> $this->devuelve_iconos(),
					'allow_custom' 		=> 0,
					'save_custom' 		=> 0,
					'default_value' 	=> [],
					'layout' 			=> 'horizontal',
					'toggle' 			=> 0,
					'return_format' 	=> 'array',
					],

				];
			}

		private function campos_tab_caracteristicas () {

			return [

				[//Pestaña "Características".
					'key' 				=> 'field_scos_settings_tab',
					'label' 			=> esc_html__('Settings', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> '',
					'type' 				=> 'tab',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'placement' 		=> 'top',
					'endpoint' 			=> 0,
					],
		
				[//Hacer estado por defecto.
					'key' 				=> 'field_scos_make_default',
					'label' 			=> esc_html__('Set this status as the default after payment completion', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_default',
					'type' 				=> 'true_false',
					'instructions' 		=> esc_html__('When enabled, this order status will be assigned automatically when a payment is completed, replacing WooCommerce\'s default behavior.', 'sdp-custom-order-status-for-woocommerce'),
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'message'			=> '',
					'default_value' 	=> '0',
					'ui' 				=> 1,
					],

				[//Campo de siguiente estado.
					'key' 				=> 'field_scos_next_status',
					'label' 			=> esc_html__('Next status in the order flow', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_sigestado',
					'type' 				=> 'select',
					'instructions' 		=> esc_html__('Sets the action button that will be displayed first for orders in this status.', 'sdp-custom-order-status-for-woocommerce'),
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'choices' 			=> $this->devuelve_estados(), //wc_get_order_statuses(),
					'default_value' 	=> [],
					'allow_null' 		=> 1,
					'multiple' 			=> 0,
					'ui' 				=> 1,
					'ajax' 				=> 0,
					'return_format' 	=> 'value',
					'placeholder' 		=> '',
					],

				[//Checkboxes de características.
					'key' 				=> 'field_scos_settings',
					'name' 				=> 'scos_settings',
					'type' 				=> 'checkbox',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'choices' 			=> [
						'editable'		=> esc_html__('Make orders in this status editable.', 'sdp-custom-order-status-for-woocommerce'),
						'completado'	=> esc_html__('Treat orders in this status as completed.', 'sdp-custom-order-status-for-woocommerce'),
						'descargas'		=> esc_html__('Allow downloads for orders in this status.', 'sdp-custom-order-status-for-woocommerce'),
						'incluir'		=> esc_html__('Include this order status in sales reports (legacy mode for older WooCommerce reports).', 'sdp-custom-order-status-for-woocommerce'),
						],
					'allow_custom' 		=> 0,
					'save_custom' 		=> 0,
					'default_value' 	=> [],
					'layout' 			=> 'vertical',
					'toggle' 			=> 0,
					'return_format' 	=> 'value',
					],

				[//Checkboxes de características pro.
					'key' 				=> 'field_scos_settings_pro',
					'name' 				=> 'scos_settings_pro',
					'type' 				=> 'checkbox',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => 'scos-disabled-field',
						'id' 	=> '',
						],
					'choices' 			=> [
						'restock'	=> '<span class="scos-pro">pro</span>' . esc_html__('Restock products in the order when it changes to this status.', 'sdp-custom-order-status-for-woocommerce'),
						'widget'	=> '<span class="scos-pro">pro</span>' . esc_html__('Show a summary of this order status in the WooCommerce dashboard widget.', 'sdp-custom-order-status-for-woocommerce'),
						],
					'allow_custom' 		=> 0,
					'save_custom' 		=> 0,
					'default_value' 	=> [],
					'layout' 			=> 'vertical',
					'toggle' 			=> 0,
					'return_format' 	=> 'value',
					],
				];
			}

		private function campos_tab_notificaciones () {

			if ($invoices = is_plugin_active ('woocommerce-pdf-invoices-packing-slips/woocommerce-pdf-invoices-packingslips.php')) {

				if (isset ($_GET['post'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended

					$post_id = absint ($_GET['post']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended

					if (($post = get_post ($post_id)) && !is_wp_error ($post) && null !== $post->post_name) {

						$settings_invoice  = get_option ('wpo_wcpdf_documents_settings_invoice');
						
						update_post_meta ($post_id, 'scos_invoice', (isset ($settings_invoice['attach_to_email_ids']) && isset ($settings_invoice['attach_to_email_ids']['scos_order_status_' . $post->post_name])) ? ['factura'] : []);
						}
					}
				}

			$notificaciones[] = [ //Pestaña "Notificaciones".
				'key' 				=> 'field_scos_email_notifactions_tab',
				'label' 			=> esc_html__('Notifications', 'sdp-custom-order-status-for-woocommerce'),
				'name' 				=> '',
				'type' 				=> 'tab',
				'instructions' 		=> '',
				'required' 			=> 0,
				'conditional_logic' => 0,
				'wrapper' 			=> [
					'width' => '',
					'class' => '',
					'id' 	=> '',
					],
				'placement' 		=> 'top',
				'endpoint' 			=> 0,
				];

			$notificaciones[] = [ //Campo de notificaciones.
				'key' 				=> 'field_scos_email_notifactions',
				'label' 			=> esc_html__('Activate notifications for:', 'sdp-custom-order-status-for-woocommerce'),
				'name' 				=> 'scos_notificaciones',
				'type' 				=> 'checkbox',
				'instructions' 		=> '',
				'required' 			=> 0,
				'conditional_logic' => 0,
				'wrapper' 			=> [
					'width' => $invoices ? '50' : '',
					'class' => '',
					'id' 	=> '',
					],
				'choices' 			=> [
					'admin' 	=> esc_html__('Admin', 'sdp-custom-order-status-for-woocommerce'),
					'cliente' 	=> esc_html__('Customer', 'woocommerce'), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
					],
				'allow_custom' 		=> 0,
				'save_custom' 		=> 0,
				'default_value' 	=> [],
				'layout' 			=> 'horizontal',
				'toggle' 			=> 0,
				'return_format' 	=> 'value',
				];

			$invoices and $notificaciones[] = [ //Campo de factura/albarán.
				'key' 				=> 'field_scos_invoice',
				'label' 			=> esc_html__('Attach documents to the notifications:', 'sdp-custom-order-status-for-woocommerce'),
				'name' 				=> 'scos_invoice',
				'type' 				=> 'checkbox',
				'instructions' 		=> '',
				'required' 			=> 0,
				'conditional_logic' => [
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'admin',
							],
						],
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'cliente',
							],
						],
					],
				'wrapper' 			=> [
					'width' => '50',
					'class' => '',
					'id' 	=> '',
					],
				'choices' 			=> [
					'factura' 	=> esc_html__('Invoice', 'sdp-custom-order-status-for-woocommerce'),
					//'albaran' 	=> esc_html__('Packing slip', 'sdp-custom-order-status-for-woocommerce'),
					],
				'allow_custom' 		=> 0,
				'save_custom' 		=> 0,
				'default_value' 	=> [],
				'layout' 			=> 'horizontal',
				'toggle' 			=> 0,
				'return_format' 	=> 'value',
				];

			$notificaciones[] = [ //Campo de direcciones de administración.
				'key' 				=> 'field_scos_email_admin',
				'label' 			=> esc_html__('Admin address', 'sdp-custom-order-status-for-woocommerce'),
				'name' 				=> 'scos_email_admin',
				'type' 				=> 'text',
				'instructions' 		=> esc_html__('Email address to which the admin notification will be sent. Supports multiple addresses separated by a semicolon (;).', 'sdp-custom-order-status-for-woocommerce'),
				'required' 			=> 0,
				'conditional_logic' => [
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'admin',
							],
						],
					],
				'wrapper' 			=> [
					'width' => '',
					'class' => '',
					'id' 	=> '',
					],
				'allow_custom' 		=> 0,
				'save_custom' 		=> 0,
				'default_value' 	=> sanitize_email (get_option ('admin_email')),
				'layout' 			=> 'horizontal',
				'toggle' 			=> 0,
				'return_format' 	=> 'value',
				];

			$notificaciones[] = [ //Campo de asunto.
				'key' 				=> 'field_scos_asunto',
				'label' 			=> esc_html__('Subject', 'sdp-custom-order-status-for-woocommerce'),
				'name'				=> 'scos_asunto',
				'type' 				=> 'text',
				'instructions' 		=> esc_html__('Email subject. Supports placeholders.', 'sdp-custom-order-status-for-woocommerce'),
				'required' 			=> 1,
				'conditional_logic' => [
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'admin',
							],
						],
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'cliente',
							],
						],
					],
				'wrapper' 			=> [
					'width' => '',
					'class' => '',
					'id' 	=> '',
					],
				'default_value' 	=> '',
				'placeholder' 		=> '',
				'prepend' 			=> '',
				'append' 			=> '',
				'maxlength' 		=> '',
				];

			$notificaciones[] = [ //Campo de encabezado.
				'key' 				=> 'field_54b234038f037',
				'label' 			=> esc_html__('Heading', 'sdp-custom-order-status-for-woocommerce'),
				'name'				=> 'scos_heading',
				'type' 				=> 'text',
				'instructions' 		=> esc_html__('If none is set, the email subject will be used. Supports placeholders.', 'sdp-custom-order-status-for-woocommerce'),
				'required' 			=> 0,
				'conditional_logic' => [
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'admin',
							],
						],
						[
							[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'cliente',
							],
						],
					],
				'wrapper' 			=> [
					'width' => '',
					'class' => '',
					'id' 	=> '',
					],
				'default_value' 	=> '',
				'placeholder' 		=> '',
				'prepend' 			=> '',
				'append' 			=> '',
				'maxlength' 		=> '',
				];

			$notificaciones[] = [ //Campo de plantilla.
				'key' 				=> 'field_scos_email_template',
				'label' 			=> esc_html__('Template', 'sdp-custom-order-status-for-woocommerce'),
				'name' 				=> 'scos_plantilla',
				'type' 				=> 'wysiwyg',
				'instructions' 		=> $this->devuelve_instrucciones_correo(),
				'required' 			=> 1,
				'conditional_logic' => [
						[
							[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'admin',
							],
						],
						[
							[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'cliente',
							],
						],
					],
				'wrapper' => [
					'width' => '',
					'class' => '',
					'id' 	=> '',
					],
				'default_value' => '',
				'placeholder' 	=> '',
				'maxlength' 	=> '',
				'rows' 			=> '',
				'new_lines' 	=> 'wpautop',
				];

			$notificaciones[] = [ //Campos de adjuntos.
				'key' 				=> 'field_scos_attachments',
				'label' 			=> esc_html__('Attach files', 'sdp-custom-order-status-for-woocommerce'),
				'name' 				=> 'scos_adjuntos',
				'type' 				=> 'message',
				'instructions' 		=> '',
				'conditional_logic' => [
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'admin',
							],
						],
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'cliente',
							],
						],
					],
				'wrapper' 			=> [
					'width' => '',
					'class' => 'scos-pro-message',
					'id' 	=> '',
					],
				/* translators: link to pro version */
				'message'		 	=> '<span class="scos-pro">pro</span> ' . sprintf (esc_html__('This is a PRO feature. Check out %1$sSDP Custom Order Status Pro%2$s to unlock it.', 'sdp-custom-order-status-for-woocommerce'), '<a target="_blank" href="' . SCOS_PRO_LINK . '">', '</a>'),
				'new_lines'			=> 'wpautop',
				'esc_html'			=> 0,
				];

			$notificaciones[] = [//Campo de estilos.
				'key' 				=> 'field_scos_styles',
				'label' 			=> esc_html__('Custom styles', 'sdp-custom-order-status-for-woocommerce'),
				'name'				=> 'scos_estilos',
				'type' 				=> 'message',
				'instructions' 		=> '',
				'conditional_logic' => [
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'admin',
							],
						],
					[
						[
							'field' 	=> 'field_scos_email_notifactions',
							'operator' 	=> '==',
							'value' 	=> 'cliente',
							],
						],
					],
				'wrapper' 			=> [
					'width' => '',
					'class' => 'scos-pro-message',
					'id' 	=> '',
					],
				/* translators: link to pro version */
				'message'		 	=>  '<span class="scos-pro">pro</span> ' . sprintf (esc_html__('This is a PRO feature. Check out %1$sSDP Custom Order Status Pro%2$s to unlock it.', 'sdp-custom-order-status-for-woocommerce'), '<a target="_blank" href="' . SCOS_PRO_LINK . '">', '</a>'),
				'new_lines'			=> 'wpautop',
				'esc_html'			=> 0,
				];

			return $notificaciones;
			}

		private function campos_tab_telegram () {

			return [

				[//Pestaña "Telegram".
					'key' 				=> 'field_scos_telegram_tab',
					'label' 			=> esc_html__('Telegram', 'sdp-custom-order-status-for-woocommerce') . ' <span class="scos-pro">pro</span>',
					'name' 				=> '',
					'type' 				=> 'tab',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'placement' 		=> 'top',
					'endpoint' 			=> 0,
					],

				[//Mensaje
					'key' 				=> 'field_scos_telegram_message',
					'label' 			=> '',
					'name' 				=> '',
					'type' 				=> 'message',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => 'scos-pro-message',
						'id' 	=> '',
						],
					/* translators: link to pro version */
					'message'		 	=> 'ℹ️ ' . sprintf (esc_html__('These are PRO features. Check out %1$sSDP Custom Order Status Pro%2$s to unlock them.', 'sdp-custom-order-status-for-woocommerce'), '<a target="_blank" href="' . SCOS_PRO_LINK . '">', '</a>'),
					'new_lines'			=> 'wpautop',
					'esc_html'			=> 0,
					],
		
				[//Activar mensaje en Telegram.
					'key' 				=> 'field_scos_telegram_notification',
					'label' 			=> esc_html__('Activate notification', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_telegram_notificar',
					'type' 				=> 'true_false',
					'instructions' 		=> esc_html__('Receive a notification via Telegram when an order changes to this status.', 'sdp-custom-order-status-for-woocommerce'),
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => 'scos-disabled-field',
						'id' 	=> '',
						],
					'message'			=> '',
					'default_value' 	=> '0',
					'ui' 				=> 1,
					],

				[//Campo de plantilla.
					'key' 				=> 'field_scos_telegram_template',
					'label' 			=> esc_html__('Template', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_telegram_plantilla',
					'type' 				=> 'wysiwyg',
					'instructions' 		=> $this->devuelve_variables_telegram(),
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' => [
						'width' => '',
						'class' => 'scos-disabled-field',
						'id' 	=> '',
						],
					'default_value' => '%%shipping_details%%<br>%%table%%<br>%%notes%%',
					'placeholder' 	=> '',
					'maxlength' 	=> '',
					'rows' 			=> '',
					'new_lines' 	=> 'wpautop',
					],

				];
			}

		private function campos_tab_automatizaciones () {

			return [

				[//Pestaña "Automatizaciones".
					'key' 				=> 'field_scos_automations_tab',
					'label' 			=> esc_html__('Automations', 'sdp-custom-order-status-for-woocommerce') . ' <span class="scos-pro">pro</span>',
					'name' 				=> '',
					'type' 				=> 'tab',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => '',
						'id' 	=> '',
						],
					'placement' 		=> 'top',
					'endpoint' 			=> 0,
					],

				[//Mensaje
					'key' 				=> 'field_scos_automation_message',
					'label' 			=> '',
					'name' 				=> '',
					'type' 				=> 'message',
					'instructions' 		=> '',
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => 'scos-pro-message',
						'id' 	=> '',
						],
					/* translators: link to the pro version */
					'message'		 	=> 'ℹ️ ' . sprintf (esc_html__('These are PRO features. Check out %1$sSDP Custom Order Status Pro%2$s to unlock them.', 'sdp-custom-order-status-for-woocommerce'), '<a target="_blank" href="' . SCOS_PRO_LINK . '">', '</a>'),
					'new_lines'			=> 'wpautop',
					'esc_html'			=> 0,
					],

				[//Campo de método de pago OR.
					'key' 				=> 'field_scos_autopago',
					'label' 			=> esc_html__('Payment method', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_autopago',
					'type' 				=> 'select',
					'instructions' 		=> esc_html__('Automatically set orders paid with the selected payment methods to this status.', 'sdp-custom-order-status-for-woocommerce'),
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => 'scos-disabled-field',
						'id' 	=> '',
						],
					'choices' 			=> [
						'sample1'	=> esc_html__('Sample gateway 1', 'sdp-custom-order-status-for-woocommerce'),
						'sample2'	=> esc_html__('Sample gateway 2', 'sdp-custom-order-status-for-woocommerce'),
						],
					'default_value' 	=> [],
					'allow_null' 		=> 1,
					'multiple' 			=> 1,
					'ui' 				=> 1,
					'ajax' 				=> 0,
					'return_format' 	=> 'value',
					'placeholder' 		=> '',
					],

				[//Campo de rol OR.
					'key' 				=> 'field_scos_autorol',
					'label' 			=> esc_html__('User role', 'sdp-custom-order-status-for-woocommerce'),
					'name' 				=> 'scos_autorol',
					'type' 				=> 'select',
					'instructions' 		=> esc_html__('Automatically set orders placed by users with the selected roles to this status.', 'sdp-custom-order-status-for-woocommerce'),
					'required' 			=> 0,
					'conditional_logic' => 0,
					'wrapper' 			=> [
						'width' => '',
						'class' => 'scos-disabled-field',
						'id' 	=> '',
						],
					'choices' 			=> [
						'sample1'	=> esc_html__('Sample role 1', 'sdp-custom-order-status-for-woocommerce'),
						'sample2'	=> esc_html__('Sample role 2', 'sdp-custom-order-status-for-woocommerce'),
						],
					'default_value' 	=> [],
					'allow_null' 		=> 1,
					'multiple' 			=> 1,
					'ui' 				=> 1,
					'ajax' 				=> 0,
					'return_format' 	=> 'value',
					'placeholder' 		=> '',
					],
				];
			}

		private function devuelve_estados () {

			$estados = [];

			foreach (SCOS_CPT::pide_query() as $estado)
				// phpcs:ignore WordPress.Security.NonceVerification.Recommended
				if (!isset ($_GET['post']) || $estado->ID != $_GET['post']) //Excluimos el estado que estamos editando actualmente.
					$estados[$estado->post_name] = esc_html ($estado->post_title) ? : esc_html__('Custom #', 'sdp-custom-order-status-for-woocommerce') . absint ($estado->ID);

			$estados['wc-processing'] = esc_html__('Processing', 'woocommerce'); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
			$estados['wc-completed']  = esc_html__('Completed', 'woocommerce'); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
			return $estados;
			}

		/**
		 * Devuelve la lista de marcadores de posición de la plantilla para las notificaciones por correo.
		 *
		 * @since 	5.1.6
		 * @return 	string
		 *
		 */
		private function devuelve_instrucciones_correo () {

			$instrucciones  = '<p>';
			$instrucciones .= esc_html__('You can use the following placeholders in the message body, subject, and heading:', 'sdp-custom-order-status-for-woocommerce');
			$instrucciones .= '</p>';

			$instrucciones .= '<table><tr><td width="50%" valign="top">';

			$instrucciones .= '<code>%%first_name%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s first name.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%last_name%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s last name.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%company%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s company.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%phone%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s phone number.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%email%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s email.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%order_number%%</code> ';
			$instrucciones .= esc_html__('for the order number.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%table%%</code> ';
			$instrucciones .= esc_html__('for the order summary table.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%total%%</code> ';
			$instrucciones .= esc_html__('for the order total.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '</td><td width="50%" valign="top">';

			$instrucciones .= '<code>%%order_date%%</code> ';
			$instrucciones .= esc_html__('for the order creation date.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%billing_details%%</code> ';
			$instrucciones .= esc_html__('for the billing details.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%shipping_details%%</code> ';
			$instrucciones .= esc_html__('for the shipping details.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%shipping_method%%</code> ';
			$instrucciones .= esc_html__('for the selected shipping method.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%payment%%</code> ';
			$instrucciones .= esc_html__('for the selected payment method.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%instructions%%</code> ';
			$instrucciones .= esc_html__('for the payment method instructions.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%notes%%</code> ';
			$instrucciones .= esc_html__('for the order notes.', 'sdp-custom-order-status-for-woocommerce');
			
			$instrucciones .= '<br><code>%%downloads%%</code> ';
			$instrucciones .= esc_html__('for the order downloads (if any).', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '</td></tr></table>';

			//Integración con otros plugins activos

			$extra = $pidenif = $euvat = false;

			if (class_exists ('Plugin_Pide_NIF') || class_exists ('APG_Campo_NIF')) //WC – APG Campo NIF/CIF/NIE
				$extra = $pidenif = true;

			if (class_exists ('WC_EU_VAT_Number_Init') || class_exists ('YITH_WooCommerce_EU_VAT')) //WooCommerce EU VAT Number y YITH WooCommerce EU VAT, OSS & IOSS Premium
				$extra = $euvat = true;

			if ($extra) {

				$br = false;

				$instrucciones .= '<p>';
				$instrucciones .= esc_html__('In addition, other plugins you have activated allow you to use these additional placeholders:', 'sdp-custom-order-status-for-woocommerce');
				$instrucciones .= '</p><p>';
			
				if ($pidenif) {

					$instrucciones .= '<code>%%tax%%</code> ';
					$instrucciones .= esc_html__('for the customer\'s tax ID.', 'sdp-custom-order-status-for-woocommerce');

					$br = true;
					}

				if ($euvat) {

					$instrucciones .= $br ? '<br>' : '';

					$instrucciones .= '<code>%%euvat%%</code> ';
					$instrucciones .= esc_html__('for the customer\'s EU VAT number.', 'sdp-custom-order-status-for-woocommerce');
					}

				$instrucciones .= '</p>';
				}

			return $instrucciones;
			}

		public static function devuelve_iconos () {

			return [
				'159' => '<span class="dashicons dashicons-marker"></span>', //Icono por defecto
				'10f' => '<span class="dashicons dashicons-insert"></span>',
				'11d' => '<span class="dashicons dashicons-admin-site-alt"></span>',
				'12a' => '<span class="dashicons dashicons-yes-alt"></span>',
				'12d' => '<span class="dashicons dashicons-instagram"></span>',
				'13b' => '<span class="dashicons dashicons-cloud-upload"></span>',
				'14f' => '<span class="dashicons dashicons-remove"></span>',
				'15f' => '<span class="dashicons dashicons-airplane"></span>',
				'16d' => '<span class="dashicons dashicons-bell"></span>',
				'16e' => '<span class="dashicons dashicons-calculator"></span>',
				'18b' => '<span class="dashicons dashicons-google"></span>',
				'18c' => '<span class="dashicons dashicons-hourglass"></span>',
				'18d' => '<span class="dashicons dashicons-linkedin"></span>',
				'18e' => '<span class="dashicons dashicons-money-alt"></span>',
				'19a' => '<span class="dashicons dashicons-whatsapp"></span>',
				'19b' => '<span class="dashicons dashicons-youtube"></span>',
				'100' => '<span class="dashicons dashicons-admin-appearance"></span>',
				'101' => '<span class="dashicons dashicons-admin-comments"></span>',
				'102' => '<span class="dashicons dashicons-admin-home"></span>',
				'103' => '<span class="dashicons dashicons-admin-links"></span>',
				'106' => '<span class="dashicons dashicons-admin-plugins"></span>',
				'107' => '<span class="dashicons dashicons-admin-tools"></span>',
				'108' => '<span class="dashicons dashicons-admin-settings"></span>',
				'109' => '<span class="dashicons dashicons-admin-post"></span>',
				'110' => '<span class="dashicons dashicons-admin-users"></span>',
				'111' => '<span class="dashicons dashicons-admin-generic"></span>',
				'112' => '<span class="dashicons dashicons-admin-network"></span>',
				'118' => '<span class="dashicons dashicons-welcome-learn-more"></span>',
				'119' => '<span class="dashicons dashicons-welcome-write-blog"></span>',
				'128' => '<span class="dashicons dashicons-format-image"></span>',
				'129' => '<span class="dashicons dashicons-camera-alt"></span>',
				'154' => '<span class="dashicons dashicons-star-empty"></span>',
				'155' => '<span class="dashicons dashicons-star-filled"></span>',
				'160' => '<span class="dashicons dashicons-lock"></span>',
				'162' => '<span class="dashicons dashicons-amazon"></span>',
				'174' => '<span class="dashicons dashicons-cart"></span>',
				'177' => '<span class="dashicons dashicons-visibility"></span>',
				'179' => '<span class="dashicons dashicons-search"></span>',
				'182' => '<span class="dashicons dashicons-trash"></span>',
				'192' => '<span class="dashicons dashicons-pinterest"></span>',
				'196' => '<span class="dashicons dashicons-spotify"></span>',
				'223' => '<span class="dashicons dashicons-editor-help"></span>',
				'226' => '<span class="dashicons dashicons-dashboard"></span>',
				'227' => '<span class="dashicons dashicons-flag"></span>',
				'230' => '<span class="dashicons dashicons-location"></span>',
				'231' => '<span class="dashicons dashicons-location-alt"></span>',
				'233' => '<span class="dashicons dashicons-images-alt2"></span>',
				'234' => '<span class="dashicons dashicons-video-alt"></span>',
				'242' => '<span class="dashicons dashicons-share-alt2"></span>',
				'301' => '<span class="dashicons dashicons-twitter"></span>',
				'304' => '<span class="dashicons dashicons-facebook"></span>',
				'308' => '<span class="dashicons dashicons-hammer"></span>',
				'312' => '<span class="dashicons dashicons-products"></span>',
				'316' => '<span class="dashicons dashicons-download"></span>',
				'317' => '<span class="dashicons dashicons-upload"></span>',
				'322' => '<span class="dashicons dashicons-portfolio"></span>',
				'323' => '<span class="dashicons dashicons-tag"></span>',
				'331' => '<span class="dashicons dashicons-book-alt"></span>',
				'334' => '<span class="dashicons dashicons-shield-alt"></span>',
				'348' => '<span class="dashicons dashicons-info"></span>',
				'450' => '<span class="dashicons dashicons-buddicons-topics"></span>',
				'451' => '<span class="dashicons dashicons-buddicons-replies"></span>',
				'454' => '<span class="dashicons dashicons-buddicons-friends"></span>',
				'456' => '<span class="dashicons dashicons-buddicons-groups"></span>',
				'457' => '<span class="dashicons dashicons-buddicons-pm"></span>',
				'464' => '<span class="dashicons dashicons-edit"></span>',
				'466' => '<span class="dashicons dashicons-email-alt"></span>',
				'473' => '<span class="dashicons dashicons-testimonial"></span>',
				'480' => '<span class="dashicons dashicons-archive"></span>',
				'481' => '<span class="dashicons dashicons-clipboard"></span>',
				'483' => '<span class="dashicons dashicons-universal-access"></span>',
				'486' => '<span class="dashicons dashicons-tickets"></span>',
				'488' => '<span class="dashicons dashicons-megaphone"></span>',
				'508' => '<span class="dashicons dashicons-calendar-alt"></span>',
				'511' => '<span class="dashicons dashicons-carrot"></span>',
				'513' => '<span class="dashicons dashicons-store"></span>',
				'515' => '<span class="dashicons dashicons-controls-repeat"></span>',
				'518' => '<span class="dashicons dashicons-controls-back"></span>',
				'519' => '<span class="dashicons dashicons-controls-forward"></span>',
				'523' => '<span class="dashicons dashicons-controls-pause"></span>',
				'524' => '<span class="dashicons dashicons-tickets-alt"></span>',
				'525' => '<span class="dashicons dashicons-phone"></span>',
				'527' => '<span class="dashicons dashicons-palmtree"></span>',
				'529' => '<span class="dashicons dashicons-thumbs-up"></span>',
				'530' => '<span class="dashicons dashicons-thumbs-down"></span>',
				'531' => '<span class="dashicons dashicons-image-rotate"></span>',
				'533' => '<span class="dashicons dashicons-image-filter"></span>',
				'534' => '<span class="dashicons dashicons-warning"></span>',
				'537' => '<span class="dashicons dashicons-sticky"></span>',
				'540' => '<span class="dashicons dashicons-admin-customizer"></span>',
				'541' => '<span class="dashicons dashicons-admin-multisite"></span>',
				'546' => '<span class="dashicons dashicons-paperclip"></span>',
				];
			}

		/**
		 * Devuelve la lista de marcadores de posición de la plantilla para las notificaciones por Telegram.
		 *
		 * @since 	5.6.0
		 * @return 	string
		 *
		 */
		private function devuelve_variables_telegram () {

			$instrucciones  = '<p>';
			$instrucciones .= esc_html__('You can use the following placeholders for the message:', 'sdp-custom-order-status-for-woocommerce');
			$instrucciones .= '</p>';

			$instrucciones .= '<table><tr><td width="50%" valign="top">';

      		$instrucciones .= '<code>%%first_name%%</code> ';
     		$instrucciones .= esc_html__('for the customer\'s first name.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%last_name%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s last name.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%company%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s company.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%phone%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s phone number.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%email%%</code> ';
			$instrucciones .= esc_html__('for the customer\'s email.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%order_number%%</code> ';
			$instrucciones .= esc_html__('for the order number.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%table%%</code> ';
			$instrucciones .= esc_html__('for the order summary table.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '</td><td width="50%" valign="top">';

			$instrucciones .= '<code>%%order_date%%</code> ';
			$instrucciones .= esc_html__('for order creation date.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%total%%</code> ';
			$instrucciones .= esc_html__('for the order total.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%billing_details%%</code> ';
			$instrucciones .= esc_html__('for the billing details.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%shipping_details%%</code> ';
			$instrucciones .= esc_html__('for the shipping details.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%shipping_method%%</code> ';
			$instrucciones .= esc_html__('for the selected shipping method.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%payment%%</code> ';
			$instrucciones .= esc_html__('for the selected payment method.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '<br><code>%%notes%%</code> ';
			$instrucciones .= esc_html__('for the order notes.', 'sdp-custom-order-status-for-woocommerce');

			$instrucciones .= '</td></tr></table>';

			//Integración con otros plugins activos

			$extra = $pidenif = $euvat = false;

			if (class_exists ('Plugin_Pide_NIF') || class_exists ('APG_Campo_NIF')) //WC – APG Campo NIF/CIF/NIE
				$extra = $pidenif = true;

			if (class_exists ('WC_EU_VAT_Number_Init') || class_exists ('YITH_WooCommerce_EU_VAT')) //WooCommerce EU VAT Number y YITH WooCommerce EU VAT, OSS & IOSS Premium
				$extra = $euvat = true;

			if ($extra) {

				$br = false;

				$instrucciones .= '<p>';
				$instrucciones .= esc_html__('In addition, other plugins you have activated allow you to use these additional placeholders:', 'sdp-custom-order-status-for-woocommerce');
				$instrucciones .= '</p><p>';
			
				if ($pidenif) {

					$instrucciones .= '<code>%%tax%%</code> ';
					$instrucciones .= esc_html__('for the customer\'s tax ID.', 'sdp-custom-order-status-for-woocommerce');

					$br = true;
					}

				if ($euvat) {

					$instrucciones .= $br ? '<br>' : '';

					$instrucciones .= '<code>%%euvat%%</code> ';
					$instrucciones .= esc_html__('for the customer’s EU VAT number.', 'sdp-custom-order-status-for-woocommerce');
					}

				$instrucciones .= '</p>';
				}

			$instrucciones .= sprintf ('<p>%s <code>%s</code></p>',esc_html__('You can also replace custom meta keys by enclosing them in double percent symbols. For example:', 'sdp-custom-order-status-for-woocommerce'), '%%_meta_key%%');

			return $instrucciones;
			}

		}

endif;