/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { Host, h } from "@stencil/core";
import saleInformationSchema from "../../locales/vehicleLookup/saleInformation/type";
import { MaterialCard } from "../components/material-card";
import { VehicleInfoLayout } from "../../features/vehicle-info-layout/index";
import { smartInvokable } from "../../features/blazor-ref/index";
import { setVehicleLookupData, setVehicleLookupErrorState } from "../../features/vehicle-lookup-component/vehicle-lookup-api-integration";
import { getLocaleLanguage, getSharedLocal, sharedLocalesSchema } from "../../features/multi-lingual/index";
import cn from "../../global/lib/cn";
import { TriangleAlertIcon } from "../../global/assets/triangle-alert";
import { UserIcon } from "../../global/assets/user-icon";
import { PhoneIcon } from "../../global/assets/phone-icon";
import { IdCardIcon } from "../../global/assets/id-card-icon";
export class VehicleSaleInformation {
    constructor() {
        // #region Localization
        this.language = 'en';
        this.locale = Object.assign({ sharedLocales: sharedLocalesSchema.getDefault() }, saleInformationSchema.getDefault());
        // #endregion
        // #region Vehicle info layout prop
        this.coreOnly = false;
        this.disableVinValidation = false;
        this.headers = {};
        this.queryString = '';
        this.isError = false;
        this.isLoading = false;
        this.hiddenFields = 'customerAccountNumber,customerID,brokerInvoiceNumber,brokerInvoiceDate,warrantyActivationDate,invoiceDate,invoiceNumber';
    }
    async componentWillLoad() {
        await this.changeLanguage(this.language);
    }
    async changeLanguage(newLanguage) {
        const [sharedLocales, locale] = await Promise.all([getSharedLocal(newLanguage), getLocaleLanguage(newLanguage, 'vehicleLookup.saleInformation', saleInformationSchema)]);
        this.locale = Object.assign({ sharedLocales }, locale);
    }
    async setBlazorRef(newBlazorRef) {
        this.blazorRef = newBlazorRef;
    }
    async setMockData(newMockData) {
        this.mockData = newMockData;
    }
    async fetchVin(newData, headers = {}) {
        await setVehicleLookupData(this, newData, headers);
    }
    async setErrorMessage(message) {
        setVehicleLookupErrorState(this, message);
    }
    onLoadingChange(newValue) {
        smartInvokable.bind(this)(this.loadingStateChange, newValue);
    }
    // #endregion
    formatDate(dateString) {
        if (!dateString)
            return '';
        try {
            const date = new Date(dateString);
            if (Number.isNaN(date.getTime()))
                return '';
            return date.toLocaleDateString(this.locale.sharedLocales.language, { year: 'numeric', month: 'long', day: '2-digit' });
        }
        catch (_a) {
            return '';
        }
    }
    render() {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
        const hiddenFields = ((_b = (_a = this.hiddenFields) === null || _a === void 0 ? void 0 : _a.split(',')) === null || _b === void 0 ? void 0 : _b.map(field => field.trim())) || [];
        const texts = this.locale;
        // @ts-ignore
        const sale = ((_c = this.vehicleLookup) === null || _c === void 0 ? void 0 : _c.saleInformation) || {};
        const getText = (v) => (v !== null && v !== void 0 ? v : '').toString().trim();
        // Manual toggle for UI testing (do not add logic yet)
        const hasEndCustomer = !!this.vehicleLookup && !!((_e = (_d = this.vehicleLookup) === null || _d === void 0 ? void 0 : _d.saleInformation) === null || _e === void 0 ? void 0 : _e.endCustomer);
        const END_CUSTOMER_FIELDS = [
            {
                fieldName: 'endCustomerName',
                title: texts.endCustomerName,
                value: getText((_f = sale === null || sale === void 0 ? void 0 : sale.endCustomer) === null || _f === void 0 ? void 0 : _f.name),
                Icon: UserIcon,
            },
            {
                fieldName: 'endCustomerPhone',
                title: texts.endCustomerPhone,
                value: getText((_g = sale === null || sale === void 0 ? void 0 : sale.endCustomer) === null || _g === void 0 ? void 0 : _g.phone),
                Icon: PhoneIcon,
            },
            {
                fieldName: 'endCustomerIdNumber',
                title: texts.endCustomerIdNumber,
                value: getText((_h = sale === null || sale === void 0 ? void 0 : sale.endCustomer) === null || _h === void 0 ? void 0 : _h.idNumber),
                Icon: IdCardIcon,
            },
        ];
        const FIELDS = [
            {
                fieldName: 'companyName',
                title: texts.companyName,
                value: getText(sale === null || sale === void 0 ? void 0 : sale.companyName),
            },
            {
                fieldName: 'branchName',
                title: texts.branchName,
                value: getText(sale === null || sale === void 0 ? void 0 : sale.branchName),
            },
            {
                fieldName: 'customerAccountNumber',
                title: texts.customerAccountNumber,
                value: getText(sale === null || sale === void 0 ? void 0 : sale.customerAccountNumber),
            },
            {
                fieldName: 'customerID',
                title: texts.customerID,
                value: getText(sale === null || sale === void 0 ? void 0 : sale.customerID),
            },
            // Broker
            {
                fieldName: 'brokerName',
                title: texts.brokerName,
                value: getText((_j = sale === null || sale === void 0 ? void 0 : sale.broker) === null || _j === void 0 ? void 0 : _j.brokerName),
            },
            {
                fieldName: 'brokerInvoiceNumber',
                title: texts.brokerInvoiceNumber,
                value: getText((_k = sale === null || sale === void 0 ? void 0 : sale.broker) === null || _k === void 0 ? void 0 : _k.invoiceNumber),
            },
            {
                fieldName: 'brokerInvoiceDate',
                title: texts.brokerInvoiceDate,
                value: this.formatDate((_l = sale === null || sale === void 0 ? void 0 : sale.broker) === null || _l === void 0 ? void 0 : _l.invoiceDate),
            },
            {
                fieldName: 'warrantyActivationDate',
                title: texts.warrantyActivationDate,
                value: getText(sale === null || sale === void 0 ? void 0 : sale.warrantyActivationDate),
            },
            {
                fieldName: 'invoiceDate',
                title: texts.invoiceDate,
                value: this.formatDate(sale === null || sale === void 0 ? void 0 : sale.invoiceDate),
            },
            {
                fieldName: 'invoiceNumber',
                title: texts.invoiceNumber,
                value: this.formatDate(sale === null || sale === void 0 ? void 0 : sale.invoiceNumber),
            },
        ];
        const filteredFields = FIELDS.filter(field => !hiddenFields.includes(field.fieldName));
        const filteredEndCustomerFields = END_CUSTOMER_FIELDS.filter(field => !hiddenFields.includes(field.fieldName));
        return (h(Host, { key: 'ff4f62eae1fda70aa3a34b19b68ceb27b19ba4fe', translate: "no" }, h(VehicleInfoLayout, { key: '895168920b58d9e8ac715033be9eb2193bf9b5d7', isError: this.isError, coreOnly: this.coreOnly, isLoading: this.isLoading, header: (_m = this.vehicleLookup) === null || _m === void 0 ? void 0 : _m.vin, direction: this.locale.sharedLocales.direction, errorMessage: this.locale.sharedLocales.errors[this.errorMessage] || this.locale.sharedLocales.errors.wildCard }, h("flexible-container", { key: '17016d85fdcc16e2269f3149c973cfcdd78eb9e2' }, h("flexible-container", { key: '08fe44174aeed8c6ea99f530465976840ff6deb4', classes: cn({ loading: this.isLoading || this.isError || !this.vehicleLookup }), isOpened: !!this.vehicleLookup && !this.isError }, h("div", { key: '6fac6fb5002d78e55952d0a50b9d320cf4a27fc9', class: "p-[16px] mx-auto !pb-0 max-w-[520px]" }, h("div", { key: '0042ba95ff45dee4002806afffa9d49fa5ed978b', class: cn('relative shift-skeleton !rounded-[12px] shift-card', { 'shift-card-warning': !hasEndCustomer }) }, h("div", { key: '2a2c069d199f726339b28cedade53ec0894c26c1', class: cn('absolute flex size-full left-0 top-0 px-[12px] items-center justify-center p-[12px] transition-opacity', !hasEndCustomer ? 'opacity-100' : 'opacity-0 pointer-events-none select-none') }, h("div", { key: 'ca83b9e16f0b43473738d7065857d0568f8e4fb7', class: "w-full max-w-[460px] rounded-[14px] px-[14px] py-[12px]" }, h("div", { key: 'eb6668cb387b3a048a871d652519114bfc0d95a2', class: "size-full flex flex-col justify-start gap-[12px] items-center" }, h("span", { key: '41215191381461fdcae26b92c82b56aa07223942', class: "shift-card-icon", "aria-hidden": "true" }, h(TriangleAlertIcon, { key: 'a837f95e52d94d84bd69bfd8cd8eb7b50a3c8dd4' })), h("p", { key: 'ca58dd61c21208eed9922c97c2fec4fa898a0341', class: "mt-[4px] text-[13.5px] text-center text-amber-900/90 leading-[1.35]" }, texts['Vehicle has no end customer.'] || '')))), h("div", { key: 'cb376f4b5bbfda6fd44f3511c0bfd9ea5ef343c0', class: cn('transition-opacity', !hasEndCustomer ? 'opacity-0 pointer-events-none select-none' : 'opacity-100') }, h("h2", { key: '8055be68136b19b5f87c5d2f6f5cee2da856361b', class: "shift-card-header" }, texts.customerInformation), h("div", { key: '5e42ac0e49ca400941d83e6b5ba9042505896f26', class: "flex flex-col gap-[2px]" }, filteredEndCustomerFields.map(field => {
            const value = field.value || '';
            const Icon = field.Icon;
            return (h("div", { class: "flex gap-[12px] items-start" }, h("span", { class: "shift-card-icon", "aria-hidden": "true" }, h(Icon, null)), h("div", { class: "flex flex-col translate-y-[-4px]" }, h("div", { class: "shift-card-seconary-text" }, field.title, ":"), h("div", { class: cn('shift-card-primary-text translate-y-[-4px]', { 'shift-card-empty-text': !value }) }, value || '—'))));
        })))))), h("div", { key: '55eb3648f5b16a0cb4569ed9d5cd16a28edc00ff', class: "flex p-[16px] [&>div]:grow overflow-auto gap-[16px] items-stretch justify-center md:justify-between flex-wrap" }, filteredFields.map(field => (h(MaterialCard, { title: field.title, desc: field.value, minWidth: "250px" }))))))));
    }
    static get is() { return "vehicle-sale-information"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["vehicle-sale-information.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["vehicle-sale-information.css"]
        };
    }
    static get properties() {
        return {
            "language": {
                "type": "string",
                "attribute": "language",
                "mutable": false,
                "complexType": {
                    "original": "LanguageKeys",
                    "resolved": "\"ar\" | \"en\" | \"ku\" | \"ru\"",
                    "references": {
                        "LanguageKeys": {
                            "location": "import",
                            "path": "~features/multi-lingual",
                            "id": "src/features/multi-lingual/index.ts::LanguageKeys"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'en'"
            },
            "coreOnly": {
                "type": "boolean",
                "attribute": "core-only",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "isDev": {
                "type": "boolean",
                "attribute": "is-dev",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "disableVinValidation": {
                "type": "boolean",
                "attribute": "disable-vin-validation",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "baseUrl": {
                "type": "string",
                "attribute": "base-url",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "headers": {
                "type": "unknown",
                "attribute": "headers",
                "mutable": false,
                "complexType": {
                    "original": "object",
                    "resolved": "object",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{}"
            },
            "queryString": {
                "type": "string",
                "attribute": "query-string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "errorCallback": {
                "type": "string",
                "attribute": "error-callback",
                "mutable": false,
                "complexType": {
                    "original": "BlazorInvokableFunction<(errorMessage: ErrorKeys) => void>",
                    "resolved": "((errorMessage: OptionalKeys<{ noBaseUrl: string; invalidVin: string; vinNumberRequired: string; partNumberRequired: string; wrongResponseFormat: string; noPartsFound: string; noServiceAvailable: string; wrongFormStructure: string; wildCard: string; requestFailedPleaseTryAgainLater: string; }>) => void) | string",
                    "references": {
                        "BlazorInvokableFunction": {
                            "location": "import",
                            "path": "~features/blazor-ref",
                            "id": "src/features/blazor-ref/index.ts::BlazorInvokableFunction"
                        },
                        "ErrorKeys": {
                            "location": "import",
                            "path": "~features/multi-lingual",
                            "id": "src/features/multi-lingual/index.ts::ErrorKeys"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "loadingStateChange": {
                "type": "string",
                "attribute": "loading-state-change",
                "mutable": false,
                "complexType": {
                    "original": "BlazorInvokableFunction<(isLoading: boolean) => void>",
                    "resolved": "((isLoading: boolean) => void) | string",
                    "references": {
                        "BlazorInvokableFunction": {
                            "location": "import",
                            "path": "~features/blazor-ref",
                            "id": "src/features/blazor-ref/index.ts::BlazorInvokableFunction"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "loadedResponse": {
                "type": "string",
                "attribute": "loaded-response",
                "mutable": false,
                "complexType": {
                    "original": "BlazorInvokableFunction<(response: VehicleLookupDTO) => void>",
                    "resolved": "((response: VehicleLookupDTO) => void) | string",
                    "references": {
                        "BlazorInvokableFunction": {
                            "location": "import",
                            "path": "~features/blazor-ref",
                            "id": "src/features/blazor-ref/index.ts::BlazorInvokableFunction"
                        },
                        "VehicleLookupDTO": {
                            "location": "import",
                            "path": "~types/generated/vehicle-lookup/vehicle-lookup-dto",
                            "id": "src/global/types/generated/vehicle-lookup/vehicle-lookup-dto.ts::VehicleLookupDTO"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "hiddenFields": {
                "type": "string",
                "attribute": "hidden-fields",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'customerAccountNumber,customerID,brokerInvoiceNumber,brokerInvoiceDate,warrantyActivationDate,invoiceDate,invoiceNumber'"
            }
        };
    }
    static get states() {
        return {
            "locale": {},
            "blazorRef": {},
            "isError": {},
            "errorMessage": {},
            "isLoading": {},
            "vehicleLookup": {}
        };
    }
    static get methods() {
        return {
            "setBlazorRef": {
                "complexType": {
                    "signature": "(newBlazorRef: DotNetObjectReference) => Promise<void>",
                    "parameters": [{
                            "name": "newBlazorRef",
                            "type": "{ invokeMethodAsync: (methodName: string, ...args: any[]) => Promise<any>; }",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "DotNetObjectReference": {
                            "location": "import",
                            "path": "~features/blazor-ref",
                            "id": "src/features/blazor-ref/index.ts::DotNetObjectReference"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "setMockData": {
                "complexType": {
                    "signature": "(newMockData: VehicleLookupMock) => Promise<void>",
                    "parameters": [{
                            "name": "newMockData",
                            "type": "{ [key: string]: VehicleLookupDTO; }",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "VehicleLookupMock": {
                            "location": "import",
                            "path": "~features/vehicle-lookup-component",
                            "id": "src/features/vehicle-lookup-component/index.ts::VehicleLookupMock"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "fetchVin": {
                "complexType": {
                    "signature": "(newData: VehicleLookupDTO | string, headers?: any) => Promise<void>",
                    "parameters": [{
                            "name": "newData",
                            "type": "string | VehicleLookupDTO",
                            "docs": ""
                        }, {
                            "name": "headers",
                            "type": "any",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "VehicleLookupDTO": {
                            "location": "import",
                            "path": "~types/generated/vehicle-lookup/vehicle-lookup-dto",
                            "id": "src/global/types/generated/vehicle-lookup/vehicle-lookup-dto.ts::VehicleLookupDTO"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "setErrorMessage": {
                "complexType": {
                    "signature": "(message: ErrorKeys) => Promise<void>",
                    "parameters": [{
                            "name": "message",
                            "type": "\"noBaseUrl\" | \"invalidVin\" | \"vinNumberRequired\" | \"partNumberRequired\" | \"wrongResponseFormat\" | \"noPartsFound\" | \"noServiceAvailable\" | \"wrongFormStructure\" | \"wildCard\" | \"requestFailedPleaseTryAgainLater\"",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "ErrorKeys": {
                            "location": "import",
                            "path": "~features/multi-lingual",
                            "id": "src/features/multi-lingual/index.ts::ErrorKeys"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "language",
                "methodName": "changeLanguage"
            }, {
                "propName": "isLoading",
                "methodName": "onLoadingChange"
            }];
    }
}
