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

if ( ! function_exists( 'qode_badges_for_woocommerce_register_badge_for_meta_options' ) ) {
	/**
	 * Function that add custom post type into global meta box allowed items array for saving meta box options
	 *
	 * @param array $post_types
	 *
	 * @return array
	 */
	function qode_badges_for_woocommerce_register_badge_for_meta_options( $post_types ) {
		$post_types[] = 'qbfw_badge';
		$post_types[] = 'product';

		return $post_types;
	}

	add_filter( 'qode_badges_for_woocommerce_filter_framework_meta_box_save', 'qode_badges_for_woocommerce_register_badge_for_meta_options' );
	add_filter( 'qode_badges_for_woocommerce_filter_framework_meta_box_remove', 'qode_badges_for_woocommerce_register_badge_for_meta_options' );
}

if ( ! function_exists( 'qode_badges_for_woocommerce_register_badge_for_framework_header' ) ) {
	/**
	 * Function that add custom post type into global framework header array
	 *
	 * @param array $post_types
	 *
	 * @return array
	 */
	function qode_badges_for_woocommerce_register_badge_for_framework_header( $post_types ) {
		$post_types[] = 'qbfw_badge';

		return $post_types;
	}

	add_filter( 'qode_badges_for_woocommerce_filter_framework_nav_cpts', 'qode_badges_for_woocommerce_register_badge_for_framework_header' );
}
if ( ! function_exists( 'qode_badges_for_woocommerce_add_badge_custom_post_type_for_admin_pages' ) ) {
	/**
	 * Function that adds gift_cards custom post type
	 *
	 * @param array $cpts
	 *
	 * @return array
	 */
	function qode_badges_for_woocommerce_add_badge_custom_post_type_for_admin_pages( $cpts ) {
		$cpts['qbfw_badge'] = esc_html__( 'All Badges', 'qode-badges-for-woocommerce' );

		return $cpts;
	}

	add_filter( 'qode_badges_for_woocommerce_filter_admin_pages_cpt', 'qode_badges_for_woocommerce_add_badge_custom_post_type_for_admin_pages' );
}

if ( ! function_exists( 'qode_badges_for_woocommerce_add_badge_custom_post_type' ) ) {
	/**
	 * Function that adds gift_cards custom post type
	 *
	 * @param array $cpts
	 *
	 * @return array
	 */
	function qode_badges_for_woocommerce_add_badge_custom_post_type( $cpts ) {
		$cpts[] = 'Qode_Badges_For_WooCommerce_Badge_CPT';

		return $cpts;
	}

	add_filter( 'qode_badges_for_woocommerce_filter_register_custom_post_types', 'qode_badges_for_woocommerce_add_badge_custom_post_type' );
}

if ( class_exists( 'Qode_Badges_For_WooCommerce_Framework_Custom_Post_Type' ) ) {
	class Qode_Badges_For_WooCommerce_Badge_CPT extends Qode_Badges_For_WooCommerce_Framework_Custom_Post_Type {

		public function map_post_type() {
			$name = esc_html__( 'Badge', 'qode-badges-for-woocommerce' );
			$this->set_base( 'qbfw_badge' );
			$this->set_public( false );
			$this->set_show_ui( true );
			$this->set_show_in_menu( false );
			$this->set_menu_icon( 'dashicons-tickets-alt' );
			$this->set_slug( 'qbfw_badge' );
			$this->set_name( $name );
			$this->set_path( QODE_BADGES_FOR_WOOCOMMERCE_CPT_PATH . '/badge' );
			$this->set_labels(
				array(
					'name'          => esc_html__( 'Badges', 'qode-badges-for-woocommerce' ),
					'singular_name' => esc_html__( 'Badge', 'qode-badges-for-woocommerce' ),
					'add_item'      => esc_html__( 'New Badge', 'qode-badges-for-woocommerce' ),
					'add_new'       => esc_html__( 'Add New Badge', 'qode-badges-for-woocommerce' ),
					'add_new_item'  => esc_html__( 'Add New Badge', 'qode-badges-for-woocommerce' ),
					'edit_item'     => esc_html__( 'Edit Badge', 'qode-badges-for-woocommerce' ),
					'search_items'  => esc_html__( 'Search Badges', 'qode-badges-for-woocommerce' ),
				)
			);

			$this->set_supports(
				array(
					'title',
				)
			);
		}
	}
}
