/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { Host, h } from "@stencil/core";
import cn from "../../global/lib/cn";
import { MaterialCard, MaterialCardChildren } from "../components/material-card";
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";
import distributerSchema from "../../locales/partLookup/distributor/type";
export class DistributorLookup {
    constructor() {
        // #region Localization
        this.language = 'en';
        this.locale = Object.assign({ sharedLocales: sharedLocalesSchema.getDefault() }, distributerSchema.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;
        // #region Component Logic
        // ===== Start 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.distributor', distributerSchema)]);
        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.partLookup ? this.localizationName || 'russian' : 'russian';
        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 partsInformation = [
            { label: this.locale.description, key: 'partDescription', value: (_c = this.partLookup) === null || _c === void 0 ? void 0 : _c.partDescription },
            { label: this.locale.productGroup, key: 'productGroup', value: (_d = this.partLookup) === null || _d === void 0 ? void 0 : _d.productGroup },
            {
                key: 'localDescription',
                value: (_e = this.partLookup) === null || _e === void 0 ? void 0 : _e.localDescription,
                label: this.locale.localDescription.replace('$', localName),
            },
            {
                key: 'purchasePrice',
                label: this.locale.dealerPurchasePrice,
                values: (_g = (_f = this.partLookup) === null || _f === void 0 ? void 0 : _f.prices) === null || _g === void 0 ? void 0 : _g.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.purchasePrice) === null || _a === void 0 ? void 0 : _a.formattedValue }); }),
            },
            {
                key: 'retailPrice',
                label: this.locale.recommendedRetailPrice,
                values: (_j = (_h = this.partLookup) === null || _h === void 0 ? void 0 : _h.prices) === null || _j === void 0 ? void 0 : _j.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.retailPrice) === null || _a === void 0 ? void 0 : _a.formattedValue }); }),
            },
            {
                key: 'supersededTo',
                label: this.locale.supersessions,
                values: (_l = (_k = this.partLookup) === null || _k === void 0 ? void 0 : _k.supersededTo) === null || _l === void 0 ? void 0 : _l.map(part => ({ header: null, body: part })),
            },
        ];
        const displayedFields = partsInformation.filter(part => !hiddenFields.includes(part.key));
        const tableHeaders = [
            {
                width: 300,
                key: 'locationName',
                label: this.locale.location,
            },
            {
                width: 300,
                key: 'quantityLookUpResult',
                label: this.locale.availability,
            },
        ];
        const displayDistributer = !((_m = this.partLookup) === null || _m === void 0 ? void 0 : _m.stockParts.some(({ quantityLookUpResult }) => quantityLookUpResult === 'LookupIsSkipped' || quantityLookUpResult === 'QuantityNotWithinLookupThreshold'));
        const rows = displayDistributer
            ? (_o = this.partLookup) === null || _o === void 0 ? void 0 : _o.stockParts.map(stock => ({
                locationName: stock.locationName,
                quantityLookUpResult: () => (h("div", { class: cn('text-[red]', {
                        'text-[green]': stock.quantityLookUpResult === 'Available',
                        'text-[orange]': stock.quantityLookUpResult === 'PartiallyAvailable',
                    }) }, h("strong", null, stock.quantityLookUpResult === 'Available'
                    ? this.locale.available
                    : stock.quantityLookUpResult === 'PartiallyAvailable'
                        ? this.locale.partiallyAvailable
                        : this.locale.notAvailable))),
            }))
            : [];
        return (h(Host, { key: '54e7fd2049ea95fefabeda4d5fe45c3860bdf38d', translate: "no" }, h(VehicleInfoLayout, { key: '3131507652e0a6f6f3abc731c8b61630faa1810d', isError: this.isError, coreOnly: this.coreOnly, isLoading: this.isLoading, header: (_p = this.partLookup) === null || _p === void 0 ? void 0 : _p.partNumber, direction: this.locale.sharedLocales.direction, errorMessage: this.locale.sharedLocales.errors[this.errorMessage] || this.locale.sharedLocales.errors.wildCard }, h("div", { key: '208500ae7e09a0fa365ba671abd55de9d76eaa25', class: "p-[16px]" }, h("div", { key: 'c105c303a592e061a36aad350e1ae3a226eb592a' }, h("flexible-container", { key: '7607e09a5775227a32da185b95fb767677d66037' }, h("div", { key: '06c646fa37e64366c99fc16305a00d000561f412', class: "flex [&>div]:grow overflow-auto gap-[16px] items-stretch justify-center md:justify-between flex-wrap" }, displayedFields.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-2 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" }))))), h("div", { key: 'cd1781bee592f7ed81f336798b19a61b657d400d', class: "mt-[32px] mx-auto w-fit max-w-full" }, h("div", { key: '9b37c8178c694aa144b212ff91289effc8a8cc3e', class: "bg-[#f6f6f6] h-[50px] flex items-center justify-center px-[16px] font-bold text-[18px]" }, this.locale.distributorStock), h("div", { key: '536900eb0969664b169b259d5e753509c4b9e5dd', class: "overflow-x-auto" }, h("information-table", { key: '019adc50fa83cd3ba3264f2aa0736830e69f54f7', isLoading: this.isLoading, rows: rows, headers: tableHeaders })))), h("manufacturer-part-lookup", { key: '91590830c0a91119b45456a8033751a71289d6af', standAlone: false, isDev: this.isDev, partLookup: this.partLookup, logId: (_q = this.partLookup) === null || _q === void 0 ? void 0 : _q.logId, closeManufacturerPartLookup: this.isLoading, manufacturerPartLookupTitle: this.manufacturerPartLookupTitle, manufacturerPartLookupEndpoint: this.manufacturerPartLookupEndpoint })))));
    }
    static get is() { return "distributor-lookup"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["distributor-lookup.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["distributor-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": true,
                "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": "''"
            },
            "manufacturerPartLookupTitle": {
                "type": "string",
                "attribute": "manufacturer-part-lookup-title",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "manufacturerPartLookupEndpoint": {
                "type": "string",
                "attribute": "manufacturer-part-lookup-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
            }
        };
    }
    static get states() {
        return {
            "locale": {},
            "searchString": {},
            "isError": {},
            "errorMessage": {},
            "partLookup": {},
            "isLoading": {},
            "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"
            }];
    }
}
