/**
 * Simplyin Payment - Check Email Availability Mixin
 * Wraps the original check-email-availability to resolve/reject with structured data.
 * Only activates when SimplyIN payment is enabled.
 */
define([
    'mage/utils/wrapper'
], function (wrapper) {
    'use strict';

    /**
     * Check if SimplyIN is enabled
     * @returns {Boolean}
     */
    function isSimplyinEnabled() {
        return !!(
            window.checkoutConfig &&
            window.checkoutConfig.payment &&
            window.checkoutConfig.payment.simplyin_payment &&
            window.checkoutConfig.payment.simplyin_payment.isActive
        );
    }

    return function (originalAction) {
        // If SimplyIN is not enabled, return original untouched
        if (!isSimplyinEnabled()) {
            return originalAction;
        }

        return wrapper.wrap(originalAction, function (original, deferred, email) {
            return original(deferred, email);
        });
    };
});
