<?php
/**
 * ACF field group for the "coupons" post type (Simple CPT).
 *
 * Powers the "We Would Suggest You" homepage section and the advance
 * search results, both of which read these fields via get_field() with
 * a get_post_meta() fallback when Advanced Custom Fields isn't active.
 *
 * @package coupon-flash-deals
 */

if ( ! function_exists( 'coupon_flash_deals_register_coupon_fields' ) ) :
function coupon_flash_deals_register_coupon_fields() {

	if ( ! function_exists( 'acf_add_local_field_group' ) ) {
		return;
	}

	acf_add_local_field_group(
		array(
			'key'      => 'group_cfd_coupon_details',
			'title'    => __( 'Coupon Details', 'coupon-flash-deals' ),
			'fields'   => array(
				array(
					'key'           => 'field_cfd_coupon_amount',
					'label'         => __( 'Discount Amount', 'coupon-flash-deals' ),
					'name'          => 'coupon_amount',
					'type'          => 'text',
					'instructions'  => __( 'e.g. 45%', 'coupon-flash-deals' ),
					'placeholder'   => '45%',
				),
				array(
					'key'           => 'field_cfd_start_date',
					'label'         => __( 'Start Date', 'coupon-flash-deals' ),
					'name'          => 'start_date',
					'type'          => 'date_picker',
					'display_format' => 'd/m/Y',
					'return_format'  => 'Ymd',
					'first_day'      => 1,
				),
				array(
					'key'           => 'field_cfd_date_expires',
					'label'         => __( 'Expiry Date', 'coupon-flash-deals' ),
					'name'          => 'date_expires',
					'type'          => 'date_picker',
					'instructions'  => __( 'Used to calculate the "Expires in X days" countdown.', 'coupon-flash-deals' ),
					'display_format' => 'd/m/Y',
					'return_format'  => 'Ymd',
					'first_day'      => 1,
				),
			),
			'location' => array(
				array(
					array(
						'param'    => 'post_type',
						'operator' => '==',
						'value'    => 'coupons',
					),
				),
			),
		)
	);
}
endif;
add_action( 'acf/init', 'coupon_flash_deals_register_coupon_fields' );
