let handleCustomerClick=function(e){var n=document.getElementById("customer-block"),o=document.getElementById("customer-company-block");"physical"===e?(n.classList.remove("d-none"),o.classList.add("d-none")):(n.classList.add("d-none"),o.classList.remove("d-none"))},handleOwnerClick=function(e){var n=document.getElementById("owner-block"),o=document.getElementById("owner-company-block");"physical"===e?(n.classList.remove("d-none"),o.classList.add("d-none")):(n.classList.add("d-none"),o.classList.remove("d-none"))};

// Bootstrap needs-validation
(function () {
    'use strict';
    var forms = document.querySelectorAll('.needs-validation');
    Array.prototype.slice.call(forms).forEach(function (form) {
        // Common required fields for both auto and estate
        var requiredNames = [
            'number', 'created_at', 'purpose_id',
            'customer_type', 'owner_type',
            'ordered_customer', 'cost',
            // auto specific
            'car_mark', 'car_number', 'body', 'engine', 'shassi', 'made_date', 'type',
            // estate specific
            'name_of_object', 'region', 'district', 'address', 'home', 'contract_date',
        ];
        requiredNames.forEach(function(name) {
            var el = form.querySelector('[name="' + name + '"]');
            if (el) el.setAttribute('required', '');
        });

        form.addEventListener('submit', function (event) {
            if (!form.checkValidity()) {
                event.preventDefault();
                event.stopPropagation();
                // Scroll to first invalid field
                var firstInvalid = form.querySelector(':invalid');
                if (firstInvalid) {
                    firstInvalid.scrollIntoView({ behavior: 'smooth', block: 'center' });
                    firstInvalid.focus();
                }
            }
            form.classList.add('was-validated');
        }, false);
    });
})();
