<?php
if ( ! defined( 'ABSPATH' ) ) {
	// Exit if accessed directly.
	exit;
}

if ( ! function_exists( 'qode_badges_for_woocommerce_add_badge_textual_meta_box' ) ) {
	function qode_badges_for_woocommerce_add_badge_textual_meta_box( $page ) {
		if ( $page ) {
			$default_type = apply_filters( 'qode_badges_for_woocommerce_filter_default_badge_type', '' );

			$text_options_types = apply_filters(
				'qode_badge_for_woocommmerce_filter_text_options_type',
				array( 'textual' )
			);

			$textual_section = $page->add_section_element(
				array(
					'name'       => 'qode_badges_for_woocommerce_textual_type_section',
					'title'      => esc_html__( 'Textual Settings', 'qode-badges-for-woocommerce' ),
					'dependency' => array(
						'show' => array(
							'qode_badges_for_woocommerce_badge_type' => array(
								'values'        => $text_options_types,
								'default_value' => $default_type,
							),
						),
					),
				)
			);

			$textual_row = $textual_section->add_row_element(
				array(
					'name' => 'qode_badges_for_woocommerce_textual_row',
				)
			);

			$textual_row->add_field_element(
				array(
					'field_type' => 'textareaeditor',
					'name'       => 'qode_badges_for_woocommerce_text',
					'title'      => esc_html__( 'Text', 'qode-badges-for-woocommerce' ),
				)
			);

			$textual_row->add_field_element(
				array(
					'field_type'    => 'color',
					'name'          => 'qode_badges_for_woocommerce_badge_text_color',
					'title'         => esc_html__( 'Text Color', 'qode-badges-for-woocommerce' ),
					'default_value' => '#000',
					'args'          => array(
						'col_width' => 6,
					),
					'data_attrs'    => array(
						'data-property' => 'color',
					),
				)
			);
			$textual_row->add_field_element(
				array(
					'field_type'    => 'select',
					'name'          => 'qode_badges_for_woocommerce_badge_text_alignment',
					'title'         => esc_html__( 'Text Alignment', 'qode-badges-for-woocommerce' ),
					'options'       => array(
						'var(--qbfw-alignment)' => esc_html__( 'Default', 'qode-badges-for-woocommerce' ),
						'left'                  => esc_html__( 'Left', 'qode-badges-for-woocommerce' ),
						'center'                => esc_html__( 'Center', 'qode-badges-for-woocommerce' ),
						'right'                 => esc_html__( 'Right', 'qode-badges-for-woocommerce' ),
					),
					'default_value' => '',
					'args'          => array(
						'col_width' => 6,
					),
					'data_attrs'    => array(
						'data-property' => '--qbfw-text-align',
					),
				)
			);

			do_action( 'qode_badges_for_woocommerce_action_textual_badge_after_options', $textual_row, $textual_section, $default_type );
		}
	}

	add_action( 'qode_badges_for_woocommerce_action_after_badge_type_meta_box_map', 'qode_badges_for_woocommerce_add_badge_textual_meta_box' );
}

if ( ! function_exists( 'qode_badges_for_woocommerce_text_field_add_wp_kses_html_fields' ) ) {
	function qode_badges_for_woocommerce_text_field_add_wp_kses_html_fields( $fields ) {
		$fields[] = 'qode_badges_for_woocommerce_text';

		return $fields;
	}

	add_filter( 'qode_badges_for_woocommerce_filter_framework_wp_kses_html_fields', 'qode_badges_for_woocommerce_text_field_add_wp_kses_html_fields' );
}
