<?php
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<script>
require([
    'jquery',
    'mage/mage'
], function($) {
    $('#support_topic_value').change(function() {
        // enable/disable the submit button
        let topic = $("#support_topic_value").val();

        if (0 !== topic.length) {
            $('#adyen_support-need-help').prop('disabled', false);
        } else {
            $('#adyen_support-need-help').prop('disabled', true);
        }
    });

    const linksMapping = {
        required_settings: [
            {
                title: 'Adobe Commerce plugin setup',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/set-up-the-plugin-in-adobe-commerce/'
            },
            {
                title: 'How to request a new merchant account',
                href: 'https://www.adyen.com/education/europe/english/modules/customer-area'
            },
            {
                title: 'Why is Apple pay not working',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/drop-in-and-components/why-do-i-receive-a-422-error-with-apple-pay-when-using-adyens-certificate'
            },
            {
                title: 'Go-live checklist',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/go-live-checklist'
            },
            {
                title: 'Troubleshooting guide',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/troubleshooting/'
            },
            {
                title: 'Why do I get the error 401 Unauthorized?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/error-codes/why-do-i-get-the-error-401-unauthorized'
            }
        ],
        card_payments: [
            {
                title: 'How to configure card payments ',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/set-up-the-payment-methods-in-adobe-commerce'
            },
            {
                title: 'What are supported schemes?',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/supported-payment-methods'
            },
            {
                title: '3D Secure 2 Component integration',
                href: 'https://docs.adyen.com/online-payments/3d-secure/native-3ds2/web-component?utm_source=ca_test'
            }
        ],
        card_tokenization: [
            {
                title: 'How to set up tokenization',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/set-up-tokenization'
            },
            {
                title: 'Video: How to set up tokenization',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/how-do-i-set-up-tokenization-in-adobe-commerce'
            },
            {
                title: 'Difference between One-off, Subscription and Top-ups',
                href: 'https://docs.adyen.com/online-payments/tokenization/create-and-use-tokens?tab=one_off_payments_1#create-a-token'
            },
            {
                title: 'Why do I receive a 800 Contract not found error?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/error-codes/why-do-i-receive-a-800-contract-not-found-error'
            },
            {
                title: 'Why do I receive a 803 PaymentDetail not found error?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/error-codes/why-do-i-receive-a-803-paymentdetail-not-found-error'
            },
            {
                title: 'Why does my recurring transaction give the error "invalid card number"?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/tokenization/why-does-my-recurring-transaction-give-the-error-invalid-card-number'
            }
        ],
        alt_payment_methods: [
            {
                title: 'Why are Adyen alternative payment methods not showing up in Adobe Commerce?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/why-arent-all-payment-methods-displayed-adobe-commerce'
            },
            {
                title: 'Supported Payment Methods',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/supported-payment-methods/'
            },
            {
                title: 'How to add payment methods in Customer Area',
                href: 'https://docs.adyen.com/point-of-sale/payment-methods#add-payment-methods-to-your-account'
            },
            {
                title: 'How do I deactivate or delete a payment method?',
                href: 'https://help.adyen.com/knowledge/payment-methods/manage-payment-methods/how-do-i-deactivate-or-delete-a-payment-method'
            },
            {
                title: 'Video: How to add payment methods in Customer Area',
                href: 'https://www.adyen.com/education/europe/english/modules/customer-area'
            },
            {
                title: 'How can we change the order of the payment methods inside Adobe Commerce 2?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/how-can-i-change-the-order-of-the-payment-methods-adobe-commerce'
            }
        ],
        pos_integration: [
            {
                title: 'Video: How to board, assign and troubleshoot a terminal',
                href: 'https://www.adyen.com/education/europe/english/modules/in-person-payments'
            },
            {
                title: 'How to troubleshoot a terminal',
                href: 'https://docs.adyen.com/point-of-sale/pos-troubleshooting?utm_source=ca_test'
            }
        ],
        pay_by_link: [
            {
                title: 'How to set up Pay By Link in the plugin',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/set-up-the-payment-methods-in-adobe-commerce/#pay-by-link'
            },
            {
                title: 'Video: How to set up PayByLink',
                href: 'https://help.adyen.com/academy/how-to-videos/plugins/how-to-set-up-pay-by-link-in-your-adobe-commerce-plugin'
            }
        ],
        adyen_giving: [
            {
                title: 'How to set up Donations in the plugin',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/set-up-the-payment-methods-in-adobe-commerce/#donations'
            },
            {
                title: 'Video: How to set up Adyen Giving',
                href: 'https://help.adyen.com/academy/how-to-videos/plugins/how-to-set-up-giving-in-your-adobe-commerce-plugin'
            }
        ],
        advanced_settings: [
            {
                title: 'Why does the order status in Adobe Commerce remain on "Payment Review"?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/why-is-my-payment-pending-in-adobe-commerce'
            },
            {
                title: 'Why is the text in Adobe Commerce not being translated?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/why-is-the-text-in-adobe-commerce-not-being-translated'
            },
            {
                title: 'How can we customise the Adobe Commerce plugin?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/how-can-we-customise-the-adobe-commerce-plugin'
            },
            {
                title: 'Why is my order status Settled or SentForSettle after I refunded it on Adobe Commerce?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/why-is-my-order-status-settled-or-sentforsettle-after-i-refunded-it-on-adobe-commerce'
            },
            {
                title: 'Why are Klarna payments stuck in Pending?',
                href: 'https://help.adyen.com/knowledge/plugins/using-plugins/why-are-klarna-payments-still-pending'
            },
            {
                title: 'How can I change the capture settings of my payment method?',
                href: 'https://help.adyen.com/knowledge/payment-methods/manage-payment-methods/how-can-i-change-the-capture-settings-of-my-payment-method'
            }
        ],
        payment_status: [
            {
                title: 'Why is my order status Settled or SentForSettle after I refunded it on Adobe Commerce?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/why-is-my-order-status-settled-or-sentforsettle-after-i-refunded-it-on-adobe-commerce'
            },
            {
                title: 'Why are Klarna payments stuck in Pending?',
                href: 'https://help.adyen.com/knowledge/plugins/using-plugins/why-are-klarna-payments-still-pending'
            },
        ],
        failed_transaction: [
            {
                title: 'What does it mean if a payment is refused because 3d-secure: Authentication failed?',
                href: 'https://help.adyen.com/knowledge/3d-secure/3ds-response-codes/what-does-it-mean-if-a-payment-is-refused-because-3d-secure-authentication-failed'
            },
            {
                title: 'Why is my payment canceled?',
                href: 'https://help.adyen.com/knowledge/payments/payment-statuses/why-is-my-payment-canceled'
            },
            {
                title: 'Why do I receive a 905 Payment details are not supported error?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/error-codes/why-do-i-receive-a-905-payment-details-are-not-supported-error'
            },
            {
                title: 'Why do I receive a 403 or 010 Not Allowed error?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/error-codes/why-do-i-receive-a-403-or-010-not-allowed-error'
            },
            {
                title: 'Why do I receive the error 422 : Unable to Decrypt Data using the Card Component or Drop-In?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/drop-in-and-components/why-do-i-receive-the-error-422-unable-to-decrypt-data-using-the-card-component-or-dropin'
            },
            {
                title: 'Why do I receive a 807 Invalid combination of shopper interaction and recurring contract error?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/error-codes/why-do-i-receive-a-807-invalid-combination-of-shopper-interaction-and-recurring-contract-error'
            },
            {
                title: 'Why do I get errorCode 908: invalid request with HTTP status 500?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/error-codes/why-do-i-get-errorcode-908-invalid-request-with-http-status-500'
            }
        ],
        offer: [
            {
                title: 'Why does the order status in Adobe Commerce remain on "Payment Review"?',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/troubleshooting/#orders'
            }
        ],
        webhooks: [
            {
                title: 'How to set up notifications in Customer Area',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/set-up-adyen-customer-area/?tab=manual_2#step-3-set-up-webhooks'
            },
            {
                title: 'Why does the order status in Adobe Commerce remain on "Payment Review"?',
                href: 'https://docs.adyen.com/plugins/adobe-commerce/troubleshooting/#orders'
            },
            {
                title: 'Why does Adobe Commerce not receive notifications?',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/why-does-adobe-commerce-does-not-receive-notifications'
            },
            {
                title: 'I get a 301, 302 or 401 error in Adobe Commerce when testing the notification endpoint',
                href: 'https://help.adyen.com/knowledge/plugins/adobe-commerce/why-am-i-receiving-301-302-or-401-error-in-adobe-commerce'
            },
            {
                title: 'How can I get additional data in standard Notifications?',
                href: 'https://help.adyen.com/knowledge/ecommerce-integrations/webhooks/how-can-i-get-additional-data-in-standard-webhooks'
            }
        ]
    };

    $('#support_topic_value').on('change', function (event) {
        let linksHtml = '';
        if (!!this.value.length) {
            let topics = linksMapping[this.value];
            if (!!topics.length) {
                linksHtml += '<ul>';
                for (i = 0; i < topics.length; i++) {
                    linksHtml += '<li><a target="_blank" href="' + topics[i].href + '">' + topics[i].title + '</a></li>';
                }
                linksHtml += '</ul>';
            }
        }
        $('.adyen_support-links').html(linksHtml);
    })

    $('#support_form').mage('form').mage('validation', {});
});
</script>
