<?php

namespace Sibs2;

class sibsPaymentSettings
{
    public static function sibs_create_backend_payment_settings($payment_id)
    {
        $form_fields = [];

        $form_fields['enabled'] =  [
            'title'      => __('BACKEND_CH_ACTIVE', sibsConstants::SIBS_TRANSLATE),
            'type'       => 'checkbox',
            'default'    => '',
            'desc'       => '',
        ];

        $form_fields = array_merge_recursive(
            $form_fields,
            self::add_card_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),
            self::add_recurring_fields_in_form($payment_id),
            self::add_recurring_credit_card_fields_in_form($payment_id),
            self::add_paydirekt_fields_in_form($payment_id),
            self::add_klarnains_fields_in_form($payment_id)
        );

        $form_fields['payment_desc'] = [
            'title'    => __('BACKEND_CH_PAYMENTDESC', sibsConstants::SIBS_TRANSLATE),
            'type'     => 'textarea',
            'default'  => '',
            'desc'     => '',
        ];

        return $form_fields;
    }

    public static function add_card_fields_in_form($payment_id)
    {
        $form_fields        = [];
        $cardPaymentMethods = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD_SAVED,
        ];

        if (in_array($payment_id, $cardPaymentMethods)) {
            $form_fields['card_types'] = [
                'title'    => __('BACKEND_CH_CARDS', sibsConstants::SIBS_TRANSLATE),
                'type'     => 'multiselect',
                'css'      => 'height:12em;',
                'options'  => [
                    //'AMEX'          => __('BACKEND_CC_AMEX', sibsConstants::SIBS_TRANSLATE),
                    //'MAESTRO'       => __('BACKEND_CC_MAESTRO', sibsConstants::SIBS_TRANSLATE),
                    'MASTER'        => __('BACKEND_CC_MASTER', sibsConstants::SIBS_TRANSLATE),
                    'MASTERDEBIT'   => __('BACKEND_CC_MASTERDEBIT', sibsConstants::SIBS_TRANSLATE),
                    'VISA'          => __('BACKEND_CC_VISA', sibsConstants::SIBS_TRANSLATE),
                    'VISADEBIT'     => __('BACKEND_CC_VISADEBIT', sibsConstants::SIBS_TRANSLATE),
                    //'VISAELECTRON'  => __('BACKEND_CC_VISAELECTRON', sibsConstants::SIBS_TRANSLATE),
                    //'VPAY'          => __('BACKEND_CC_VPAY', sibsConstants::SIBS_TRANSLATE),
                ],
                'default'  => ['MASTER', 'VISA'],
                'desc'     => esc_attr(__('Hold Ctrl while selecting the card you want to activate the payment gateway for the selected card.', sibsConstants::SIBS_TRANSLATE)),
            ];
        }

        return $form_fields;
    }

    public static function add_auth_db_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_auth_db = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD_SAVED,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_DIRECT_DEBIT,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_DIRECT_DEBIT_SAVED,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_PAYDIREKT,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD,
        ];

        if (in_array($payment_id, $payment_auth_db)) {
            $form_fields['trans_mode'] = [
                'title'   => __('BACKEND_CH_MODE', sibsConstants::SIBS_TRANSLATE),
                'type'    => 'select',
                'options' => [
                    sibsConstants::SPG_PAYMENT_TYPE_PURS  => __('BACKEND_CH_MODEDEBIT', sibsConstants::SIBS_TRANSLATE),
                    sibsConstants::SPG_PAYMENT_TYPE_AUTH  => __('BACKEND_CH_MODEPREAUTH', sibsConstants::SIBS_TRANSLATE),
                ],
                'default'  => sibsConstants::SPG_PAYMENT_TYPE_PURS,
                'desc'     => '',
            ];
        }

        return $form_fields;
    }

    public static function add_pay_by_link_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_pay_by_link = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_PAY_BY_LINK,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_PAY_BY_LINK_KEVIN,
        ];

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

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

        return $form_fields;
    }

    public static function add_blik_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_blik = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_BLIK,
        ];

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

        //     $form_fields['sibs_retry_delay'] = [
        //         'title'    => __('SIBS Blik Retry Delay (seconds)', sibsConstants::SIBS_TRANSLATE),
        //         'type'     => 'text',
        //         'default'  => '1',
        //         'desc'     => '',
        //     ];
        // }

        return $form_fields;
    }

    public static function add_tokenization_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_tokenization = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD_SAVED,
        ];

        if (in_array($payment_id, $payment_tokenization)) {
            $form_fields['tokenization'] = [
                'title'   => __('BACKEND_CH_TOKENIZATION', sibsConstants::SIBS_TRANSLATE),
                'type'    => 'select',
                'options' => [
                    'none'              => __('BACKEND_BT_NONE', sibsConstants::SIBS_TRANSLATE),
                    'tokenization'      => __('BACKEND_BT_TOKENIZATION', sibsConstants::SIBS_TRANSLATE),
                    'oneclick'          => __('BACKEND_BT_ONECLICK', sibsConstants::SIBS_TRANSLATE),
                ],
                'default' => 'none',
            ];
        }

        return $form_fields;
    }

    public static function add_recurring_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_recurring = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD_SAVED,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_DIRECT_DEBIT_SAVED,
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_PAYPAL_SAVED,
        ];

        if (in_array($payment_id, $payment_recurring)) {
            $form_fields['amount_registration'] = [
                'title'       => __('BACKEND_CH_AMOUNT', sibsConstants::SIBS_TRANSLATE),
                'type'        => 'text',
                'default'     => '',
                'desc'        => __('BACKEND_TT_REGISTRATION_AMOUNT', sibsConstants::SIBS_TRANSLATE),
            ];
        }

        return $form_fields;
    }

    public static function add_recurring_credit_card_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_recurring_credit_card = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD_SAVED,
        ];

        if (in_array($payment_id, $payment_recurring_credit_card)) {
            $form_fields['multichannel'] = [
                'title'   => __('BACKEND_CH_MULTICHANNEL', sibsConstants::SIBS_TRANSLATE),
                'type'    => 'select',
                'options' => [
                    'true'  => __('BACKEND_BT_YES', sibsConstants::SIBS_TRANSLATE),
                    'false' => __('BACKEND_BT_NO', sibsConstants::SIBS_TRANSLATE),
                ],
                'default'  => 'false',
                'desc'     => __('BACKEND_TT_MULTICHANNEL', sibsConstants::SIBS_TRANSLATE),
            ];

            $form_fields['channel_moto'] = [
                'title'    => __('BACKEND_CH_MOTO', sibsConstants::SIBS_TRANSLATE),
                'type'     => 'text',
                'default'  => '',
                'desc'     => __('BACKEND_TT_CHANNEL_MOTO', sibsConstants::SIBS_TRANSLATE),
            ];
        }

        return $form_fields;
    }

    public static function add_paydirekt_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_paydirekt = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_PAYDIREKT,
        ];

        if (in_array($payment_id, $payment_paydirekt)) {
            $form_fields['minimum_age'] = [
                'title'    => __('BACKEND_CH_MINIMUM_AGE', sibsConstants::SIBS_TRANSLATE),
                'type'     => 'number',
                'default'  => '18',
                'desc'     => '',
            ];

            $form_fields['payment_is_partial'] = [
                'title'   => __('BACKEND_CH_PAYMENT_IS_PARTIAL', sibsConstants::SIBS_TRANSLATE),
                'type'    => 'select',
                'options' => [
                    'true'  => __('BACKEND_BT_YES', sibsConstants::SIBS_TRANSLATE),
                    'false' => __('BACKEND_BT_NO', sibsConstants::SIBS_TRANSLATE),
                ],
                'default'  => 'false',
                'desc'     => '',
            ];
        }

        return $form_fields;
    }

    public static function add_klarnains_fields_in_form($payment_id)
    {
        $form_fields = [];

        $payment_klarnains = [
            sibsConstants::SIBS_PAYMENT_METHOD_ORDER_KLARNAINS,
        ];

        if (in_array($payment_id, $payment_klarnains)) {
            $form_fields['pclass'] = [
                'title'       => __('BACKEND_CH_KLARNA_PCLASS', sibsConstants::SIBS_TRANSLATE),
                'type'        => 'text',
                'default'     => '',
                'desc'        => __('BACKEND_TT_KLARNAPCLASS', sibsConstants::SIBS_TRANSLATE),
            ];
        }

        return $form_fields;
    }

    public static function sibs_backend_payment_title($payment_id)
    {
        $paymentName = sibsGeneralFunctions::sibs_translate_backend_payment($payment_id);

        return $paymentName;
    }

    public static function sibs_backend_payment_desc($payment_id)
    {
        switch($payment_id) {
            case sibsConstants::SIBS_PAYMENT_METHOD_ORDER_CREDIT_CARD:
                return __('Accept Card payments from VISA and MasterCard.', sibsConstants::SIBS_TRANSLATE);

                break;
            case sibsConstants::SIBS_PAYMENT_METHOD_ORDER_BLIK:
                return __('Allow your clients to purchase online by authorizing the purchase in the Blik app.', sibsConstants::SIBS_TRANSLATE);

                break;
            case sibsConstants::SIBS_PAYMENT_METHOD_ORDER_PAY_BY_LINK:
                return __('Allow your clients to authorize purchase through Pay By Link.', sibsConstants::SIBS_TRANSLATE);

                break;
            case sibsConstants::SIBS_PAYMENT_METHOD_ORDER_PAY_BY_LINK_KEVIN:
                return __('Allow your clients to authorize purchase through Pay By Link Kevin.', sibsConstants::SIBS_TRANSLATE);

                break;
            default:
                return '';
        }
    }
}
