<?php

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

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


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

$gigneo_currency = get_woocommerce_currency();

//Tab Main Heading
$gigneo_job_main_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Jobs', 'gigneo' ),
	esc_html__( 'Manage job options for your platform.', 'gigneo' ),
);

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

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

$gigneo_job_general_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_job_general' )
		->set_html( $gigneo_job_general_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_job_general_fields[] =
	Field::make( 'select', 'gigneo_ts_job_type', esc_html__( 'Job 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_job_general_fields[] =
	Field::make( 'text', 'gigneo_ts_job_featured_limit', esc_html__( 'Featured limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_help_text( esc_html__( 'Set the maximum jobs a user can featured.', 'gigneo' ) );

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

$gigneo_job_general_fields = apply_filters( 'gigneo_ts_tab_job_section_general_fields', $gigneo_job_general_fields );
$gigneo_job_fields         = array_merge( $gigneo_job_fields, $gigneo_job_general_fields );

//Creation - Sections
$gigneo_job_creation_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Creation', 'gigneo' ),
	esc_html__( 'Configure and manage job creation options.', 'gigneo' )
);

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

$gigneo_job_creation_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_job_creation' )
		->set_html( $gigneo_job_creation_heading )
		->set_classes( 'gn-ts-field-heading' );

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

$gigneo_job_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_job_creation_credits', esc_html__( 'Credits for publish', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 10 )
		->set_attribute( 'placeholder', esc_html__( '10', 'gigneo' ) )
		->set_help_text( esc_html__( 'Set number of credits for job publishing.', 'gigneo' ) )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_job_creation_type',
					'value' => 'paid',
				),
			)
		);

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

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

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

$gigneo_job_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_job_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( 10 )
		->set_help_text( esc_html__( 'Set the maximum jobs a user can create.', 'gigneo' ) );
$gigneo_job_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_job_max_specific_types', esc_html__( 'Specific types limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 5 );

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

$gigneo_job_creation_fields[] =
	Field::make( 'select', 'gigneo_ts_default_job_type', esc_html__( 'Default job type', 'gigneo' ) )
		->set_options(
			array(
				'remote' => esc_html__( 'Remote', 'gigneo' ),
				'onsite' => esc_html__( 'On site', 'gigneo' ),
			)
		)
		->set_default_value( 'remote' );

