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

if ( ! function_exists( 'qode_badges_for_woocommerce_add_badge_image_meta_box' ) ) {
	function qode_badges_for_woocommerce_add_badge_image_meta_box( $page ) {
		if ( $page ) {

			$default_type = apply_filters( 'qode_badges_for_woocommerce_filter_default_badge_type', '' );

			$image_section = $page->add_section_element(
				array(
					'name'       => 'qode_badges_for_woocommerce_image_type_section',
					'title'      => esc_html__( 'Image Settings', 'qode-badges-for-woocommerce' ),
					'dependency' => array(
						'show' => array(
							'qode_badges_for_woocommerce_badge_type' => array(
								'values'        => 'image',
								'default_value' => $default_type,
							),
						),
					),
				)
			);

			$image_section->add_field_element(
				array(
					'field_type'    => 'select',
					'name'          => 'qode_badges_for_woocommerce_image_type',
					'title'         => esc_html__( 'Image Type', 'qode-badges-for-woocommerce' ),
					'options'       => array(
						'predefined_image' => esc_html__( 'Predefined Image', 'qode-badges-for-woocommerce' ),
						'custom_image'     => esc_html__( 'Custom Image', 'qode-badges-for-woocommerce' ),
					),
					'default_value' => 'predefined_image',
				)
			);

			$image_section->add_field_element(
				array(
					'field_type' => 'image',
					'name'       => 'qode_badges_for_woocommerce_image',
					'title'      => esc_html__( 'Image', 'qode-badges-for-woocommerce' ),
					'dependency' => array(
						'show' => array(
							'qode_badges_for_woocommerce_image_type' => array(
								'values'        => 'custom_image',
								'default_value' => 'custom_image',
							),
						),
					),
				)
			);

			$image_section->add_field_element(
				array(
					'field_type'    => 'radio',
					'name'          => 'qode_badges_for_woocommerce_badge_image_predefined',
					'title'         => esc_html__( 'Choose Image', 'qode-badges-for-woocommerce' ),
					'options'       => qode_badges_for_woocommerce_predefined_images(),
					'default_value' => qode_badges_for_woocommerce_default_value( 'predefined_image' ),
					'args'          => array(
						'images' => true,
					),
					'data_attrs'    => array(
						'data-exclude' => 'yes',
					),
					'dependency'    => array(
						'show' => array(
							'qode_badges_for_woocommerce_image_type' => array(
								'values'        => 'predefined_image',
								'default_value' => 'custom_image',
							),
						),
					),
				)
			);
		}
	}

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