<?php

namespace Sibs\Stargate\Admin;

use Sibs\Stargate\Constants\PaymentMethods;
use Sibs\Stargate\Constants\PaymentTypes;
use Sibs\Stargate\Constants\WoocommercePaymentMethods;
use Sibs\Stargate\Core\SibsGeneralFunctions;

defined('ABSPATH') || exit;

class SibsPaymentSettings
{
    /**
     * SIBS Create Backend Payment Settings.
     *
     * @param string $payment_id
     *
     * @return array
     */
    public static function sibs_create_backend_payment_settings($payment_id)
    {
        $form_fields = [];

        $form_fields['enabled'] = [
            'title' => __('Active', 'sibs-woo-stg'),
            'type' => 'checkbox',
            'default' => '',
            'desc' => '',
        ];

        $form_fields = array_merge_recursive(
            $form_fields,
            self::add_card_fields_in_form($payment_id),
            self::add_xpay_fields_in_form($payment_id),
            self::add_auth_db_fields_in_form($payment_id),
            self::add_pay_by_link_fields_in_form($payment_id),
            self::add_blik_fields_in_form($payment_id),
            self::add_tokenization_fields_in_form($payment_id)
        );

        $form_fields['payment_desc'] = [
            'title' => __('Payment Description', 'sibs-woo-stg'),
            'type' => 'textarea',
            'default' => '',
            'desc' => '',
        ];

        return $form_fields;
    }

    /**
     * Add Xpay Fields in Form.
     *
     * @param string $payment_id
     *
     * @return array
     */
    public static function add_xpay_fields_in_form($payment_id)
    {
        $form_fields = [];
        $cardPaymentMethods = [
            WoocommercePaymentMethods::XPAY,
            WoocommercePaymentMethods::GPAY,
            WoocommercePaymentMethods::APAY,
        ];

        if (in_array($payment_id, $cardPaymentMethods)) {
            $form_fields['card_types'] = [
                'title' => __('Card Logos to present on Checkout', 'sibs-woo-stg'),
                'type' => 'multiselect',
                'css' => 'height:12em;',
                'options' => [
                    PaymentMethods::GPAY => __('Google Pay', 'sibs-woo-stg'),
                    PaymentMethods::APAY => __('Apple Pay', 'sibs-woo-stg'),
                ],
                'default' => [PaymentMethods::GPAY, PaymentMethods::APAY],
                'desc' => esc_attr(__('Hold Ctrl while selecting the card you want to activate the payment gateway for the selected card', 'sibs-woo-stg')),
            ];
        }

        return $form_fields;
    }

    /**
     * Add Card Fields In Form.
     *
     * @param string $payment_id
     *
     * @return array
     */
    public static function add_card_fields_in_form($payment_id)
    {
        $form_fields = [];
        $cardPaymentMethods = [
            WoocommercePaymentMethods::CARD,
        ];

        if (in_array($payment_id, $cardPaymentMethods)) {
            $form_fields['card_types'] = [
                'title' => __('Card Logos to present on Checkout', 'sibs-woo-stg'),
                'type' => 'multiselect',
                'css' => 'height:12em;',
                'options' => [
                    // 'AMEX'          => __('American Express', 'sibs-woo-stg'),
                    // 'MAESTRO'       => __('Maestro', 'sibs-woo-stg'),
                    'MASTER' => __('MasterCard', 'sibs-woo-stg'),
                    // 'MASTERDEBIT'   => __('MasterCard Debit', 'sibs-woo-stg'),
                    'VISA' => __('VISA', 'sibs-woo-stg'),
                    // 'VISADEBIT'     => __('VISA Debit', 'sibs-woo-stg'),
                    // 'VISAELECTRON'  => __('VISA Electron', 'sibs-woo-stg'),
                    // 'VPAY'          => __('V PAY', 'sibs-woo-stg'),
                ],
                'default' => ['MASTER', 'VISA'],
                'desc' => esc_attr(__('Hold Ctrl while selecting the card you want to activate the payment gateway for the selected card', 'sibs-woo-stg')),
            ];
        }

        return $form_fields;
    }

