<?php

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

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

//Tab Main Heading
$gigneo_freelancer_main_heading = Theme_Option::render_heading_markup(
	gigneo_freelancer_plural(),
	sprintf(
		// translators: %s: freelancer singular.
		esc_html__( 'Manage %s options and profile settings.', 'gigneo' ),
		strtolower( gigneo_freelancer_singular() )
	)
);

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

//General - Sections
$gigneo_freelancer_general_heading = Theme_Option::render_heading_markup(
	esc_html__( 'General', 'gigneo' ),
	esc_html__( 'Customize and manage the general core features.', 'gigneo' )
);

$gigneo_freelancer_general_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_freelancer_general' )
		->set_html( $gigneo_freelancer_general_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_freelancer_general_fields[] = Field::make( 'image', 'gigneo_ts_freelancer_default_profile_image', esc_html__( 'Default profile image', 'gigneo' ) );

$gigneo_freelancer_general_fields[] =
	Field::make( 'text', 'gigneo_ts_post_type_freelancer_singular', esc_html__( 'Singular', 'gigneo' ) )
		->set_default_value( esc_html__( 'Freelancer', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[A-Z][a-z]*$' );

$gigneo_freelancer_general_fields[] =
	Field::make( 'text', 'gigneo_ts_post_type_freelancer_plural', esc_html__( 'Plural', 'gigneo' ) )
		->set_default_value( esc_html__( 'Freelancers', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[A-Z][a-z]*$' );



//Social Profiles
if ( in_array( 'social_profiles', gigneo_active_modules(), true ) ) {

	$gigneo_freelancer_general_fields[] =
		Field::make( 'multiselect', 'gigneo_ts_freelancer_social_profiles', esc_html__( 'Social profiles', 'gigneo' ) )
			->set_datastore( new Serialized() )
			->set_options( gigneo_social_profiles() )
			->set_default_value( array( 'facebook', 'twitter', 'instagram', 'linkedin' ) );

}

$gigneo_freelancer_general_fields = apply_filters( 'gigneo_ts_tab_freelancer_section_general_fields', $gigneo_freelancer_general_fields );
$gigneo_freelancer_fields         = array_merge( $gigneo_freelancer_fields, $gigneo_freelancer_general_fields );

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

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

$gigneo_freelancer_archive_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_freelancer_archive' )
		->set_html( $gigneo_freelancer_archive_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_freelancer_archive_fields[] =
	Field::make( 'select', 'gigneo_ts_freelancer_archive_layout', esc_html__( 'Layout', 'gigneo' ) )
		->set_options(
			apply_filters(
				'gigneo_ts_freelancer_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_freelancer_archive_visibility_conditions = array(
	'profile_image' => esc_html__( 'Profile image', 'gigneo' ),
);

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

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

$gigneo_freelancer_archive_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_freelancer_visibility_conditions', esc_html__( 'Visibility conditions', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( $gigneo_freelancer_archive_visibility_conditions )
		->set_default_value( array( 'profile_image' ) )
		->set_help_text( esc_html__( 'Set visibility conditions to show on listing page.', 'gigneo' ) );

$gigneo_freelancer_archive_fields[] =
	Field::make( 'text', 'gigneo_ts_services_published', esc_html__( 'Published services', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_help_text( esc_html__( 'Set minimum published services to show on listing page.', 'gigneo' ) )
		->set_conditional_logic(
			array(
				array(
					'field'   => 'gigneo_ts_freelancer_visibility_conditions',
					'value'   => 'publish_services',
					'compare' => 'INCLUDES',
				),
			)
		);

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

$gigneo_freelancer_archive_fields = apply_filters( 'gigneo_ts_tab_freelancer_section_archive_fields', $gigneo_freelancer_archive_fields );
$gigneo_freelancer_fields         = array_merge( $gigneo_freelancer_fields, $gigneo_freelancer_archive_fields );
