<?php

/**
 * Add placeholders button.
 * copyright Simple Direct Plugins - support@simpledirectplugins.com
 *
 * @author 			Simple Direct Plugins
 * @link			https://simpledirectplugins.com
 * @since			6.1.0
 * @package			SCOSWoo
 *
 */

defined ('ABSPATH') or exit;

if (!class_exists ('SCOS_Editor')) :

	Class SCOS_Editor {

		public function __construct () {

			add_action ('wp_enqueue_media', [$this, 'add_scos_placeholder_js'], 10);
			}

		public function add_scos_placeholder_js () {

			if (SCOS_CPT::CPT === get_post_type()) {

				wp_enqueue_style ('scos-jquery-ui', esc_url (SCOS_ASSETS . 'css/jquery-ui.min.css'), [], '1.14.2');
				wp_enqueue_style ('scos-placeholder-button', esc_url (SCOS_ASSETS . 'css/buttons.min.css'), [], '1.1');
				wp_enqueue_script ('scos-placeholder-button', esc_url (SCOS_ASSETS . 'js/buttons.min.js'), ['jquery', 'jquery-ui-dialog', 'jquery-ui-tabs'], '1.1', true);
				wp_localize_script ('scos-placeholder-button', 'scosPlaceholdersData', $this->placeholders_array());
				}
			}

		private function placeholders_array (): array {

			$placeholders = [
				'%%first_name%%'		=> esc_html__('First name', 'woocommerce'),
				'%%last_name%%'			=> esc_html__('Last name', 'woocommerce'),
				'%%company%%'			=> esc_html__('Company', 'woocommerce'),
				'%%order_number%%'		=> esc_html__('Order number', 'sdp-custom-order-status-for-woocommerce'),
				'%%email%%'   			=> esc_html__('Email', 'default'),
				'%%table%%'	  			=> esc_html__('Order table', 'sdp-custom-order-status-for-woocommerce'),
				'%%notes%%'				=> esc_html__('Order notes', 'woocommerce'),
				'%%downloads%%'			=> esc_html__('Downloads table', 'sdp-custom-order-status-for-woocommerce'),
				'%%total%%'   			=> esc_html__('Order total', 'sdp-custom-order-status-for-woocommerce'),
				'%%billing_details%%'	=> esc_html__('Billing details', 'sdp-custom-order-status-for-woocommerce'),
				'%%shipping_details%%'	=> esc_html__('Shipping details', 'sdp-custom-order-status-for-woocommerce'),
				'%%phone%%'				=> esc_html__('Phone', 'woocommerce'),
				'%%shipping_method%%'	=> esc_html__('Shipping method', 'woocommerce'),
				'%%payment%%'			=> esc_html__('Payment method', 'woocommerce'),
				'%%instructions%%'		=> esc_html__('Payment method instructions', 'sdp-custom-order-status-for-woocommerce'),
				'%%order_date%%'		=> esc_html__('Order date', 'sdp-custom-order-status-for-woocommerce'),
				];

			if (class_exists ('Plugin_Pide_NIF') || class_exists ('APG_Campo_NIF'))
				$placeholders['%%tax%%'] = esc_html__('Tax ID', 'sdp-custom-order-status-for-woocommerce');

			if (class_exists ('WC_EU_VAT_Number_Init') || class_exists ('YITH_WooCommerce_EU_VAT'))
				$placeholders['%%euvat%%'] = esc_html__('EU VAT number', 'sdp-custom-order-status-for-woocommerce');

			return [
				'button'		=> esc_html__('Add Placeholder', 'sdp-custom-order-status-for-woocommerce'),
				'title'			=> esc_html__('Insert placeholder', 'sdp-custom-order-status-for-woocommerce'),
				'cancel'		=> esc_html__('Cancel', 'default'),
				'width'			=> apply_filters ('scos_placeholders_modal_width', wp_is_mobile() ? 300 : 700),
				'groups'		=> [
					'email'		=> $placeholders,
					],
				];
			}

		}

endif;