    /**
     * Add Auth Fields In Form.
     *
     * @param string $payment_id
     *
     * @return array
     */
    public static function add_auth_db_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_auth_db = [
            WoocommercePaymentMethods::CARD,
            // WoocommercePaymentMethods::XPAY,
            // WoocommercePaymentMethods::APAY,
            // WoocommercePaymentMethods::GPAY,
        ];

        if (in_array($payment_id, $payment_auth_db)) {
            $form_fields['trans_mode'] = [
                'title' => __('Transaction-Mode', 'sibs-woo-stg'),
                'type' => 'select',
                'options' => [
                    PaymentTypes::PURS => __('Debit', 'sibs-woo-stg'),
                    PaymentTypes::AUTH => __('Pre-Authorization', 'sibs-woo-stg'),
                ],
                'default' => PaymentTypes::PURS,
                'desc' => '',
            ];
        }

        return $form_fields;
    }

    /**
     * Add Pay By Link Fields In Form.
     *
     * @param string $payment_id
     *
     * @return array
     */
    public static function add_pay_by_link_fields_in_form($payment_id)
    {
        return [];
        // $payment_pay_by_link = [
        //     WoocommercePaymentMethods::PAY_BY_LINK,
        //     WoocommercePaymentMethods::PAY_BY_LINK_KEVIN,
        // ];

        // if (in_array($payment_id, $payment_pay_by_link)) {
        //     $form_fields['sibs_payment_date_value'] = [
        //         'title'    => __('SIBS Pbl Expiration Value', 'sibs-woo-stg'),
        //         'type'     => 'text',
        //         'default'  => '60',
        //         'desc'     => '',
        //     ];

        //     $form_fields['sibs_payment_date_unit'] = [
        //         'title'   => __('SIBS Pbl Expiration Unit', 'sibs-woo-stg'),
        //         'type'    => 'select',
        //         'options' => [
        //             'minute'    => __('Minute', 'sibs-woo-stg'),
        //             'hour'      => __('Hour', 'sibs-woo-stg'),
        //             'day'       => __('Day', 'sibs-woo-stg'),
        //             'month'     => __('Month', 'sibs-woo-stg'),
        //         ],
        //         'default'  => 'minute',
        //         'desc'     => '',
        //     ];
        // }
    }

    /**
     * Add Blik Fields In Form.
     *
     * @param string $payment_id
     *
     * @return array
     */
    public static function add_blik_fields_in_form($payment_id)
    {
        return [];
        // $payment_blik = [
        //     WoocommercePaymentMethods::BLIK,
        // ];

        // if (in_array($payment_id, $payment_blik)) {
        //     $form_fields['sibs_number_of_retries'] = [
        //         'title'    => __('SIBS Blik Number of Retries', 'sibs-woo-stg'),
        //         'type'     => 'text',
        //         'default'  => '30',
        //         'desc'     => '',
        //     ];

        //     $form_fields['sibs_retry_delay'] = [
        //         'title'    => __('SIBS Blik Retry Delay (seconds)', 'sibs-woo-stg'),
        //         'type'     => 'text',
        //         'default'  => '1',
        //         'desc'     => '',
        //     ];
        // }
    }

    /**
     * Add Tokenization Fields In Form.
     *
     * @param string $payment_id
     *
     * @return array
     */
    public static function add_tokenization_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_tokenization = [
            WoocommercePaymentMethods::CARD,
        ];

        if (in_array($payment_id, $payment_tokenization)) {
            $form_fields['tokenization'] = [
                'title' => __('Tokenization', 'sibs-woo-stg'),
                'type' => 'select',
                'options' => [
                    'none' => __('None', 'sibs-woo-stg'),
                    'tokenization' => __('Tokenize', 'sibs-woo-stg'),
                    'oneclick' => __('OneClick', 'sibs-woo-stg'),
                ],
                'default' => 'none',
            ];
        }

        return $form_fields;
    }

    /**
     * SIBS Backend Payment Title.
     *
     * @param string $payment_id
     *
     * @return string
     */
    public static function sibs_backend_payment_title($payment_id)
    {
        return SibsGeneralFunctions::sibs_translate_backend_payment($payment_id);
    }

    /**
     * SIBS Backend Payment Description.
     *
     * @param string $payment_id
     *
     * @return string
     */
    public static function sibs_backend_payment_desc($payment_id)
    {
        return SibsGeneralFunctions::sibs_backend_payment_description($payment_id);
    }
}
