<?php

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

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

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

$gigneo_currency = get_woocommerce_currency();

//Tab Main Heading
$gigneo_payment_main_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Payment', 'gigneo' ),
	esc_html__( 'Manage and configure platform payments.', 'gigneo' )
);

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

//Basic - Sections
$gigneo_payment_general_heading = Theme_Option::render_heading_markup(
	esc_html__( 'General', 'gigneo' ),
	esc_html__( 'Personalize and manage the general payments settings.', 'gigneo' )
);

$gigneo_payment_general_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_payment_basic' )
		->set_html( $gigneo_payment_general_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_payment_general_fields[] =
	Field::make( 'select', 'gigneo_ts_wallet_product', esc_html__( 'Wallet product', 'gigneo' ) )
		->set_options( gigneo_product_list() )
		->set_classes( 'gn-select2' );

$gigneo_payment_general_fields[] =
	Field::make( 'text', 'gigneo_ts_credit_rate', esc_html__( 'Credit rate', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'data-regex', '^[0-9]+$' )
		->set_default_value( 1 )
		->set_help_text(
			sprintf(
			// translators: %s: Default currency
				esc_html__( 'Define how many credits is equal to 1 %s.', 'gigneo' ),
				esc_html( $gigneo_currency )
			)
		);

$gigneo_payment_general_fields[] =
	Field::make( 'select', 'gigneo_ts_withdrawal_product', esc_html__( 'Withdrawal product', 'gigneo' ) )
		->set_options( gigneo_product_list() )
		->set_classes( 'gn-select2' );

$gigneo_payment_withdraw_payouts = array(
	'paypal'   => esc_html__( 'Paypal', 'gigneo' ),
	'payoneer' => esc_html__( 'Payoneer', 'gigneo' ),
	'bank'     => esc_html__( 'Bank', 'gigneo' ),
);
if ( in_array( 'custom_payouts', gigneo_active_modules(), true ) ) {
	$gigneo_payment_withdraw_payouts['custom'] = esc_html__( 'Custom', 'gigneo' );
}
$gigneo_payment_general_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_payment_withdraw_payouts', esc_html__( 'Withdrawal payouts', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( $gigneo_payment_withdraw_payouts )
		->set_default_value( array( 'paypal', 'payoneer' ) );

$gigneo_payment_general_fields[] =
	Field::make( 'multiselect', 'gigneo_ts_payment_bank_required_fields', esc_html__( 'Bank required fields', 'gigneo' ) )
		->set_datastore( new Serialized() )
		->set_options( gigneo_payout_bank_fields() )
		->set_default_value( array( 'name', 'acc_name', 'acc_number' ) )
		->set_conditional_logic(
			array(
				array(
					'field'   => 'gigneo_ts_payment_withdraw_payouts',
					'value'   => 'bank',
					'compare' => 'INCLUDES',
				),
			)
		);



$gigneo_payment_general_fields[] =
	Field::make( 'text', 'gigneo_ts_minimum_withdraw_amount', esc_html__( 'Minimum withdrawal', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_default_value( 50 );

$gigneo_payment_general_fields[] = Field::make( 'text', 'gigneo_ts_platform_fee_name', esc_html__( 'Commission fee name', 'gigneo' ) )
		->set_default_value( esc_html__( 'Platform fee', 'gigneo' ) )
		->set_help_text( esc_html__( 'Set the name of the platform fee.', 'gigneo' ) );


$gigneo_payment_general_fields = apply_filters( 'gigneo_ts_tab_payment_section_general_fields', $gigneo_payment_general_fields );
$gigneo_payment_fields         = array_merge( $gigneo_payment_fields, $gigneo_payment_general_fields );

//Withdrawal fee - Section
$gigneo_payment_withdrawal_fee_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Withdrawal fee', 'gigneo' ),
	esc_html__( 'Manage withdrawal fees that may apply to transactions.', 'gigneo' ),
);

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

$gigneo_payment_withdrawal_fee_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_withdrawal_fee' )
		->set_html( $gigneo_payment_withdrawal_fee_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_payment_withdrawal_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_withdrawal_fee_name', esc_html__( 'Name', 'gigneo' ) )
		->set_default_value( esc_html__( 'Withdrawal fee', 'gigneo' ) );

$gigneo_payment_withdrawal_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_withdrawal_percentage_fee', esc_html__( 'Percentage', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', '%' )
		->set_attribute( 'max', 100 );

$gigneo_payment_withdrawal_fee_fields[] =
	Field::make( 'text', 'gigneo_ts_withdrawal_fixed_amount_fee', esc_html__( 'Flat', 'gigneo' ) )
		->set_attribute( 'type', 'number' )
		->set_attribute( 'placeholder', $gigneo_currency );



$gigneo_payment_withdrawal_fee_fields = apply_filters( 'gigneo_ts_tab_payment_section_withdrawal_fee_fields', $gigneo_payment_withdrawal_fee_fields );
$gigneo_payment_fields                = array_merge( $gigneo_payment_fields, $gigneo_payment_withdrawal_fee_fields );

//Invoice - Section
$gigneo_payment_invoice_heading = Theme_Option::render_heading_markup(
	esc_html__( 'Invoice', 'gigneo' ),
	esc_html__( 'Manage the invoice settings.', 'gigneo' ),
);

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

$gigneo_payment_invoice_fields[] =
	Field::make( 'html', 'gigneo_ts_heading_invoice' )
		->set_html( $gigneo_payment_invoice_heading )
		->set_classes( 'gn-ts-field-heading' );

$gigneo_payment_invoice_fields[] =
	Field::make( 'image', 'gigneo_ts_invoice_logo', esc_html__( 'Logo', 'gigneo' ) );

$gigneo_payment_invoice_fields[] =
	Field::make( 'text', 'gigneo_ts_invoice_from_name', esc_html__( 'From name', 'gigneo' ) )
		->set_default_value( get_bloginfo( 'name' ) );

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

$gigneo_payment_invoice_fields[] =
	Field::make( 'text', 'gigneo_ts_invoice_from_address', esc_html__( 'Address', 'gigneo' ) );

$gigneo_payment_invoice_fields[] =
	Field::make( 'text', 'gigneo_ts_invoice_from_email', esc_html__( 'Email', 'gigneo' ) );

$gigneo_payment_invoice_fields[] =
	Field::make( 'text', 'gigneo_ts_invoice_from_phone', esc_html__( 'Phone', 'gigneo' ) );

$gigneo_payment_invoice_fields[] =
	Field::make( 'textarea', 'gigneo_ts_invoice_footer_text', esc_html__( 'Footer text', 'gigneo' ) );

$gigneo_payment_invoice_fields = apply_filters( 'gigneo_ts_tab_payment_section_invoice_fields', $gigneo_payment_invoice_fields );
$gigneo_payment_fields         = array_merge( $gigneo_payment_fields, $gigneo_payment_invoice_fields );
