/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { Host, h } from "@stencil/core";
import cn from "../../global/lib/cn";
import Eye from "~assets/eye.svg";
import { CalendarDaysIcon } from "../../global/assets/calendar-days-icon";
import paintThicknessSchema from "../../locales/vehicleLookup/paintThickness/type";
import { VehicleInfoLayout } from "../../features/vehicle-info-layout/index";
import { closeImageViewer, ImageViewer, openImageViewer } from "../../features/image-viewer/index";
import { smartInvokable } from "../../features/blazor-ref/index";
import { setVehicleLookupData, setVehicleLookupErrorState } from "../../features/vehicle-lookup-component/index";
import { getLocaleLanguage, getSharedLocal, sharedLocalesSchema } from "../../features/multi-lingual/index";
export class VehiclePaintThickness {
    constructor() {
        // #region Localization
        this.language = 'en';
        this.locale = Object.assign({ sharedLocales: sharedLocalesSchema.getDefault() }, paintThicknessSchema.getDefault());
        // #endregion
        // #region Vehicle info layout prop
        this.coreOnly = false;
        // #endregion
        // #region Image Viewer Logic
        this.expandedImage = '';
        this.disableVinValidation = false;
        this.headers = {};
        this.queryString = '';
        this.isError = false;
        this.isLoading = false;
        // #endregion
        // #region Tab Logic
        this.activeTabIndex = 0;
        this.onActiveTabChange = ({ idx }) => {
            this.activeTabIndex = idx;
        };
        // #endregion
        this.groupPanels = (panels) => {
            const groups = new Map();
            for (const p of panels) {
                const key = `${p.panelType}|${p.panelPosition || ''}`;
                if (!groups.has(key)) {
                    groups.set(key, { panel: p.panelType, position: p.panelPosition || '' });
                }
                const row = groups.get(key);
                if (p.panelSide === 'Left')
                    row.left = p.measuredThickness;
                else if (p.panelSide === 'Right')
                    row.right = p.measuredThickness;
                else
                    row.center = p.measuredThickness;
            }
            return Array.from(groups.values());
        };
    }
    async componentWillLoad() {
        await this.changeLanguage(this.language);
    }
    async changeLanguage(newLanguage) {
        const [sharedLocales, locale] = await Promise.all([getSharedLocal(newLanguage), getLocaleLanguage(newLanguage, 'vehicleLookup.paintThickness', paintThicknessSchema)]);
        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);
    }
    onVehicleLookupChange() {
        this.activeTabIndex = 0;
    }
    render() {
        var _a, _b;
        const texts = this.locale;
        const inspections = ((_a = this.vehicleLookup) === null || _a === void 0 ? void 0 : _a.paintThicknessInspections) || [];
        const tabs = inspections.map((inspection, idx) => {
            const isDuplicate = inspections.some((other, otherIdx) => otherIdx !== idx && other.source === inspection.source);
            return isDuplicate && inspection.inspectionDate ? `${inspection.source} (${inspection.inspectionDate})` : inspection.source;
        });
        const hideTabs = this.isLoading || this.isError;
        const activeInspection = inspections[this.activeTabIndex] || inspections[0];
        const panels = (activeInspection === null || activeInspection === void 0 ? void 0 : activeInspection.panels) || [];
        const groupedRows = this.groupPanels(panels);
        const imageGroups = panels
            .filter(panel => { var _a; return (_a = panel.images) === null || _a === void 0 ? void 0 : _a.length; })
            .map(panel => ({
            name: [panel.panelPosition, panel.panelSide, panel.panelType].filter(Boolean).join(' '),
            images: panel.images,
        }));
        const colWidths = { panel: 200, position: 200, side: 150 };
        return (h(Host, { translate: "no" }, h(ImageViewer, { closeImageViewer: () => closeImageViewer.bind(this)(), expandedImage: this.expandedImage }), h(VehicleInfoLayout, { isError: this.isError, coreOnly: this.coreOnly, isLoading: this.isLoading, header: (_b = this.vehicleLookup) === null || _b === void 0 ? void 0 : _b.vin, direction: this.locale.sharedLocales.direction, errorMessage: this.locale.sharedLocales.errors[this.errorMessage] || this.locale.sharedLocales.errors.wildCard }, h("div", { class: cn('duration-300', 'py-[15px]', { hidden: hideTabs }) }, h("shift-tabs", { activeTabIndex: this.activeTabIndex, changeActiveTab: this.onActiveTabChange, tabs: tabs })), h("flexible-container", { isOpened: !this.isLoading && !!(activeInspection === null || activeInspection === void 0 ? void 0 : activeInspection.inspectionDate) }, h("div", { class: "flex items-center justify-center gap-[6px] border-b border-slate-200 px-[16px] py-[10px] text-[16px] text-slate-700" }, h(CalendarDaysIcon, { class: "size-[18px] shrink-0" }), h("span", { class: "font-semibold" }, texts.inspectionDate, ":"), h("span", { class: "shift-skeleton" }, activeInspection === null || activeInspection === void 0 ? void 0 : activeInspection.inspectionDate))), h("div", { class: "overflow-x-auto" }, h("div", { class: cn('mx-auto w-fit', { loading: this.isLoading }) }, h("div", { class: "flex" }, h("div", { class: "font-semibold border-b py-[16px] px-[16px] text-center", style: { width: `${colWidths.panel}px` } }, texts.panel), h("div", { class: "font-semibold border-b py-[16px] px-[16px] text-center", style: { width: `${colWidths.position}px` } }, texts.position), h("div", { class: "font-semibold border-b py-[16px] px-[16px] text-center", style: { width: `${colWidths.side}px` } }, texts.left), h("div", { class: "font-semibold border-b py-[16px] px-[16px] text-center", style: { width: `${colWidths.side}px` } }, texts.right)), h("flexible-container", { height: "auto" }, !groupedRows.length && (h("div", { class: "border-b" }, h("div", { class: "flex" }, h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.panel}px` } }, h("div", { class: "shift-skeleton" }, "\u00A0")), h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.position}px` } }, h("div", { class: "shift-skeleton" }, "\u00A0")), h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.side}px` } }, h("div", { class: "shift-skeleton" }, "\u00A0")), h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.side}px` } }, h("div", { class: "shift-skeleton" }, "\u00A0"))))), groupedRows.map((row, idx) => (h("div", { key: row.panel + row.position + idx, class: "border-b last:border-b-0" }, h("div", { class: cn('flex hover:bg-sky-100/50 transition duration-300', { 'bg-slate-100': idx % 2 === 1 }) }, h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.panel}px` } }, h("div", { class: "shift-skeleton" }, row.panel)), h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.position}px` } }, h("div", { class: "shift-skeleton" }, row.position || '\u00A0')), row.center !== undefined ? (h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.side * 2}px` } }, h("div", { class: "shift-skeleton" }, row.center))) : ([
            h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.side}px` } }, h("div", { class: "shift-skeleton" }, row.left !== undefined ? row.left : '\u00A0')),
            h("div", { class: "px-[16px] py-[16px] text-center my-auto", style: { width: `${colWidths.side}px` } }, h("div", { class: "shift-skeleton" }, row.right !== undefined ? row.right : '\u00A0')),
        ])))))))), h("flexible-container", { isOpened: !this.isLoading && !!(imageGroups === null || imageGroups === void 0 ? void 0 : imageGroups.length) }, h("div", { class: "py-[16px] gap-[16px] justify-center flex flex-wrap px-[24px] w-full" }, imageGroups === null || imageGroups === void 0 ? void 0 : imageGroups.map((imageGroup, index) => (h("div", { class: "shrink-0 rounded-lg shadow-sm border overflow-hidden flex flex-col", key: (imageGroup === null || imageGroup === void 0 ? void 0 : imageGroup.name) + index }, h("h1", { class: "text-center border-b bg-slate-50 font-semibold p-[6px]" }, h("span", { class: "shift-skeleton" }, imageGroup === null || imageGroup === void 0 ? void 0 : imageGroup.name)), h("div", { class: "flex max-w-full flex-wrap p-[12px] gap-[8px]" }, imageGroup === null || imageGroup === void 0 ? void 0 : imageGroup.images.map((image, idx) => (h("div", { class: cn('flex shift-skeleton gap-[8px]', { loading: !image }), key: image + idx }, h("button", { onClick: ({ target }) => openImageViewer.bind(this)(target, image), class: "shrink-0 relative ring-0 outline-none w-fit mx-auto [&_img]:hover:shadow-lg [&_div]:hover:!opacity-100 cursor-pointer" }, h("div", { class: "absolute flex-col justify-center gap-[4px] size-full flex items-center pointer-events-none hover:opacity-100 rounded-lg opacity-0 bg-black/40 transition-all duration-300" }, h("img", { src: Eye }), h("span", { class: "text-white" }, texts.expand)), h("img", { src: image, class: "h-[150px] cursor-pointer shadow-sm rounded-lg w-[84px] transition-all duration-300" }))))))))))))));
    }
    static get is() { return "vehicle-paint-thickness"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["vehicle-paint-thickness.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["vehicle-paint-thickness.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
            }
        };
    }
    static get states() {
        return {
            "locale": {},
            "expandedImage": {},
            "blazorRef": {},
            "isError": {},
            "errorMessage": {},
            "isLoading": {},
            "vehicleLookup": {},
            "activeTabIndex": {}
        };
    }
    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"
            }, {
                "propName": "vehicleLookup",
                "methodName": "onVehicleLookupChange"
            }];
    }
}
