import { BaseAddressModel } from "@insite/client-framework/Types/ApiModels";

export const areAddressesTheSame = (address1: BaseAddressModel, address2: BaseAddressModel) => {
    return (
        address1.firstName === address2.firstName &&
        address1.lastName === address2.lastName &&
        address1.attention === address2.attention &&
        address1.companyName === address2.companyName &&
        address1.address1 === address2.address1 &&
        address1.address2 === address2.address2 &&
        address1.address3 === address2.address3 &&
        address1.address4 === address2.address4 &&
        address1.country?.id === address2.country?.id &&
        address1.city === address2.city &&
        address1.state?.id === address2.state?.id &&
        address1.postalCode === address2.postalCode &&
        address1.phone === address2.phone &&
        address1.email === address2.email &&
        address1.fax === address2.fax
    );
};

export const scrollToFirstFormError = () => {
    const firstErrorElement = document.querySelector("[aria-invalid='true']");
    if (firstErrorElement) {
        const formFieldParent = firstErrorElement.closest("[class*='FormFieldStyle']");
        if (!formFieldParent) {
            return;
        }
        const { top } = formFieldParent.getBoundingClientRect();
        window.scrollTo({
            top: top + window.pageYOffset,
            left: 0,
            behavior: "smooth",
        });
    }
};
