<?php

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

use Carbon_Fields\Field\Field;
use Gigneo\Theme_Option;
use Gigneo\Theme_Option\Serialized;

if ( 'jobs' === gigneo_platform_type() ) {
	return;
}

$gigneo_currency = get_woocommerce_currency();

//Tab Main Heading
$gigneo_service_main_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Services', 'gigneo' ),
	esc_html__( 'Manage service options for your platform.', 'gigneo' ),
);

$gigneo_service_fields[] =
	Field::make( 'html', 'gigneo_service_main_heading' )
		->set_html( $gigneo_service_main_heading )
		->set_classes( 'gn-ts-main-heading' );

//Basic - Sections
$gigneo_service_general_heading = Theme_Option::render_heading_markup(
	esc_html__( 'General', 'gigneo' ),
	esc_html__( 'Configure and manage core service features.', 'gigneo' )
);

$gigneo_service_general_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_service_basic' )
		->set_html( $gigneo_service_general_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_service_general_fields[] =
	Field::make( 'select', 'gigneo_ts_service_type', esc_html__( 'Service type', 'gigneo' ) )
		->set_options(
			array(
				'remote' => esc_html__( 'Remote', 'gigneo' ),
				'onsite' => esc_html__( 'Onsite', 'gigneo' ),
				'both'   => esc_html__( 'Both', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( 'both' );

$gigneo_service_general_fields[] =
	Field::make( 'text', 'gigneo_ts_service_featured_limit', esc_html__( 'Featured limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 0 )
		->set_help_text( esc_html__( 'Set the maximum services a user can featured.', 'gigneo' ) );

$gigneo_service_general_fields[] =
	Field::make( 'checkbox', 'gigneo_ts_service_custom_offers', esc_html__( 'Custom offers', 'gigneo' ) )
		->set_help_text( esc_html__( 'Enable to allow user to add multiple custom offer efficiently.', 'gigneo' ) )
		->set_default_value( true )
		->set_classes( 'gn-switch' );

$gigneo_service_general_fields[] =
	Field::make( 'checkbox', 'gigneo_ts_service_manually_approve', esc_html__( 'Manually approve', 'gigneo' ) )
		->set_help_text( esc_html__( 'Services require manual approval by an admin before going live.', 'gigneo' ) )
		->set_classes( 'gn-switch' )
		->set_default_value( false );

$gigneo_service_general_fields = apply_filters( 'gigneo_ts_tab_service_section_general_fields', $gigneo_service_general_fields );
$gigneo_service_fields         = array_merge( $gigneo_service_fields, $gigneo_service_general_fields );

//Creation - Section
$gigneo_service_creation_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_service_creation' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_service_creation_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Creation', 'gigneo' ),
	esc_html__( 'Configure and manage service creation options.', 'gigneo' )
);

$gigneo_service_creation_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_service_creation' )
		->set_html( $gigneo_service_creation_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_service_creation_fields[] =
	Field::make( 'select', 'gigneo_ts_service_creation_type', esc_html__( 'Publish type', 'gigneo' ) )
		->set_options(
			array(
				'free' => esc_html__( 'Free', 'gigneo' ),
				'paid' => esc_html__( 'Paid', 'gigneo' ),
			)
		)
		->set_default_value( 'paid' )
		->set_classes( 'gn-select2' );

$gigneo_service_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_service_creation_credits', esc_html__( 'Credits for publish', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'min', 1 )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 10 )
		->set_help_text( esc_html__( 'Set number of credits for service publishing.', 'gigneo' ) )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_service_creation_type',
					'value' => 'paid',
				),
			)
		);

$gigneo_service_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_service_title_prefix', esc_html__( 'Title prefix', 'gigneo' ) )
		->set_attribute( 'type', 'text' );

$gigneo_service_creation_fields[] =
	Field::make( 'select', 'gigneo_ts_service_pricing_title', esc_html__( 'Pricing title', 'gigneo' ) )
		->set_options(
			array(
				'custom'  => esc_html__( 'Custom', 'gigneo' ),
				'default' => esc_html__( 'Default', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( 'custom' );

$gigneo_service_creation_conditions = array(
	'profile_image' => esc_html__( 'Profile image', 'gigneo' ),
);

if ( in_array( 'email_verification', gigneo_active_modules(), true ) ) {
	$gigneo_service_creation_conditions['email_verified'] = esc_html__( 'Email verified', 'gigneo' );
}

$gigneo_service_creation_conditions = apply_filters( 'gigneo_service_creation_conditions', $gigneo_service_creation_conditions );
$gigneo_service_creation_fields[]   =
	Field::make( 'multiselect', 'gigneo_ts_service_creation_conditions', esc_html__( 'Creation conditions', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( $gigneo_service_creation_conditions );

$gigneo_service_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_service_creation_limit', esc_html__( 'Creation limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', esc_html__( 'Unlimited', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 3 )
		->set_help_text( esc_html__( 'Set the maximum services a user can create.', 'gigneo' ) );

$gigneo_service_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_service_max_specific_types', esc_html__( 'Specific types limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 5 );

$gigneo_service_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_service_max_skills', esc_html__( 'Skills limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 5 );



$gigneo_service_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_service_gallery_limit', esc_html__( 'Attach images limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', esc_html__( '3', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 3 );

$gigneo_service_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_service_document_limit', esc_html__( 'Attach documents limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', esc_html__( '3', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 3 );



$gigneo_service_creation_fields = apply_filters( 'gigneo_ts_tab_service_section_creation_fields', $gigneo_service_creation_fields );
$gigneo_service_fields          = array_merge( $gigneo_service_fields, $gigneo_service_creation_fields );

//Archive - Sections
$gigneo_service_archive_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Archive', 'gigneo' ),
	esc_html__( 'Customize and manage archive display and functionality.', 'gigneo' )
);

$gigneo_service_archive_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_service_archive' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_service_archive_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_service_archive' )
		->set_html( $gigneo_service_archive_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_service_archive_fields[] =
	Field::make( 'select', 'gigneo_ts_service_archive_layout', esc_html__( 'Layout', 'gigneo' ) )
		->set_options(
			apply_filters(
				'gigneo_ts_service_archive_layout_options',
				array(
					'1' => esc_html__( 'Style 1', 'gigneo' ),
					'2' => esc_html__( 'Style 2', 'gigneo' ),
				)
			)
		)
		->set_classes( 'gn-select2' )
		->set_default_value( '1' );



$gigneo_service_archive_fields[] =
	Field::make( 'text', 'gigneo_ts_services_per_page', esc_html__( 'Show per page', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 9 );


$gigneo_service_archive_fields = apply_filters( 'gigneo_ts_tab_service_section_archive_fields', $gigneo_service_archive_fields );
$gigneo_service_fields         = array_merge( $gigneo_service_fields, $gigneo_service_archive_fields );

//Freelancer fee - Section
$gigneo_service_freelancer_fee_heading = Theme_Option::render_heading_markup(
	sprintf(
	// translators: %s: Freelancer singular.
		esc_html__( '%s fee', 'gigneo' ),
		gigneo_freelancer_singular()
	),
	sprintf(
		// translators: %s:Freelancer singular.
		esc_html__( 'Manage the platform commission fee from %s.', 'gigneo' ),
		strtolower( gigneo_freelancer_singular() )
	)
);

$gigneo_service_freelancer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_freelancer_service_fee' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_service_freelancer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_freelancer_service_fee' )
		->set_html( $gigneo_service_freelancer_fee_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_service_freelancer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_freelancer_service_percentage_fee', esc_html__( 'Percentage', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', '%' )
		->set_attribute( 'min', 0 )
		->set_attribute( 'max', 100 )
		->set_attribute( 'data-regex', '^[0-9]+$' );

$gigneo_service_freelancer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_freelancer_service_fixed_amount_fee', esc_html__( 'Flat', 'gigneo' ) )
	->set_attribute( 'type', 'number' )
	->set_attribute( 'placeholder', $gigneo_currency )
	->set_attribute( 'data-regex', '^[0-9]+$' );



$gigneo_service_freelancer_fee_fields = apply_filters( 'gigneo_ts_tab_payment_section_freelancer_service_fee_fields', $gigneo_service_freelancer_fee_fields );
$gigneo_service_fields                = array_merge( $gigneo_service_fields, $gigneo_service_freelancer_fee_fields );

//Employer fee - Section
$gigneo_service_employer_fee_heading = Theme_Option::render_heading_markup(
	sprintf(
	// translators: %s: Employer singular.
		esc_html__( '%s fee', 'gigneo' ),
		gigneo_employer_singular()
	),
	sprintf(
	// translators: %s: Employer singular.
		esc_html__( 'Manage the platform commission fee from %s.', 'gigneo' ),
		strtolower( gigneo_employer_singular() )
	)
);

$gigneo_service_employer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_employer_service_fee' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_service_employer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_employer_service_fee' )
		->set_html( $gigneo_service_employer_fee_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_service_employer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_employer_service_percentage_fee', esc_html__( 'Percentage', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', '%' )
		->set_attribute( 'min', 0 )
		->set_attribute( 'max', 100 )
		->set_attribute( 'data-regex', '^[0-9]+$' );

$gigneo_service_employer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_employer_service_fixed_amount_fee', esc_html__( 'Flat', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', $gigneo_currency )
		->set_attribute( 'data-regex', '^[0-9]+$' );



$gigneo_service_employer_fee_fields = apply_filters( 'gigneo_ts_tab_payment_section_employer_service_fee_fields', $gigneo_service_employer_fee_fields );
$gigneo_service_fields              = array_merge( $gigneo_service_fields, $gigneo_service_employer_fee_fields );

//Order - Sections
$gigneo_service_order_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Order', 'gigneo' ),
	esc_html__( 'Customize and manage order display and functionality.', 'gigneo' )
);

$gigneo_service_order_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_service_order' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_service_order_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_service_order' )
		->set_html( $gigneo_service_order_heading )
		->set_classes( 'gn-ts-field-heading' );