$gigneo_job_creation_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_job_attachment_extensions', esc_html__( 'Attachment extensions', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( gigneo_file_extensions() )
		->set_default_value( array( 'jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'mp4' ) );
$gigneo_job_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_job_attachment_limit', esc_html__( 'Upload attachment limit', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', esc_html__( '3', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 3 );
$gigneo_job_creation_fields[] =
	Field::make( 'text', 'gigneo_ts_job_attachment_max_size', esc_html__( 'Attachment size limit', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 5 )
		->set_help_text( esc_html__( 'Set the maximum file size for attachment that user can upload in MB.', 'gigneo' ) );
$gigneo_job_creation_fields   = apply_filters( 'gigneo_ts_tab_job_section_creation_fields', $gigneo_job_creation_fields );
$gigneo_job_fields            = array_merge( $gigneo_job_fields, $gigneo_job_creation_fields );

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

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

$gigneo_job_archive_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_job_archive' )
		->set_html( $gigneo_job_archive_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_job_archive_fields[] =
	Field::make( 'select', 'gigneo_ts_job_archive_layout', esc_html__( 'Layout', 'gigneo' ) )
		->set_options(
			apply_filters(
				'gigneo_ts_job_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_job_archive_fields[] =
	Field::make( 'text', 'gigneo_ts_jobs_per_page', esc_html__( 'Show per page', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 8 );


$gigneo_job_archive_fields = apply_filters( 'gigneo_ts_tab_job_section_archive_fields', $gigneo_job_archive_fields );
$gigneo_job_fields         = array_merge( $gigneo_job_fields, $gigneo_job_archive_fields );


//Freelancer fee - Section
$gigneo_job_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_job_freelancer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_freelancer_job_fee' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_job_freelancer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_freelancer_job_fee' )
		->set_html( $gigneo_job_freelancer_fee_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_job_freelancer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_freelancer_job_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_job_freelancer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_freelancer_job_fixed_amount_fee', esc_html__( 'Flat', 'gigneo' ) )
	->set_attribute( 'type', 'number' )
	->set_attribute( 'placeholder', $gigneo_currency )
	->set_attribute( 'data-regex', '^[0-9]+$' );



$gigneo_job_freelancer_fee_fields = apply_filters( 'gigneo_ts_tab_payment_section_freelancer_job_fee_fields', $gigneo_job_freelancer_fee_fields );
$gigneo_job_fields                = array_merge( $gigneo_job_fields, $gigneo_job_freelancer_fee_fields );

//Employer fee - Section
$gigneo_job_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_job_employer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_separator_employer_job_fee' )
		->set_html( '<hr>' )
		->set_classes( 'gn-separator' );

$gigneo_job_employer_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_employer_job_fee' )
		->set_html( $gigneo_job_employer_fee_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_job_employer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_employer_job_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_job_employer_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_employer_job_fixed_amount_fee', esc_html__( 'Flat', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', $gigneo_currency )
		->set_attribute( 'data-regex', '^[0-9]+$' );



$gigneo_job_employer_fee_fields = apply_filters( 'gigneo_ts_tab_payment_section_employer_job_fee_fields', $gigneo_job_employer_fee_fields );
$gigneo_job_fields              = array_merge( $gigneo_job_fields, $gigneo_job_employer_fee_fields );


//Apply - Sections
$gigneo_job_recruitment_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Recruitment', 'gigneo' ),
	esc_html__( 'Configure and manage job recruitment options.', 'gigneo' )
);

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

$gigneo_job_recruitment_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_job_recruitment' )
		->set_html( $gigneo_job_recruitment_heading )
		->set_classes( 'gn-ts-field-heading' );

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

$gigneo_job_recruitment_fields[] =
	Field::make( 'text', 'gigneo_ts_job_apply_credits', esc_html__( 'Credits for proposal', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 10 )
		->set_attribute( 'placeholder', esc_html__( '10', 'gigneo' ) )
		->set_help_text( esc_html__( 'Set number of credits for job apply.', 'gigneo' ) )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_job_apply_type',
					'value' => 'paid',
				),
			)
		);

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

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

$gigneo_job_recruitment_conditions = apply_filters( 'gigneo_job_recruitment_conditions', $gigneo_job_recruitment_conditions );
$gigneo_job_recruitment_fields[]   =
	Field::make( 'multiselect', 'gigneo_ts_job_apply_conditions', esc_html__( 'Apply conditions', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( $gigneo_job_recruitment_conditions );

$gigneo_job_recruitment_fields = apply_filters( 'gigneo_ts_tab_job_section_recruitment_fields', $gigneo_job_recruitment_fields );
$gigneo_job_fields             = array_merge( $gigneo_job_fields, $gigneo_job_recruitment_fields );


//Proposals - Sections
$gigneo_job_proposals_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Proposals', 'gigneo' ),
	esc_html__( 'Configure and manage proposal display and functionality.', 'gigneo' )
);

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

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

$gigneo_job_order_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_job_order' )
		->set_html( $gigneo_job_order_heading )
		->set_classes( 'gn-ts-field-heading' );


$gigneo_job_order_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_job_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_job_order_fields[] =
	Field::make( 'text', 'gigneo_ts_job_order_max_files', esc_html__( 'Attachment files limit', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( '3' );

$gigneo_job_order_fields[] =
	Field::make( 'text', 'gigneo_ts_job_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 job order attachments that user can upload in MB.', 'gigneo' ) );

$gigneo_job_order_fields[] =
	Field::make( 'complex', 'gigneo_ts_job_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_job_order_fields = apply_filters( 'gigneo_ts_tab_job_section_order_fields', $gigneo_job_order_fields );
$gigneo_job_fields       = array_merge( $gigneo_job_fields, $gigneo_job_order_fields );
