<div id="product_tabs" class="panel woocommerce_options_panel">

	<?php
	$post_id  = get_the_ID();
	$cat_list = wp_get_post_terms( $post_id, 'product_cat', [ 'fields' => 'ids' ] );
	$tag_list = wp_get_post_terms( $post_id, 'product_tag', [ 'fields' => 'ids' ] );

	$required_tabs = $this->product_tabs_list;


	// Check for All flag;
	if ( ! empty( $required_tabs ) && is_array( $required_tabs ) ) {
		foreach ( $required_tabs as $k => $t ) {
			if ( isset( $t->post_meta['_wpt_option_use_default_for_all'] ) ) {
				if ( 'yes' == array_shift( $t->post_meta['_wpt_option_use_default_for_all'] ) ) {
					unset( $required_tabs[ $k ] );
				}
			}
		}
	}

	if ( ! empty( $required_tabs ) ) {
		echo '<div class="tab-content-wrap">';
		foreach ( $required_tabs as $key => $tab ) {

			if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
				$lang     = ICL_LANGUAGE_CODE;
				$tab_lang = wpml_get_language_information( '', $tab->ID );
			}

			$icon                     = get_post_meta( $tab->ID, '_wpt_tab_icon', true );
			$tab->_wpt_conditions_tag = wp_get_post_terms( $tab->ID, 'product_tag', [ 'fields' => 'ids' ] );

			$show = true;
			if ( empty( $tab->_wpt_conditions_category ) && empty( $tab->_wpt_conditions_tag ) && empty( $tab->_wpt_conditions_product ) ) {
				$show = true;
			} else {

				if ( ! empty( $tab->_wpt_conditions_category ) && is_array( $tab->_wpt_conditions_category ) && array_intersect( $cat_list, $tab->_wpt_conditions_category ) ) {
					$show = true;
				} elseif ( ! empty( $tab->_wpt_conditions_tag ) && is_array( $tab->_wpt_conditions_tag ) && array_intersect( $tag_list, $tab->_wpt_conditions_tag ) ) {
					$show = true;
				} elseif ( ! empty( $tab->_wpt_conditions_product ) && is_array( $tab->_wpt_conditions_product ) && in_array( $post_id, $tab->_wpt_conditions_product ) ) {
					$show = true;
				} else {
					$show = false;
				}
			}
			if ( $show == false ) {
				unset( $tab );
			} elseif ( defined( 'ICL_SITEPRESS_VERSION' ) && $lang !== $tab_lang['language_code'] ) {
					unset( $tab );
			} else {

				echo '<h3 class="wpt_accordion"><strong><i class="' . esc_attr( $icon ) . '"></i> ' . esc_html( $tab->post_title ) . '</strong></h3>';
				$tab_value = get_post_meta( $post_id, '_wpt_field_' . $tab->post_name, true );

				if ( empty( $tab_value ) ) {
					$tab_value = $tab->post_content;
				}

				$settings = [
					'textarea_name' => '_wpt_field_' . $tab->post_name,
					'editor_height' => '150px',
				];
				wp_editor( $tab_value, '_wpt_field_' . esc_attr( $tab->post_name ), $settings );
				echo '<br />';
			}
		}
		echo '</div>';

	}
		?>

	<input type="hidden" name="count" value="0" id="count">
	<?php wp_nonce_field( 'wpt_product_data', '_wpt_product_data_nonce' ); ?>
	<div class="tabs-layout hidden">
		<?php
		woocommerce_wp_text_input(
			[
				'label'       => '',
				'id'          => 'hidden_duplicate_title',
				'placeholder' => 'Title',
				'class'       => 'tab_title_field'
			]
		);

		woocommerce_wp_textarea_input(
			[
				'label'       => '',
				'id'    => 'hidden_duplicate_content',
				'class' => 'tabs_content_field'
			]
		);

		echo sprintf(
			'%s%s%s',
			'<p><a href="#" class="icon-div hidden">',
			__( 'Add Icon', 'woocommerce-product-tabs' ),
			'</a></p>'
		);

		echo sprintf(
			'%s%s%s',
			'<p class="remove-tabs"><a href="#" class="remove_product_tab hidden">',
			__( 'Remove', 'woocommerce-product-tabs' ),
			'</a></p>'
		);
		?>
	</div>

	<button class="button button-secondary add-new-tab">
		<?php esc_html_e( 'Add New Tab', 'woocommerce-product-tabs' ); ?>
	</button>

	<?php require 'icons.php'; ?>

</div>
