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

if ( ! function_exists( 'qode_badges_for_woocommerce_add_product_meta_box' ) ) {
	/**
	 * Function that add general options for this module
	 */
	function qode_badges_for_woocommerce_add_product_meta_box() {
		$qode_badges_for_woocommerce_framework = qode_badges_for_woocommerce_framework_get_framework_root();

		$page = $qode_badges_for_woocommerce_framework->add_options_page(
			array(
				'scope' => array( 'product' ),
				'type'  => 'meta',
				'slug'  => 'badges-product',
				'title' => esc_html__( 'Product', 'qode-badges-for-woocommerce' ),
			)
		);

		if ( $page ) {

			/* Badge section */

			// Hook to include additional options after module options.
			do_action( 'qode_badges_for_woocommerce_action_before_product_meta_box_map', $page );

			$badge_options = qode_badges_for_woocommerce_get_cpt_items( array(), true );

			$page->add_field_element(
				array(
					'field_type'    => 'select',
					'name'          => 'qode_badges_for_woocommerce_badge',
					'title'         => esc_html__( 'Select Badge', 'qode-badges-for-woocommerce' ),
					'options'       => $badge_options,
					'default_value' => 'textual',
				)
			);

			$schedule_section = $page->add_section_element(
				array(
					'name'  => 'qode_badges_for_woocommerce_schedule_section',
					'title' => esc_html__( 'Schedule', 'qode-badges-for-woocommerce' ),
				)
			);

			$schedule_row = $schedule_section->add_row_element(
				array(
					'name' => 'qode_badges_for_woocommerce_schedule_row',
				)
			);

			$schedule_row->add_field_element(
				array(
					'field_type'    => 'yesno',
					'name'          => 'qode_badges_for_woocommerce_schedule_badge',
					'title'         => esc_html__( 'Schedule Badge', 'qode-badges-for-woocommerce' ),
					'default_value' => 'no',
					'args'          => array(
						'col_width' => 4,
					),
				)
			);
			$schedule_row->add_field_element(
				array(
					'field_type' => 'date',
					'name'       => 'qode_badges_for_woocommerce_schedule_badge_start_date',
					'title'      => esc_html__( 'Start Date', 'qode-badges-for-woocommerce' ),
					'dependency' => array(
						'show' => array(
							'qode_badges_for_woocommerce_schedule_badge' => array(
								'values'        => 'yes',
								'default_value' => 'no',
							),
						),
					),
					'args'       => array(
						'col_width' => 4,
					),
				)
			);
			$schedule_row->add_field_element(
				array(
					'field_type' => 'date',
					'name'       => 'qode_badges_for_woocommerce_schedule_badge_end_date',
					'title'      => esc_html__( 'End Date', 'qode-badges-for-woocommerce' ),
					'dependency' => array(
						'show' => array(
							'qode_badges_for_woocommerce_schedule_badge' => array(
								'values'        => 'yes',
								'default_value' => 'no',
							),
						),
					),
					'args'       => array(
						'col_width' => 4,
					),
				)
			);

			// Hook to include additional options after module options.
			do_action( 'qode_badges_for_woocommerce_action_after_product_meta_box_map', $page );
		}
	}

	add_action( 'qode_badges_for_woocommerce_action_default_meta_boxes_init', 'qode_badges_for_woocommerce_add_product_meta_box' );
}
