<?php
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Plugin;

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

class Ecafe_Displaycondition {

	protected $ecDcCondition = array();
	protected $dc_options;

	/**
	 * Constructor
	 */
	public function __construct() {
		$extrasListOpt = get_option( 'ecafe_extension' );
		if ( ! empty( $extrasListOpt ) && ( isset( $extrasListOpt['extrasList'] ) && ! empty( $extrasListOpt['extrasList'] ) ) && in_array( 'ecafe-displaycondition', $extrasListOpt['extrasList'] ) ) {
			$this->ecAddAction();
			$this->EcAddActionRule();
		}
	}

	/**
	 * Condition Set Options
	 */
	private function ecSetOption() {
		$this->dc_options = array(
			array(
				'label'   => esc_html__( 'User', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'login'   => esc_html__( 'Login Status', 'essential-classy-addons-for-elementor' ),
					'role'    => esc_html__( 'Role', 'essential-classy-addons-for-elementor' ),
					'browser' => esc_html__( 'Browser', 'essential-classy-addons-for-elementor' ),
					'os'      => esc_html__( 'Operating System', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'Date and Time', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'day'            => esc_html__( 'Day', 'essential-classy-addons-for-elementor' ),
					'date'           => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
					'daterange'      => esc_html__( 'Date Range', 'essential-classy-addons-for-elementor' ),
					'timerange'      => esc_html__( 'Time Range', 'essential-classy-addons-for-elementor' ),
					'weekofthemonth' => esc_html__( 'Week of the Month (Pro)', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'Post/Page', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'post' => esc_html__( 'Post', 'essential-classy-addons-for-elementor' ),
					'page' => esc_html__( 'Page', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'Other', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'sitelanguage' => esc_html__( 'Site Language', 'essential-classy-addons-for-elementor' ),
					'stringinurl'  => esc_html__( 'String in URL', 'essential-classy-addons-for-elementor' ),
					'urlparameter' => esc_html__( 'URL Parameter', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'WOO (Pro)', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'cartempty'                   => esc_html__( 'Cart', 'essential-classy-addons-for-elementor' ),
					'cartsubtotal'                => esc_html__( 'Cart Sub Total', 'essential-classy-addons-for-elementor' ),
					'carttotal'                   => esc_html__( 'Cart Total', 'essential-classy-addons-for-elementor' ),
					'cartproduct'                 => esc_html__( 'Cart Product', 'essential-classy-addons-for-elementor' ),
					'cartproductcategory'         => esc_html__( 'Cart Product Category', 'essential-classy-addons-for-elementor' ),
					'cartproducttag'              => esc_html__( 'Cart Product Tag', 'essential-classy-addons-for-elementor' ),
					'cartitem'                    => esc_html__( 'Cart Item', 'essential-classy-addons-for-elementor' ),
					'producttype'                 => esc_html__( 'Product - Type', 'essential-classy-addons-for-elementor' ),
					'productcategory'             => esc_html__( 'Product - Category', 'essential-classy-addons-for-elementor' ),
					'producttag'                  => esc_html__( 'Product - Tag', 'essential-classy-addons-for-elementor' ),
					'productprice'                => esc_html__( 'Product Price', 'essential-classy-addons-for-elementor' ),
					'productstock'                => esc_html__( 'Product Stock', 'essential-classy-addons-for-elementor' ),
					'productstockstatus'          => esc_html__( 'Product Stock Status', 'essential-classy-addons-for-elementor' ),
					'productsoldindividually'     => esc_html__( 'Product Sold individually', 'essential-classy-addons-for-elementor' ),
					'purchaseproduct'             => esc_html__( 'Purchase Product', 'essential-classy-addons-for-elementor' ),
					'purchaseproductcategory'     => esc_html__( 'Purchase Product Category', 'essential-classy-addons-for-elementor' ),
					'purchaseproducttag'          => esc_html__( 'Purchase Product Tag', 'essential-classy-addons-for-elementor' ),
					'purchaseordertotal'          => esc_html__( 'Purchase Order Total', 'essential-classy-addons-for-elementor' ),
					'firstpurchasedate'           => esc_html__( 'First Purchase Date', 'essential-classy-addons-for-elementor' ),
					'lastpurchasedate'            => esc_html__( 'Last Purchase Date', 'essential-classy-addons-for-elementor' ),
					'purchasedate'                => esc_html__( 'Purchase Date', 'essential-classy-addons-for-elementor' ),
					'totalorder'                  => esc_html__( 'Total Order No.', 'essential-classy-addons-for-elementor' ),
					'lastorderstatus'             => esc_html__( 'Last Order Status', 'essential-classy-addons-for-elementor' ),
					'totalpurchasedproduct'       => esc_html__( 'Total Purchased Product', 'essential-classy-addons-for-elementor' ),
					'totalpurchasedproductprice'  => esc_html__( 'Total Purchased Product Price', 'essential-classy-addons-for-elementor' ),
					'firstorderbillingcity'       => esc_html__( 'First Order Billing City', 'essential-classy-addons-for-elementor' ),
					'firstorderbillingstate'      => esc_html__( 'First Order Billing State', 'essential-classy-addons-for-elementor' ),
					'firstorderbillingcountry'    => esc_html__( 'First Order Billing Country', 'essential-classy-addons-for-elementor' ),
					'firstorderbillingpostcode'   => esc_html__( 'First Order Billing Postcode', 'essential-classy-addons-for-elementor' ),
					'lastorderbillingcity'        => esc_html__( 'Last Order Billing City', 'essential-classy-addons-for-elementor' ),
					'lastorderbillingstate'       => esc_html__( 'Last Order Billing State', 'essential-classy-addons-for-elementor' ),
					'lastorderbillingcountry'     => esc_html__( 'Last Order Billing Country', 'essential-classy-addons-for-elementor' ),
					'lastorderbillingpostcode'    => esc_html__( 'Last Order Billing Postcode', 'essential-classy-addons-for-elementor' ),
					'firstordershippinggcity'     => esc_html__( 'First Order Shipping City', 'essential-classy-addons-for-elementor' ),
					'firstordershippinggstate'    => esc_html__( 'First Order Shipping State', 'essential-classy-addons-for-elementor' ),
					'firstordershippinggcountry'  => esc_html__( 'First Order Shipping Country', 'essential-classy-addons-for-elementor' ),
					'firstordershippinggpostcode' => esc_html__( 'First Order Shipping Postcode', 'essential-classy-addons-for-elementor' ),
					'lastordershippinggcity'      => esc_html__( 'Last Order Shipping City', 'essential-classy-addons-for-elementor' ),
					'lastordershippinggstate'     => esc_html__( 'Last Order Shipping State', 'essential-classy-addons-for-elementor' ),
					'lastordershippinggcountry'   => esc_html__( 'Last Order Shipping Country', 'essential-classy-addons-for-elementor' ),
					'lastordershippinggpostcode'  => esc_html__( 'Last Order Shipping Postcode', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'ACF (Pro)', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'acftext'        => esc_html__( 'Text', 'essential-classy-addons-for-elementor' ),
					'acfnumber'      => esc_html__( 'Number', 'essential-classy-addons-for-elementor' ),
					'acfboolean'     => esc_html__( 'Boolean', 'essential-classy-addons-for-elementor' ),
					'acfselect'      => esc_html__( 'Select', 'essential-classy-addons-for-elementor' ),
					'acfradio'       => esc_html__( 'Radio', 'essential-classy-addons-for-elementor' ),
					'acfcheckbox'    => esc_html__( 'Checkbox', 'essential-classy-addons-for-elementor' ),
					'acfbuttongroup' => esc_html__( 'Button Group', 'essential-classy-addons-for-elementor' ),
					'acfdate'        => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'Metabox (Pro)', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'mbtext'     => esc_html__( 'Text', 'essential-classy-addons-for-elementor' ),
					'mbnumber'   => esc_html__( 'Number', 'essential-classy-addons-for-elementor' ),
					'mbcheckbox' => esc_html__( 'Checkbox List', 'essential-classy-addons-for-elementor' ),
					'mbradio'    => esc_html__( 'Radio', 'essential-classy-addons-for-elementor' ),
					'mbselect'   => esc_html__( 'Select', 'essential-classy-addons-for-elementor' ),
					'mbdate'     => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'Toolset (Pro)', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'tssingleline' => esc_html__( 'Single Line', 'essential-classy-addons-for-elementor' ),
					'tsnumber'     => esc_html__( 'Number', 'essential-classy-addons-for-elementor' ),
					'tsselect'     => esc_html__( 'Select', 'essential-classy-addons-for-elementor' ),
					'tsradio'      => esc_html__( 'Radio', 'essential-classy-addons-for-elementor' ),
					'tscheckbox'   => esc_html__( 'Checkboxs', 'essential-classy-addons-for-elementor' ),
					'tsdate'       => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'PODS (Pro)', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'podsplaintext'   => esc_html__( 'Plain Text', 'essential-classy-addons-for-elementor' ),
					'podsdate'        => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
					'podsplainnumber' => esc_html__( 'Plain Number', 'essential-classy-addons-for-elementor' ),
					'podsboolean'     => esc_html__( 'Boolean', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'JetEngine (Pro)', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'jetext'     => esc_html__( 'Text', 'essential-classy-addons-for-elementor' ),
					'jenumber'   => esc_html__( 'Number', 'essential-classy-addons-for-elementor' ),
					'jeselect'   => esc_html__( 'Select', 'essential-classy-addons-for-elementor' ),
					'jecheckbox' => esc_html__( 'Checkbox', 'essential-classy-addons-for-elementor' ),
					'jeradio'    => esc_html__( 'Radio', 'essential-classy-addons-for-elementor' ),
					'jeswitcher' => esc_html__( 'Switcher', 'essential-classy-addons-for-elementor' ),
					'jedate'     => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
				),
			),

			array(
				'label'   => esc_html__( 'CFS (Pro)', 'essential-classy-addons-for-elementor' ),
				'options' => array(
					'cfstext'    => esc_html__( 'Text', 'essential-classy-addons-for-elementor' ),
					'cfsselect'  => esc_html__( 'Select', 'essential-classy-addons-for-elementor' ),
					'cfsboolean' => esc_html__( 'Boolean', 'essential-classy-addons-for-elementor' ),
					'cfsdate'    => esc_html__( 'Date', 'essential-classy-addons-for-elementor' ),
				),
			),
		);
	}
	public function get_name() {
		return 'eca-extras-opts';
	}

	protected function ecAddAction() {
		add_action( 'elementor_pro/element/common/section_custom_css/after_section_end', array( $this, 'addControls' ), 10, 2 );
		add_action( 'elementor/element/section/section_custom_css/after_section_end', array( $this, 'addControls' ), 10, 2 );
		add_action( 'elementor/element/common/section_custom_css_pro/after_section_end', array( $this, 'addControls' ), 10, 2 );
		$experiments_manager = Plugin::$instance->experiments;
		if ( $experiments_manager->is_feature_active( 'container' ) ) {
			add_action( 'elementor/element/container/section_layout/after_section_end', array( $this, 'addControls' ), 10, 2 );
		}
	}

	/**
	 * Add Controls
	 */
	public function addControls( $element, $args ) {
		$elementType = $element->get_type();
		$element->start_controls_section(
			'ecaDcSec',
			array(
				'label' => esc_html__( 'EC Display Condition', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_ADVANCED,
			)
		);

		$element->add_control(
			'ecaDcSecSwitch',
			array(
				'label'              => esc_html__( 'Display Condition', 'essential-classy-addons-for-elementor' ),
				'type'               => Controls_Manager::SWITCHER,
				'default'            => '',
				'label_on'           => esc_html__( 'Yes', 'essential-classy-addons-for-elementor' ),
				'label_off'          => esc_html__( 'No', 'essential-classy-addons-for-elementor' ),
				'return_value'       => 'yes',
				'frontend_available' => true,
			)
		);

		if ( $elementType === 'section' || $elementType === 'container' || $elementType === 'widget' ) {
			$element->add_control(
				'ecRenderHtml',
				array(
					'label'              => esc_html__( 'Render HTML with Display None CSS', 'essential-classy-addons-for-elementor' ),
					'default'            => 'yes',
					'type'               => Controls_Manager::SWITCHER,
					'label_on'           => esc_html__( 'Yes', 'essential-classy-addons-for-elementor' ),
					'label_off'          => esc_html__( 'No', 'essential-classy-addons-for-elementor' ),
					'return_value'       => 'yes',
					'frontend_available' => true,
					'condition'          => array(
						'ecaDcSecSwitch' => 'yes',
					),
				)
			);
		}
		$element->add_control(
			'ecDisplayWhen',
			array(
				'label'     => esc_html__( 'Display When', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'any',
				'options'   => array(
					'all' => esc_html__( 'All True', 'essential-classy-addons-for-elementor' ),
					'any' => esc_html__( 'Any one True', 'essential-classy-addons-for-elementor' ),
				),
				'condition' => array(
					'ecaDcSecSwitch' => 'yes',
				),
			)
		);

		$repeater = new Repeater();
		$repeater->add_control(
			'ecDisplayKey',
			array(
				'type'        => Controls_Manager::SELECT,
				'default'     => 'login',
				'label_block' => true,
				'groups'      => $this->dc_options,
			)
		);
		$repeater->add_control(
			'ecDisplayIsNot',
			array(
				'type'        => Controls_Manager::SELECT,
				'default'     => 'is',
				'label_block' => true,
				'options'     => array(
					'is'  => esc_html__( 'Is', 'essential-classy-addons-for-elementor' ),
					'not' => esc_html__( 'Not', 'essential-classy-addons-for-elementor' ),
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIslogin_value',
			array(
				'type'        => Controls_Manager::SELECT,
				'default'     => 'logged-in',
				'label_block' => true,
				'options'     => array(
					'logged-in' => esc_html__( 'Logged in', 'essential-classy-addons-for-elementor' ),
				),
				'condition'   => array(
					'ecDisplayKey' => 'login',
				),
			)
		);
		global $wp_roles;
		$repeater->add_control(
			'ecDisplayIsrole_value',
			array(
				'label'       => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::SELECT2,
				'default'     => array(),
				'label_block' => true,
				'options'     => $wp_roles->get_names(),
				'multiple'    => false,
				'condition'   => array(
					'ecDisplayKey' => 'role',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIsbrowser_value',
			array(
				'label'       => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::SELECT2,
				'default'     => 'chrome',
				'label_block' => true,
				'options'     => array(
					'chrome'  => esc_html__( 'Google Chrome', 'essential-classy-addons-for-elementor' ),
					'safari'  => esc_html__( 'Safari', 'essential-classy-addons-for-elementor' ),
					'firefox' => esc_html__( 'Mozilla Firefox', 'essential-classy-addons-for-elementor' ),
					'opera'   => esc_html__( 'Opera', 'essential-classy-addons-for-elementor' ),
					'edge'    => esc_html__( 'Microsoft Edge', 'essential-classy-addons-for-elementor' ),
					'ie'      => esc_html__( 'Internet Explorer', 'essential-classy-addons-for-elementor' ),
				),
				'multiple'    => false,
				'condition'   => array(
					'ecDisplayKey' => 'browser',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIsos_value',
			array(
				'label'       => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::SELECT2,
				'default'     => array( 'windows' ),
				'label_block' => true,
				'options'     => array(
					'windows'    => esc_html__( 'Windows', 'essential-classy-addons-for-elementor' ),
					'mac_os'     => esc_html__( 'Mac OS', 'essential-classy-addons-for-elementor' ),
					'linux'      => esc_html__( 'Linux', 'essential-classy-addons-for-elementor' ),
					'android'    => esc_html__( 'Android', 'essential-classy-addons-for-elementor' ),
					'iphone'     => esc_html__( 'iPhone', 'essential-classy-addons-for-elementor' ),
					'blackberry' => esc_html__( 'BlackBerry', 'essential-classy-addons-for-elementor' ),
					'open_bsd'   => esc_html__( 'OpenBSD', 'essential-classy-addons-for-elementor' ),
					'sun_os'     => esc_html__( 'SunOS', 'essential-classy-addons-for-elementor' ),
					'qnx'        => esc_html__( 'QNX', 'essential-classy-addons-for-elementor' ),
					'beos'       => esc_html__( 'BeOS', 'essential-classy-addons-for-elementor' ),
					'os2'        => esc_html__( 'OS/2', 'essential-classy-addons-for-elementor' ),
				),
				'multiple'    => false,
				'condition'   => array(
					'ecDisplayKey' => 'os',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIsday_value',
			array(
				'label'       => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::SELECT2,
				'default'     => array( 'Sunday' ),
				'label_block' => true,
				'options'     => array(
					'Sunday'    => esc_html__( 'Sunday', 'essential-classy-addons-for-elementor' ),
					'Monday'    => esc_html__( 'Monday', 'essential-classy-addons-for-elementor' ),
					'Tuesday'   => esc_html__( 'Tuesday', 'essential-classy-addons-for-elementor' ),
					'Wednesday' => esc_html__( 'Wednesday', 'essential-classy-addons-for-elementor' ),
					'Thursday'  => esc_html__( 'Thursday', 'essential-classy-addons-for-elementor' ),
					'Friday'    => esc_html__( 'Friday', 'essential-classy-addons-for-elementor' ),
					'Saturday'  => esc_html__( 'Saturday', 'essential-classy-addons-for-elementor' ),
				),
				'multiple'    => false,
				'condition'   => array(
					'ecDisplayKey' => 'day',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIsdate_value',
			array(
				'label'          => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'           => Controls_Manager::DATE_TIME,
				'default'        => gmdate( 'Y/m/d' ),
				'label_block'    => true,
				'picker_options' => array(
					'format'     => 'd-m-Y',
					'enableTime' => false,
				),
				'condition'      => array(
					'ecDisplayKey' => 'date',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIsdaterange_value',
			array(
				'label'          => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'           => Controls_Manager::DATE_TIME,
				'default'        => gmdate( 'Y/m/d' ),
				'label_block'    => true,
				'picker_options' => array(
					'format'     => 'd-m-Y',
					'enableTime' => false,
					'mode'       => 'range',
				),
				'condition'      => array(
					'ecDisplayKey' => 'daterange',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIstimerange_value',
			array(
				'label'          => esc_html__( 'Start', 'essential-classy-addons-for-elementor' ),
				'type'           => Controls_Manager::DATE_TIME,
				'label_block'    => true,
				'picker_options' => array(
					'noCalendar' => true,
					'enableTime' => true,
					'dateFormat' => 'H:i',
				),
				'condition'      => array(
					'ecDisplayKey' => 'timerange',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIstimerange_value2',
			array(
				'label'          => esc_html__( 'End', 'essential-classy-addons-for-elementor' ),
				'type'           => Controls_Manager::DATE_TIME,
				'label_block'    => true,
				'picker_options' => array(
					'noCalendar' => true,
					'enableTime' => true,
					'dateFormat' => 'H:i',
				),
				'condition'      => array(
					'ecDisplayKey' => 'timerange',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIspost_value',
			array(
				'label'       => esc_html__( 'Select', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::SELECT2,
				'default'     => array(),
				'label_block' => true,
				'options'     => $this->ecget_post_lists(),
				'multiple'    => false,
				'condition'   => array(
					'ecDisplayKey' => 'post',
				),
			)
		);
		$repeater->add_control(
			'ecDisplayIspage_value',
			array(
				'label'       => esc_html__( 'Select', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::SELECT2,
				'default'     => array(),
				'label_block' => true,
				'options'     => $this->ecget_page_lists(),
				'multiple'    => false,
				'condition'   => array(
					'ecDisplayKey' => 'page',
				),
			)
		);
		$repeater->add_control(
			'ecDisplayIssitelanguage_value',
			array(
				'placeholder' => esc_html__( 'Language', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::SELECT,
				'multiple'    => false,
				'label_block' => true,
				'options'     => $this->get_lang_opt(),
				'condition'   => array(
					'ecDisplayKey' => 'sitelanguage',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIsstringinurl_value',
			array(
				'label'       => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'label_block' => true,
				'description' => __( 'Enter string', 'essential-classy-addons-for-elementor' ),
				'condition'   => array(
					'ecDisplayKey' => 'stringinurl',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayIsurlparameter_value',
			array(
				'label'       => esc_html__( 'Value', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXTAREA,
				'label_block' => true,
				'description' => __( 'Enter Parameter', 'essential-classy-addons-for-elementor' ),
				'condition'   => array(
					'ecDisplayKey' => 'urlparameter',
				),
			)
		);

		$repeater->add_control(
			'ecDisplayProNotice',
			array(
				'type'            => Controls_Manager::RAW_HTML,
				'raw'             => '<a href="https://ecaddons.com/pricing/"  target="_blank" rel="noopener noreferrer">Pro Feature - Let\'s Unlock</a>',
				'content_classes' => 'ec-pro-feature-note',
				'condition'       => array(
					'ecDisplayKey' => array( 'cartproductcategory', 'cartproducttag', 'cartproduct', 'cartsubtotal', 'carttotal', 'cartitem', 'purchaseordertotal', 'purchasedate', 'firstpurchasedate', 'lastpurchasedate', 'purchaseproductcategory', 'purchaseproducttag', 'purchaseproduct', 'totalorder', 'productcategory', 'producttag', 'productprice', 'productstock', 'lastorderbillingcity', 'lastorderbillingstate', 'lastorderbillingcountry', 'lastorderbillingpostcode', 'lastordershippinggcity', 'lastordershippinggstate', 'lastordershippinggcountry', 'lastordershippinggpostcode', 'acftext', 'acfnumber', 'acfboolean', 'acfselect', 'acfradio', 'acfcheckbox', 'acfbuttongroup', 'acfdate', 'tssingleline', 'tsnumber', 'tsselect', 'tsradio', 'tscheckbox', 'tsdate', 'podsplaintext', 'podsdate', 'podsplainnumber', 'podsboolean', 'jetext', 'jenumber', 'jeselect', 'jecheckbox', 'jeradio', 'jeswitcher', 'jedate', 'cfstext', 'cfsselect', 'cfsboolean', 'cfsdate', 'mbtext', 'mbnumber', 'mbdate', 'mbcheckbox', 'mbradio', 'mbselect', 'firstorderbillingcity', 'firstorderbillingstate', 'firstorderbillingcountry', 'firstorderbillingpostcode', 'firstordershippinggcity', 'firstordershippinggstate', 'firstordershippinggcountry', 'firstordershippinggpostcode', 'cartempty', 'productstockstatus', 'producttype', 'totalpurchasedproduct', 'totalpurchasedproductprice', 'lastorderstatus', 'productsoldindividually', 'weekofthemonth' ),
				),
			)
		);

		$element->add_control(
			'ecDisplayIsRules',
			array(
				'label'       => esc_html__( 'Rules', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::REPEATER,
				'default'     => array(
					array(
						'ecDisplayKey'           => 'login',
						'ecDisplayIsNot'         => 'is',
						'ecDisplayIslogin_value' => 'logged-in',
					),
				),
				'condition'   => array(
					'ecaDcSecSwitch' => 'yes',
				),
				'fields'      => $repeater->get_controls(),
				'title_field' => '{{ecDisplayKey}}',
			)
		);
		$element->end_controls_section();
	}

	protected function EcAddActionRule() {
		$this->ecSetOption();
		add_action( 'elementor/element/section/section_custom_css/after_section_end', array( $this, 'addControls' ), 10, 2 );
		add_action(
			'elementor/widget/render_content',
			function ( $ecWContent, $element ) {
				$settings = $element->get_settings();
				if ( ! empty( $settings['ecaDcSecSwitch'] ) && $settings['ecaDcSecSwitch'] === 'yes' ) {
					$this->ecSetupRule( $element->get_id(), $settings['ecDisplayIsRules'] );
					if ( ! $this->ecDcVIew( $element->get_id(), $settings['ecDisplayWhen'] ) && ! empty( $settings['ecDisplayWhen'] ) ) {
						if ( $settings['ecRenderHtml'] !== 'yes' ) {
							return;
						}
					}
				}
				return $ecWContent;
			},
			10,
			2
		);

		add_action(
			'elementor/frontend/widget/before_render',
			function ( $element ) {
				$settings = $element->get_settings();
				if ( ! empty( $settings['ecaDcSecSwitch'] ) && $settings['ecaDcSecSwitch'] === 'yes' ) {
					$this->ecSetupRule( $element->get_id(), $settings['ecDisplayIsRules'] );
					if ( ! $this->ecDcVIew( $element->get_id(), $settings['ecDisplayWhen'] ) && ! empty( $settings['ecDisplayWhen'] ) ) {
						$element->add_render_attribute( '_wrapper', 'class', 'ec-dc-hide-wrap' );
						$element->add_render_attribute( '_wrapper', 'style', 'display:none' );
					}
				}
			},
			10,
			1
		);

		// sections rules
		add_action( 'elementor/frontend/section/before_render', array( $this, 'ecSectionBottom' ), 10, 1 );
		add_action( 'elementor/frontend/section/after_render', array( $this, 'ecSectionTop' ), 10, 1 );

		$experiments_manager = Plugin::$instance->experiments;
		if ( $experiments_manager->is_feature_active( 'container' ) ) {
			add_action( 'elementor/frontend/container/before_render', array( $this, 'ecSectionBottom' ), 10, 1 );
			add_action( 'elementor/frontend/container/after_render', array( $this, 'ecSectionTop' ), 10, 1 );
		}
	}
	public function ecSectionBottom( $element ) {
		$settings = $element->get_settings();
		if ( ! empty( $settings['ecaDcSecSwitch'] ) && $settings['ecaDcSecSwitch'] === 'yes' ) {
			$this->ecSetupRule( $element->get_id(), $settings['ecDisplayIsRules'] );
			if ( ! $this->ecDcVIew( $element->get_id(), $settings['ecDisplayWhen'] ) && ! empty( $settings['ecDisplayWhen'] ) ) {
				if ( $settings['ecRenderHtml'] !== 'yes' ) {
					echo '<!--Hidden with Essential Classy Addons For Elementor Display Condition-->';
					ob_start();
				} else {
					$element->add_render_attribute( '_wrapper', 'class', 'ec-dc-hide-wrap' );
					$element->add_render_attribute( '_wrapper', 'style', 'display:none' );
				}
			}
		}
	}

	public function ecSectionTop( $element ) {
		$settings = $element->get_settings();
		if ( ! empty( $settings['ecaDcSecSwitch'] ) && $settings['ecaDcSecSwitch'] === 'yes' ) {
			$this->ecSetupRule( $element->get_id(), $settings['ecDisplayIsRules'] );
			if ( ! $this->ecDcVIew( $element->get_id(), $settings['ecDisplayWhen'] ) && ! empty( $settings['ecDisplayWhen'] ) ) {
				if ( $settings['ecRenderHtml'] !== 'yes' ) {
					ob_get_clean();
				} else {
					$element->add_render_attribute( '_wrapper', 'class', 'ec-dc-hide-wrap' );
					$element->add_render_attribute( '_wrapper', 'style', 'display:none' );
				}
			}
		}
	}

	protected function ecSetupRule( $id, $rules = array() ) {
		if ( ! $rules ) {
			return;
		}

		foreach ( $rules as $index => $rule ) {
			$key    = $rule['ecDisplayKey'];
			$keyGet = null;
			if ( array_key_exists( 'ecDisplayIs' . $key . 'Get', $rule ) ) {
				$keyGet = $rule[ 'ecDisplayIs' . $key . 'Get' ];
			}
			$ecDisplayIsNot = $rule['ecDisplayIsNot'];

			if ( ( $key == 'cartproductcategory' ) || ( $key == 'cartitem' ) || ( $key == 'cartproducttag' ) || ( $key == 'cartsubtotal' ) || ( $key == 'cartproduct' ) || ( $key == 'carttotal' ) || ( $key == 'purchaseordertotal' ) || ( $key == 'purchasedate' ) || ( $key == 'firstpurchasedate' ) || ( $key == 'lastpurchasedate' ) || ( $key == 'purchaseproductcategory' ) || ( $key == 'purchaseproducttag' ) || ( $key == 'purchaseproduct' ) || ( $key == 'totalorder' ) || ( $key == 'productcategory' ) || ( $key == 'producttag' ) || ( $key == 'productprice' ) || ( $key == 'productstock' ) || ( $key == 'lastorderbillingcity' ) || ( $key == 'lastorderbillingstate' ) || ( $key == 'lastorderbillingcountry' ) || ( $key == 'lastorderbillingpostcode' ) || ( $key == 'lastordershippinggcity' ) || ( $key == 'lastordershippinggstate' ) || ( $key == 'lastordershippinggcountry' ) || ( $key == 'lastordershippinggpostcode' ) || ( $key == 'acftext' ) || ( $key == 'acfnumber' ) || ( $key == 'acfboolean' ) || ( $key == 'acfselect' ) || ( $key == 'acfradio' ) || ( $key == 'acfcheckbox' ) || ( $key == 'acfbuttongroup' ) || ( $key == 'acfdate' ) || ( $key == 'mbtext' ) || ( $key == 'mbnumber' ) || ( $key == 'mbselect' ) || ( $key == 'mbcheckbox' ) || ( $key == 'mbradio' ) || ( $key == 'mbdate' ) || ( $key == 'tssingleline' ) || ( $key == 'tsnumber' ) || ( $key == 'tsselect' ) || ( $key == 'tsradio' ) || ( $key == 'tscheckbox' ) || ( $key == 'tsdate' ) || ( $key == 'podsplaintext' ) || ( $key == 'podsdate' ) || ( $key == 'podsplainnumber' ) || ( $key == 'podsboolean' ) || ( $key == 'jetext' ) || ( $key == 'jenumber' ) || ( $key == 'jeselect' ) || ( $key == 'jecheckbox' ) || ( $key == 'jeradio' ) || ( $key == 'jeswitcher' ) || ( $key == 'jedate' ) || ( $key == 'cfstext' ) || ( $key == 'cfsselect' ) || ( $key == 'cfsboolean' ) || ( $key == 'cfsdate' ) || ( $key == 'firstorderbillingcity' ) || ( $key == 'firstorderbillingstate' ) || ( $key == 'firstorderbillingcountry' ) || ( $key == 'firstorderbillingpostcode' ) || ( $key == 'firstordershippinggcity' ) || ( $key == 'firstordershippinggstate' ) || ( $key == 'firstordershippinggcountry' ) || ( $key == 'firstordershippinggpostcode' ) || ( $key == 'cartempty' ) || ( $key == 'productstockstatus' ) || ( $key == 'producttype' ) || ( $key == 'totalpurchasedproduct' ) || ( $key == 'totalpurchasedproductprice' ) || ( $key == 'lastorderstatus' ) || ( $key == 'productsoldindividually' ) || ( $key == 'weekofthemonth' ) ) {
				$value = '';
			} else {
				$value = $rule[ 'ecDisplayIs' . $key . '_value' ];
			}

			$exvalue2 = ! empty( $rule['ecDisplayIstimerange_value2'] ) ? $rule['ecDisplayIstimerange_value2'] : '';

			if ( method_exists( $this, 'ecDisplayChecking_' . $key ) ) {
				$checking = call_user_func( array( $this, 'ecDisplayChecking_' . $key ), $value, $ecDisplayIsNot, $keyGet, $exvalue2 );
				$this->ecDcCondition[ $id ][ $key . '_' . esc_attr( $rule['_id'] ) ] = $checking;
			}
		}
	}

	protected function ecDcVIew( $id, $relation ) {
		if ( ! array_key_exists( $id, $this->ecDcCondition ) ) {
			return;
		}

		if ( ! \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
			if ( $relation === 'any' ) {
				if ( ! in_array( true, $this->ecDcCondition[ $id ] ) ) {
					return false;
				}
			} elseif ( in_array( false, $this->ecDcCondition[ $id ] ) ) {
					return false;
			}
		}
		return true;
	}

	protected static function ecDCCompare( $valueOne, $valueTwo, $ecDisplayIsNot ) {
		if ( $ecDisplayIsNot == 'is' ) {
			return $valueOne == $valueTwo;
		} elseif ( $ecDisplayIsNot == 'not' ) {
			return $valueOne != $valueTwo;
		} else {
			return $valueOne === $valueTwo;
		}
	}

	protected static function ecDisplayChecking_login( $value, $ecDisplayIsNot, $key ) {
		return self::ecDCCompare( is_user_logged_in(), true, $ecDisplayIsNot );
	}
	protected static function ecDisplayChecking_role( $value, $ecDisplayIsNot, $key ) {
		if ( empty( $value ) ) {
			return false;
		}
		$value  = ! is_array( $value ) ? (array) $value : $value;
		$user   = wp_get_current_user();
		$result = ( ! empty( $value ) && ! empty( $user->roles ) && array_intersect( $value, (array) $user->roles ) ) ? true : false;
		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_browser( $value, $ecDisplayIsNot, $key ) {
		$result    = '';
		$userAgent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
		if ( strpos( $userAgent, 'Chrome' ) ) {
			$result = 'chrome';
		} elseif ( strpos( $userAgent, 'Safari' ) ) {
			$result = 'safari';
		} elseif ( strpos( $userAgent, 'Firefox' ) ) {
			$result = 'firefox';
		} elseif ( strpos( $userAgent, 'Opera' ) || strpos( $userAgent, 'OPR/' ) ) {
			$result = 'opera';
		} elseif ( strpos( $userAgent, 'Edg' ) || strpos( $userAgent, 'Edge' ) ) {
			$result = 'edge';
		} elseif ( strpos( $userAgent, 'MSIE' ) || strpos( $userAgent, 'Trident/7' ) ) {
			$result = 'ie';
		}
		$result = is_array( $value ) && ! empty( $value ) ? in_array( $result, $value, true ) : $value === $result;
		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_os( $value, $ecDisplayIsNot, $key ) {
		$userAgent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
		$osList    = array(
			'windows'    => '(Win16)|(Windows 95)|(Win95)|(Windows_95)|(Windows 98)|(Win98)|(Windows NT 5.0)|(Windows 2000)|(Windows NT 5.1)|(Windows XP)|(Windows NT 5.2)|(Windows NT 6.0)|(Windows Vista)|(Windows NT 6.1)|(Windows 7)|(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)|(Windows ME)',
			'mac_os'     => '(Mac_PowerPC)|(Macintosh)|(mac os x)',
			'linux'      => '(Linux)|(X11)',
			'android'    => '(Android)',
			'iphone'     => 'iPhone',
			'blackberry' => 'BlackBerry',
			'open_bsd'   => 'OpenBSD',
			'sun_os'     => 'SunOS',
			'qnx'        => 'QNX',
			'beos'       => 'BeOS',
		);

		$currentOs = array();
		foreach ( $osList as $key => $key_val ) {
			$preg_match = preg_match( '/' . $key_val . '/i', $userAgent );
			if ( $preg_match ) {
				array_push( $currentOs, $key );

				if ( $key === 'iphone' ) {
					array_shift( $currentOs );
				} elseif ( $key === 'android' ) {
					array_shift( $currentOs );
				}
			}
		}

		$result = ( ! empty( $value ) && ! empty( $currentOs ) && in_array( $value, $currentOs ) ) ? true : false;
		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_day( $value, $ecDisplayIsNot, $key ) {
		$result = false;
		if ( ! empty( $value ) ) {
			if ( $value === date( 'l' ) ) {
				$result = true;
			}
		} else {
			$result = $value === date( 'w' );
		}

		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_date( $value, $ecDisplayIsNot, $key ) {
		$result = false;
		$value  = strtotime( $value );
		$today  = strtotime( date( 'Y-m-d' ) );
		$result = ! empty( $value ) && $today === $value ? true : false;

		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_daterange( $value, $ecDisplayIsNot, $key ) {
		$result = false;
		$range  = explode( 'to', $value );

		if ( ! is_array( $range ) || count( $range ) !== 2 ) {
			return;
		}

		$start = strtotime( $range[0] );
		$end   = strtotime( $range[1] );

		$today  = strtotime( date( 'Y-m-d' ) );
		$result = ( ( $today >= $start ) && ( $today <= $end ) );
		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_timerange( $value, $ecDisplayIsNot, $key, $exvalue2 ) {
		$result = false;
		$time1  = date( 'H:i', strtotime( preg_replace( '/\s+/', '', $value ) ) );
		$time2  = date( 'H:i', strtotime( preg_replace( '/\s+/', '', $exvalue2 ) ) );
		$now    = date( 'H:i', strtotime( 'now' ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );

		if ( \DateTime::createFromFormat( 'H:i', $time1 ) === false && \DateTime::createFromFormat( 'H:i', $time2 ) === false ) {
			return;
		}

		$t1  = strtotime( $time1 );
		$t2  = strtotime( $time2 );
		$cur = strtotime( $now );

		if ( $cur > $t1 && $cur < $t2 ) {
			$result = true;
		}

		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_post( $value, $ecDisplayIsNot, $key ) {
		$result   = false;
		$getValue = get_queried_object_id();
		if ( ! empty( $getValue ) && ! empty( $value ) && ( $getValue == (int) $value ) ) {
			$result = true;
		}
		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}
	protected static function ecDisplayChecking_page( $value, $ecDisplayIsNot, $key ) {
		$result   = false;
		$getValue = get_queried_object_id();
		if ( ! empty( $getValue ) && ! empty( $value ) && ( $getValue == (int) $value ) ) {
			$result = true;
		}
		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}
	protected static function ecDisplayChecking_sitelanguage( $value, $ecDisplayIsNot, $key ) {
		$result     = false;
		$get_locale = function_exists( 'get_locale' ) ? get_locale() : false;
		if ( ! $get_locale || empty( $value ) ) {
			return;
		}

		if ( $get_locale === $value ) {
			$result = true;
		}

		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}
	protected static function ecDisplayChecking_stringinurl( $value, $ecDisplayIsNot, $key ) {
		if ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) {
			return;
		}
		$REQUEST_URI = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
		if ( ! $REQUEST_URI ) {
			return false;
		}
		$result = false !== ( ! empty( $value ) && strpos( $REQUEST_URI, $value ) ) ? true : false;

		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	protected static function ecDisplayChecking_urlparameter( $value, $ecDisplayIsNot, $key ) {
		if ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) {
			return;
		}
		$REQUEST_URI = wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );

		if ( ! $REQUEST_URI || ! isset( $REQUEST_URI['query'] ) || empty( $REQUEST_URI['query'] ) ) {
			return false;
		}

		$rQuery = explode( '&', $REQUEST_URI['query'] );

		$value = explode( "\n", sanitize_textarea_field( $value ) );

		foreach ( $value as $ind => $parameter ) {
			$eq = strpos( $parameter, '=' );
			if ( ! $eq ) {
				$gp = isset( $_GET[ $parameter ] ) ? sanitize_text_field( wp_unslash( $_GET[ $parameter ] ) ) : '';

				$value[ $ind ] = $value[ $ind ] . '=' . rawurlencode( $gp );
			}
		}

		$result = ! empty( array_intersect( $value, $rQuery ) ) ? true : false;
		return self::ecDCCompare( $result, true, $ecDisplayIsNot );
	}

	public function get_lang_opt() {
		return array(
			'af'             => 'Afrikaans',
			'en_US'          => 'English',
			'hi_IN'          => 'Hindi',
			'am'             => 'አማርኛ',
			'ar'             => 'العربية',
			'ary'            => 'العربية المغربية',
			'as'             => 'অসমীয়া',
			'az'             => 'Azərbaycan dili',
			'azb'            => 'گؤنئی آذربایجان',
			'bel'            => 'Беларуская мова',
			'bg_BG'          => 'Български',
			'bn_BD'          => 'বাংলা',
			'bo'             => '>བོད་ཡིག</',
			'bs_BA'          => 'Bosanski',
			'ca'             => 'Català',
			'ceb'            => 'Cebuano',
			'cs_CZ'          => 'Čeština',
			'cy'             => 'Cymraeg',
			'da_DK'          => 'Dansk',
			'de_CH_informal' => 'Deutsch (Schweiz, Du)',
			'de_DE'          => 'Deutsch',
			'de_DE_formal'   => 'Deutsch (Sie)',
			'de_CH'          => 'Deutsch (Schweiz)',
			'de_AT'          => 'Deutsch (Österreich)',
			'dsb'            => 'Dolnoserbšćina',
			'dzo'            => 'རྫོང་ཁ',
			'el'             => 'Ελληνικά',
			'en_ZA'          => 'English (South Africa)',
			'en_CA'          => 'English (Canada)',
			'en_NZ'          => 'English (New Zealand)',
			'en_GB'          => 'English (UK)',
			'en_AU'          => 'English (Australia)',
			'eo'             => 'Esperanto',
			'es_ES'          => 'Español',
			'es_AR'          => 'Español de Argentina',
			'es_CO'          => 'Español de Colombia',
			'es_MX'          => 'Español de México',
			'es_DO'          => 'Español de República Dominicana',
			'es_CR'          => 'Español de Costa Rica',
			'es_PE'          => 'Español de Perú',
			'es_UY'          => 'Español de Uruguay',
			'es_CL'          => 'Español de Chile',
			'es_PR'          => 'Español de Puerto Rico',
			'es_GT'          => 'Español de Guatemala',
			'es_EC'          => 'Español de Ecuador',
			'es_VE'          => 'Español de Venezuela',
			'et'             => 'Eesti',
			'eu'             => 'Euskara',
			'fa_IR'          => 'فارسی',
			'fa_AF'          => '(فارسی (افغانستان',
			'fi'             => 'Suomi',
			'fr_FR'          => 'Français',
			'fr_CA'          => 'Français du Canada',
			'fr_BE'          => 'Français de Belgique',
			'fur'            => 'Friulian',
			'gd'             => 'Gàidhlig',
			'gl_ES'          => 'Galego',
			'gu'             => 'ગુજરાતી',
			'haz'            => 'هزاره گی',
			'he_IL'          => 'בְרִית',
			'hr'             => 'Hrvatski',
			'hsb'            => 'Hornjoserbšćina',
			'hu_HU'          => 'Magyar',
			'hy'             => 'Հայերեն',
			'id_ID'          => 'Bahasa Indonesia',
			'is_IS'          => 'Íslenska',
			'it_IT'          => 'Italiano',
			'ja'             => '日本語',
			'jv_ID'          => 'Basa Jawa',
			'ka_GE'          => 'ქართული',
			'kab'            => 'Taqbaylit',
			'kk'             => 'Қазақ тілі',
			'km'             => 'ភាសាខ្មែរ',
			'kn'             => 'ಕನ್ನಡ',
			'ko_KR'          => '한국어',
			'ckb'            => 'كوردی&lrm;',
			'lo'             => 'ພາສາລາວ',
			'lt_LT'          => 'Lietuvių kalba',
			'lv'             => 'Latviešu valoda',
			'mk_MK'          => 'Македонски јазик',
			'ml_IN'          => 'മലയാളം',
			'mn'             => 'Монгол',
			'mr'             => 'मराठी',
			'ms_MY'          => 'Bahasa Melayu',
			'my_MM'          => 'ဗမာစာ',
			'nb_NO'          => 'Norsk bokmål',
			'ne_NP'          => 'नेपाली',
			'nl_NL'          => 'Nederlands',
			'nl_BE'          => 'Nederlands (België)',
			'nl_NL_formal'   => 'Nederlands (Formeel)',
			'nn_NO'          => 'Norsk nynorsk',
			'oci'            => 'Occitan',
			'pa_IN'          => 'ਪੰਜਾਬੀ',
			'pl_PL'          => 'Polski',
			'ps'             => 'پښتو',
			'pt_PT'          => 'Português',
			'pt_PT_ao90'     => 'Português (AO90)',
			'pt_AO'          => 'Português de Angola',
			'pt_BR'          => 'Português do Brasil',
			'rhg'            => 'Ruáinga',
			'ro_RO'          => 'Română',
			'ru_RU'          => 'Русский',
			'sah'            => 'Сахалыы',
			'snd'            => 'سنڌي',
			'si_LK'          => 'සිංහල',
			'sk_SK'          => 'Slovenčina',
			'skr'            => 'سرائیکی',
			'sl_SI'          => 'Slovenščina',
			'sq'             => 'Shqip',
			'sr_RS'          => 'Српски језик',
			'sv_SE'          => 'Svenska',
			'sw'             => 'Kiswahili',
			'szl'            => 'Ślōnskŏ gŏdka',
			'ta_IN'          => 'தமிழ்',
			'ta_LK'          => 'தமிழ்',
			'te'             => 'తెలుగు',
			'th'             => 'ไทย',
			'tl'             => 'Tagalog',
			'tr_TR'          => 'Türkçe',
			'tt_RU'          => 'Татар теле',
			'tah'            => 'Reo Tahiti',
			'ug_CN'          => 'ئۇيغۇرچە',
			'uk'             => 'Українська',
			'ur'             => 'اردو',
			'uz_UZ'          => 'O‘zbekcha',
			'vi'             => 'Tiếng Việt',
			'zh_HK'          => '香港中文版',
			'zh_TW'          => '繁體中文',
			'zh_CN'          => '简体中文',
		);
	}

	public function ecget_post_lists() {
		$postList = array();
		$args     = array(
			'post_type'      => 'post',
			'post_status'    => 'publish',
			'posts_per_page' => -1,
			'fields'         => 'ids',
		);
		$postIds  = get_posts( $args );

		foreach ( $postIds as $postId ) {
			$post = get_post( $postId );

			if ( $post ) {
				$postList[ $post->ID ] = $post->post_title;
			}
		}

		return $postList;
	}

	public function ecget_page_lists() {
		$pageList = array();
		$args     = array(
			'post_type'      => 'page',
			'post_status'    => 'publish',
			'posts_per_page' => -1,
			'fields'         => 'ids',
		);
		$pageIds  = get_posts( $args );

		foreach ( $pageIds as $pageId ) {
			$page = get_post( $pageId );

			if ( $page ) {
				$pageList[ $page->ID ] = $page->post_title;
			}
		}

		return $pageList;
	}
}