$gigneo_service_order_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_service_order_extensions', esc_html__( 'Attachment extensions', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( gigneo_file_extensions() )
		->set_default_value( array( 'jpg', 'jpeg', 'png', 'doc' ) );

$gigneo_service_order_fields[] =
	Field::make( 'text', 'gigneo_ts_service_order_max_files', esc_html__( 'Attachment files limit', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( '3' );

$gigneo_service_order_fields[] =
	Field::make( 'text', 'gigneo_ts_service_order_max_size', esc_html__( 'Attachment size limit', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( '1' )
		->set_help_text( esc_html__( 'Set the maximum file size for service order attachments that user can upload in MB.', 'gigneo' ) );

$gigneo_service_order_fields[] =
	Field::make( 'complex', 'gigneo_ts_service_cancel_reasons', esc_html__( 'Cancel Reasons', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->add_fields(
			array(
				Field::make( 'text', 'reason', esc_html__( 'Reason', 'gigneo' ) ),
			)
		)
		->set_header_template( '<%- reason %>' )
		->set_default_value(
			array(
				array( 'reason' => esc_html__( 'Scheduling conflict', 'gigneo' ) ),
				array( 'reason' => esc_html__( 'Skills mismatch', 'gigneo' ) ),
				array( 'reason' => esc_html__( 'Security issues', 'gigneo' ) ),
			)
		)
		->set_collapsed( true );


$gigneo_service_order_fields = apply_filters( 'gigneo_ts_tab_service_section_order_fields', $gigneo_service_order_fields );
$gigneo_service_fields       = array_merge( $gigneo_service_fields, $gigneo_service_order_fields );
