<?php

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

use Carbon_Fields\Field\Field;
use Gigneo\Modules;
use Gigneo\Theme_Option;

//Tab Main Heading
$gigneo_notification_main_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Notifications', 'gigneo' ),
	esc_html__( 'Manage and configure platform notifications.', 'gigneo' )
);

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

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

$gigneo_notification_general_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_notification_general' )
		->set_html( $gigneo_notification_general_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_notification_realtime_options = array(
	'none'      => esc_html__( 'None', 'gigneo' ),
	'heartbeat' => esc_html__( 'Heartbeat', 'gigneo' ),
);
if ( in_array( 'real_time', gigneo_active_modules(), true ) ) {
	$gigneo_notification_realtime_options['pusher'] = esc_html__( 'Pusher', 'gigneo' );
}
$gigneo_notification_general_fields[] =
	Field::make( 'select', 'gigneo_ts_notification_type', esc_html__( 'Realtime', 'gigneo' ) )
		->set_default_value( 'heartbeat' )
		->set_options( $gigneo_notification_realtime_options )
		->set_classes( 'gn-select2' );

$gigneo_notification_general_fields[] =
	Field::make( 'text', 'gigneo_ts_heartbeat_interval', esc_html__( 'Interval', 'gigneo' ) )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_notification_type',
					'value' => 'heartbeat',
				),
			)
		)
		->set_help_text( esc_html__( 'Set heartbeat interval in second(s).', 'gigneo' ) );

$gigneo_notification_general_fields[] =
	Field::make( 'checkbox', 'gigneo_ts_notification_onscreen', esc_html__( 'Onscreen', 'gigneo' ) )
		->set_help_text( esc_html__( 'Enable to show new notifications while on a page on-screen.', 'gigneo' ) )
		->set_classes( 'gn-switch' )
		->set_default_value( true );

$gigneo_notification_general_fields[] =
	Field::make( 'select', 'gigneo_ts_notification_onscreen_type', esc_html__( 'Onscreen position', 'gigneo' ) )
		->set_default_value( 'heartbeat' )
		->set_options(
			array(
				'top-left'     => esc_html__( 'Top left', 'gigneo' ),
				'top-right'    => esc_html__( 'Top right', 'gigneo' ),
				'bottom-left'  => esc_html__( 'Bottom left', 'gigneo' ),
				'bottom-right' => esc_html__( 'Bottom right', 'gigneo' ),
			)
		)
		->set_classes( 'gn-select2' )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_notification_onscreen',
					'value' => true,
				),
			)
		);

$gigneo_notification_general_fields[] =
	Field::make( 'text', 'gigneo_ts_notification_onscreen_auto_hide', esc_html__( 'Auto hide', 'gigneo' ) )
		->set_default_value( '5' )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_help_text( esc_html__( 'Set auto hide delay in seconds.', 'gigneo' ) )
		->set_conditional_logic(
			array(
				array(
					'field' => 'gigneo_ts_notification_onscreen',
					'value' => true,
				),
			)
		);

$gigneo_notification_general_fields[] =
	Field::make( 'text', 'gigneo_ts_notification_auto_delete', esc_html__( 'Auto delete', 'gigneo' ) )
		->set_default_value( '15' )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_help_text( esc_html__( 'Remove read notifications after the specified days.', 'gigneo' ) );

$gigneo_notification_general_fields = apply_filters( 'gigneo_ts_tab_notification_section_general_fields', $gigneo_notification_general_fields );
$gigneo_notification_fields         = array_merge( $gigneo_notification_fields, $gigneo_notification_general_fields );
