/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { Host, h } from "@stencil/core";
import { MaterialCard, MaterialCardChildren } from "../components/material-card";
import manufacturerSchema from "../../locales/partLookup/manufacturer/type";
import { getMockFile } from "../../features/mocks/index";
import { VehicleInfoLayout } from "../../features/vehicle-info-layout/index";
import { smartInvokable } from "../../features/blazor-ref/index";
import { setPartLookupData, setPartLookupErrorState } from "../../features/part-lookup-components/index";
import { getLocaleLanguage, getSharedLocal, sharedLocalesSchema } from "../../features/multi-lingual/index";
export class ManufacturerLookup {
    constructor() {
        // #region Localization
        this.language = 'en';
        this.locale = Object.assign({ sharedLocales: sharedLocalesSchema.getDefault() }, manufacturerSchema.getDefault());
        // #endregion
        // #region Vehicle info layout prop
        this.coreOnly = false;
        // #endregion
        // #region Part Lookup Component Shared Logic
        this.mockUrl = '';
        this.isError = false;
        this.isLoading = false;
        // #endregion
        // #region Component Logic
        this.hiddenFields = '';
        this.localizationName = '';
    }
    async componentWillLoad() {
        await Promise.all([this.changeLanguage(this.language), this.onIsDevChange(this.isDev)]);
    }
    async changeLanguage(newLanguage) {
        const [sharedLocales, locale] = await Promise.all([getSharedLocal(newLanguage), getLocaleLanguage(newLanguage, 'partLookup.manufacturer', manufacturerSchema)]);
        this.locale = Object.assign({ sharedLocales }, locale);
    }
    async setMockData(newMockData) {
        this.mockData = newMockData;
        smartInvokable.bind(this)(this.loadedMockDatas, newMockData);
    }
    async getMockData() {
        return this.mockData;
    }
    async onIsDevChange(isDev) {
        if (!isDev)
            return;
        const mockData = await getMockFile('part-lookup', this.mockUrl);
        await this.setMockData(mockData);
    }
    async fetchData(newData) {
        await setPartLookupData(this, newData);
    }
    async setErrorMessage(message) {
        setPartLookupErrorState(this, message);
    }
    onLoadingChange(newValue) {
        smartInvokable.bind(this)(this.loadingStateChange, newValue);
    }
    async setBlazorRef(newBlazorRef) {
        this.blazorRef = newBlazorRef;
    }
    // #endregion
    render() {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
        const localName = this.localizationName || '';
        const hiddenFields = ((_a = this.hiddenFields) === null || _a === void 0 ? void 0 : _a.split(',').map(field => field === null || field === void 0 ? void 0 : field.trim())) || [];
        const manufacturerData = [
            { label: this.locale.origin, key: 'origin', value: (_b = this.partLookup) === null || _b === void 0 ? void 0 : _b.origin },
            {
                label: this.locale.warrantyPrice,
                key: 'warrantyPrice',
                values: (_c = this.partLookup) === null || _c === void 0 ? void 0 : _c.prices.map(price => {
                    var _a;
                    return { header: price === null || price === void 0 ? void 0 : price.countryName, body: (_a = price === null || price === void 0 ? void 0 : price.warrantyPrice) === null || _a === void 0 ? void 0 : _a.formattedValue };
                }),
            },
            { label: this.locale.specialPrice, key: 'specialPrice' },
            { label: this.locale.wholesalesPrice, key: 'salesPrice' },
            { label: this.locale.pnc, key: 'pnc', value: (_d = this.partLookup) === null || _d === void 0 ? void 0 : _d.pnc },
            { label: this.locale.pncName.replace('$', localName), key: 'pnc', value: (_e = this.partLookup) === null || _e === void 0 ? void 0 : _e.pnc },
            { label: this.locale.binCode, key: 'binType', value: (_f = this.partLookup) === null || _f === void 0 ? void 0 : _f.binType },
            { label: this.locale.length, key: 'length', value: (_g = this.partLookup) === null || _g === void 0 ? void 0 : _g.length },
            { label: this.locale.width, key: 'width', value: (_h = this.partLookup) === null || _h === void 0 ? void 0 : _h.width },
            { label: this.locale.height, key: 'height', value: (_j = this.partLookup) === null || _j === void 0 ? void 0 : _j.height },
            { label: this.locale.netWeight, key: 'netWeight', value: (_k = this.partLookup) === null || _k === void 0 ? void 0 : _k.netWeight },
            { label: this.locale.grossWeight, key: 'grossWeight', value: (_l = this.partLookup) === null || _l === void 0 ? void 0 : _l.grossWeight },
            { label: this.locale.cubicMeasure, key: 'cubicMeasure', value: (_m = this.partLookup) === null || _m === void 0 ? void 0 : _m.cubicMeasure },
            { label: this.locale.hsCode, key: 'hsCode', value: (_o = this.partLookup) === null || _o === void 0 ? void 0 : _o.hsCode },
            { label: this.locale.uzHsCode, key: 'hsCode', value: (_p = this.partLookup) === null || _p === void 0 ? void 0 : _p.hsCode },
        ];
        const displayedManufacturerData = manufacturerData.filter(part => !hiddenFields.includes(part.key));
        return (h(Host, { translate: "no" }, h(VehicleInfoLayout, { isError: this.isError, coreOnly: this.coreOnly, isLoading: this.isLoading, header: (_q = this.partLookup) === null || _q === void 0 ? void 0 : _q.partNumber, direction: this.locale.sharedLocales.direction, errorMessage: this.locale.sharedLocales.errors[this.errorMessage] || this.locale.sharedLocales.errors.wildCard }, h("flexible-container", null, h("div", { class: "flex p-[16px] [&>div]:grow overflow-auto gap-[16px] items-stretch justify-center md:justify-between flex-wrap" }, displayedManufacturerData.map(({ label, value, values }) => values ? (h(MaterialCard, { title: label, minWidth: "250px" }, h(MaterialCardChildren, { class: "flex flex-wrap gap-[8px] p-[2px]" }, values
            .filter(x => x.body)
            .map(x => (h("span", { class: "inline-flex items-center bg-red-50 text-red-800 font-medium px-3 text-[16px] py-1 me-1 mt-2 rounded-lg border border-red-300" }, x.header && h("span", { class: "font-semibold" }, x.header, ":"), h("span", { class: "ml-1" }, x.body))))))) : (h(MaterialCard, { desc: (value === null || value === void 0 ? void 0 : value.toString()) || '', title: label, minWidth: "250px" }))))))));
    }
    static get is() { return "manufacturer-lookup"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["manufacturer-lookup.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["manufacturer-lookup.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"
            },
            "mockUrl": {
                "type": "string",
                "attribute": "mock-url",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "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
            },
            "endpoint": {
                "type": "string",
                "attribute": "endpoint",
                "mutable": false,
                "complexType": {
                    "original": "Endpoint",
                    "resolved": "string | { url: string; body?: object; headers?: object; method?: string; query?: QueryString; }",
                    "references": {
                        "Endpoint": {
                            "location": "import",
                            "path": "~lib/fetch-from",
                            "id": "src/global/lib/fetch-from.ts::Endpoint"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "loadedMockDatas": {
                "type": "string",
                "attribute": "loaded-mock-datas",
                "mutable": true,
                "complexType": {
                    "original": "BlazorInvokableFunction<(response: any) => void>",
                    "resolved": "((response: any) => 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
            },
            "errorCallback": {
                "type": "string",
                "attribute": "error-callback",
                "mutable": true,
                "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": true,
                "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": true,
                "complexType": {
                    "original": "BlazorInvokableFunction<(response: PartLookupDTO) => void>",
                    "resolved": "((response: PartLookupDTO) => void) | string",
                    "references": {
                        "BlazorInvokableFunction": {
                            "location": "import",
                            "path": "~features/blazor-ref",
                            "id": "src/features/blazor-ref/index.ts::BlazorInvokableFunction"
                        },
                        "PartLookupDTO": {
                            "location": "import",
                            "path": "~types/generated/part/part-lookup-dto",
                            "id": "src/global/types/generated/part/part-lookup-dto.ts::PartLookupDTO"
                        }
                    }
                },
                "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": "''"
            },
            "localizationName": {
                "type": "string",
                "attribute": "localization-name",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            }
        };
    }
    static get states() {
        return {
            "locale": {},
            "searchString": {},
            "isError": {},
            "errorMessage": {},
            "isLoading": {},
            "partLookup": {},
            "blazorRef": {}
        };
    }
    static get methods() {
        return {
            "setMockData": {
                "complexType": {
                    "signature": "(newMockData: PartLookupMock) => Promise<void>",
                    "parameters": [{
                            "name": "newMockData",
                            "type": "{ [key: string]: PartLookupDTO; }",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "PartLookupMock": {
                            "location": "import",
                            "path": "~features/part-lookup-components",
                            "id": "src/features/part-lookup-components/index.ts::PartLookupMock"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "getMockData": {
                "complexType": {
                    "signature": "() => Promise<any>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<any>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "fetchData": {
                "complexType": {
                    "signature": "(newData: PartLookupDTO | string) => Promise<void>",
                    "parameters": [{
                            "name": "newData",
                            "type": "string | PartLookupDTO",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "PartLookupDTO": {
                            "location": "import",
                            "path": "~types/generated/part/part-lookup-dto",
                            "id": "src/global/types/generated/part/part-lookup-dto.ts::PartLookupDTO"
                        }
                    },
                    "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": []
                }
            },
            "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": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "language",
                "methodName": "changeLanguage"
            }, {
                "propName": "isDev",
                "methodName": "onIsDevChange"
            }, {
                "propName": "isLoading",
                "methodName": "onLoadingChange"
            }];
    }
}
