<?php

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

use Carbon_Fields\Field\Field;
use Gigneo\Modules;
use Gigneo\Post_Meta\Serialized;

$gigneo_locations_complex_fields[] = Field::make( 'select', 'country_state', esc_html__( 'Country / State', 'gigneo' ) )
									->set_options( gigneo_countries_with_states( 'active' ) )
									->set_classes( 'gn-select2' );

$gigneo_cities_option = gigneo_option( '_gigneo_ts_disable_cities', false );

if ( ! $gigneo_cities_option ) {
	$gigneo_locations_complex_fields[] = Field::make( 'select', 'city', esc_html__( 'City', 'gigneo' ) )
										->set_options( gigneo_cities() )
										->set_classes( 'gn-select2' );
}

$gigneo_locations_complex_fields[] =
	Field::make( 'text', 'area', esc_html__( 'Area', 'gigneo' ) )
		->set_attribute( 'placeholder', esc_html__( 'Block / Sector / Town', 'gigneo' ) );

$gigneo_locations_complex_fields[] =
	Field::make( 'text', 'zip_code', esc_html__( 'Postcode / ZIP', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' );




$gigneo_locations_complex_fields[] = Field::make( 'textarea', 'address', esc_html__( 'Address', 'gigneo' ) );


$gigneo_multi_location = false;

if ( in_array( 'multi_location', gigneo_active_modules(), true ) ) {
	$gigneo_multi_location = gigneo_option( '_gigneo_ts_service_multi_locations', false );
}

$gigneo_locations_complex_fields = apply_filters( 'gigneo_locations_complex_fields', $gigneo_locations_complex_fields );

$gigneo_feature_fields[] = Field::make( 'complex', 'gigneo_pm_locations', esc_html__( 'Locations', 'gigneo' ) )
	->set_datastore( new Serialized() )
	->add_fields( $gigneo_locations_complex_fields )
	->set_header_template( '<%- address %>' )
	->set_collapsed( true )
	->set_max( ! $gigneo_multi_location ? 1 : '' );

$gigneo_feature_fields[] = Field::make( 'complex', 'gigneo_pm_custom_offers', esc_html__( 'Custom offers', 'gigneo' ) )
	->set_datastore( new Serialized() )
	->add_fields(
		array(
			Field::make( 'text', 'name', esc_html__( 'Name', 'gigneo' ) ),
			Field::make( 'checkbox', 'plan_one', esc_html__( 'Plan 1', 'gigneo' ) ),
			Field::make( 'checkbox', 'plan_two', esc_html__( 'Plan 2', 'gigneo' ) ),
			Field::make( 'checkbox', 'plan_three', esc_html__( 'Plan 3', 'gigneo' ) ),
		)
	)
	->set_header_template( '<%- name %>' )
	->set_collapsed( true );

$gigneo_feature_fields = apply_filters( 'gigneo_pm_service_feature_tab_fields', $gigneo_feature_fields );
