(function () {
    'use strict';

    document.querySelectorAll('[data-abandoned-cart-discount]').forEach(function (container) {
        var discountType = container.querySelector('[data-discount-type]');
        var conditionalFields = container.querySelectorAll('[data-discount-field]');

        if (!discountType) {
            return;
        }

        function updateConditionalFields() {
            conditionalFields.forEach(function (field) {
                field.hidden = field.dataset.discountField !== discountType.value;
            });
        }

        discountType.addEventListener('change', updateConditionalFields);
        updateConditionalFields();
    });
})();
