/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
'use strict';

var index = require('./index-CmK48vN3.js');
var type = require('./type-CjTn3Uuy.js');
var types = require('./types-DV_cOCRi.js');
var getLocalLanguage = require('./get-local-language-d1KUONiZ.js');
var getLanguageFromUrl = require('./get-language-from-url-CQuyIE9M.js');
var cn = require('./cn-BHnqYtun.js');
var fetchFrom = require('./fetch-from-CDC_gRf3.js');

const manufacturerPartLookupCss = "*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;border:0 solid #e5e7eb;box-sizing:border-box}::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;}/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/:after,:before{--tw-content:\"\"}:host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-feature-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,fieldset,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}.block{display:block}:host{all:initial!important;display:block;font-family:inherit!important;font-family:Noto Kufi Arabic,Nunito,Roboto,Arial,sans-serif!important}*,:host *{font-family:inherit!important}.static{position:static}.flex{display:flex}.h-\\[200px\\]{height:200px}.w-full{width:100%}.items-center{align-items:center}.justify-center{justify-content:center}.text-\\[26px\\]{font-size:26px}.text-red-600{--tw-text-opacity:1;color:rgb(220 38 38/var(--tw-text-opacity,1))}.shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.flex-col{flex-direction:column}.gap-\\[16px\\]{gap:16px}.p-\\[16px\\]{padding:16px}.pb-\\[16px\\]{padding-bottom:16px}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.mx-auto{margin-left:auto;margin-right:auto}.me-2{margin-inline-end:.5rem}.ml-1{margin-left:.25rem}.mt-2{margin-top:.5rem}.mt-\\[32px\\]{margin-top:32px}.inline-flex{display:inline-flex}.h-\\[50px\\]{height:50px}.w-fit{width:fit-content}.max-w-full{max-width:100%}.flex-wrap{flex-wrap:wrap}.items-stretch{align-items:stretch}.gap-\\[8px\\]{gap:8px}.overflow-auto{overflow:auto}.overflow-x-auto{overflow-x:auto}.rounded-lg{border-radius:.5rem}.border{border-width:1px}.border-red-300{--tw-border-opacity:1;border-color:rgb(252 165 165/var(--tw-border-opacity,1))}.bg-\\[\\#f6f6f6\\]{--tw-bg-opacity:1;background-color:rgb(246 246 246/var(--tw-bg-opacity,1))}.bg-red-50{--tw-bg-opacity:1;background-color:rgb(254 242 242/var(--tw-bg-opacity,1))}.p-\\[2px\\]{padding:2px}.px-3{padding-left:.75rem;padding-right:.75rem}.px-\\[16px\\]{padding-left:16px;padding-right:16px}.py-1{padding-bottom:.25rem;padding-top:.25rem}.text-\\[16px\\]{font-size:16px}.text-\\[18px\\]{font-size:18px}.font-bold{font-weight:700}.font-medium{font-weight:500}.font-semibold{font-weight:600}.text-\\[green\\]{--tw-text-opacity:1;color:rgb(0 128 0/var(--tw-text-opacity,1))}.text-\\[orange\\]{--tw-text-opacity:1;color:rgb(255 165 0/var(--tw-text-opacity,1))}.text-\\[red\\]{--tw-text-opacity:1;color:rgb(255 0 0/var(--tw-text-opacity,1))}.text-red-800{--tw-text-opacity:1;color:rgb(153 27 27/var(--tw-text-opacity,1))}@media (min-width:768px){.md\\:justify-between{justify-content:space-between}}.\\[\\&\\>div\\]\\:grow>div{flex-grow:1}.me-1{margin-inline-end:.25rem}.relative{position:relative}.mb-\\[12px\\]{margin-bottom:12px}.w-\\[500px\\]{width:500px}.max-w-\\[250px\\]{max-width:250px}.max-w-\\[96vw\\]{max-width:96vw}.flex-1{flex:1 1 0%}.shrink-0{flex-shrink:0}.gap-2{gap:.5rem}.gap-\\[32px\\]{gap:32px}.rounded-md{border-radius:.375rem}.border-b{border-bottom-width:1px}.border-l{border-left-width:1px}.border-r{border-right-width:1px}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.py-\\[10px\\]{padding-bottom:10px;padding-top:10px}.py-\\[12px\\]{padding-bottom:12px}.pt-\\[12px\\],.py-\\[12px\\]{padding-top:12px}.pt-\\[32px\\]{padding-top:32px}.pt-\\[8px\\]{padding-top:8px}.text-center{text-align:center}.text-\\[20px\\]{font-size:20px}.text-xl{font-size:1.25rem;line-height:1.75rem}.even\\:bg-slate-100:nth-child(2n){--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity,1))}.hover\\:bg-sky-100\\/50:hover{background-color:rgba(224,242,254,.5)}.\\!h-auto{height:auto!important}.min-w-full{min-width:100%}.resize{resize:both}.overflow-hidden{overflow:hidden}.\\!transition-none{transition-property:none!important}.transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.\\!duration-0{transition-duration:0s!important}.\\!duration-500{transition-duration:.5s!important}.duration-500{transition-duration:.5s}.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1536px){.container{max-width:1536px}}.\\!pointer-events-none{pointer-events:none!important}.absolute{position:absolute}.top-0{top:0}.\\!w-full{width:100%!important}.translate-x-\\[-200\\%\\]{--tw-translate-x:-200%}.translate-x-\\[-200\\%\\],.translate-y-\\[200\\%\\]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-y-\\[200\\%\\]{--tw-translate-y:200%}.opacity-0{opacity:0}.transition{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1)}.\\[\\&_\\*\\]\\:\\!pointer-events-none *{pointer-events:none!important}.my-auto{margin-bottom:auto;margin-top:auto}.table{display:table}.grid{display:grid}.size-\\[20px\\]{height:20px;width:20px}.size-\\[32px\\]{height:32px;width:32px}.size-full{height:100%;width:100%}.rotate-180{--tw-rotate:180deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.cursor-pointer{cursor:pointer}.place-items-center{place-items:center}.whitespace-nowrap{white-space:nowrap}.rounded{border-radius:.25rem}.bg-sky-100{--tw-bg-opacity:1;background-color:rgb(224 242 254/var(--tw-bg-opacity,1))}.bg-sky-200{--tw-bg-opacity:1;background-color:rgb(186 230 253/var(--tw-bg-opacity,1))}.bg-slate-100{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity,1))}.bg-slate-200\\/70{background-color:rgba(226,232,240,.7)}.px-\\[12px\\]{padding-left:12px;padding-right:12px}.px-\\[6px\\]{padding-left:6px;padding-right:6px}.px-\\[8px\\]{padding-left:8px;padding-right:8px}.py-\\[16px\\]{padding-bottom:16px;padding-top:16px}.py-\\[6px\\]{padding-bottom:6px;padding-top:6px}.py-\\[8px\\]{padding-bottom:8px;padding-top:8px}.text-\\[13px\\]{font-size:13px}.text-slate-700{--tw-text-opacity:1;color:rgb(51 65 85/var(--tw-text-opacity,1))}.transition-transform{transition-duration:.15s;transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1)}.duration-300{transition-duration:.3s}.last\\:border-b-0:last-child{border-bottom-width:0}.hover\\:cursor-pointer:hover{cursor:pointer}.hover\\:bg-sky-200:hover{--tw-bg-opacity:1;background-color:rgb(186 230 253/var(--tw-bg-opacity,1))}.hover\\:bg-slate-200\\/70:hover{background-color:rgba(226,232,240,.7)}";

const manufacturerOrderTypesFetcher = async ({}) => {
    return [
        {
            value: '0',
            label: 'V',
        },
        {
            value: '1',
            label: 'A ',
        },
    ];
};
const manufacturerPartLookupValidation = types.create$3({
    orderType: types.create$6()
        .meta({ label: 'Order Type', placeholder: 'Order Type' })
        .required('This field is required.'),
    quantity: types.create$5()
        .meta({ label: 'quantity', placeholder: 'quantity' })
        .required('This field is required.')
        .typeError('This field is required.')
        .min(1, 'This field is required.'),
    partNumber: types.create$6()
        .meta({ label: 'Part Number', placeholder: 'Part Number' })
        .required('This field is required.'),
});
const ManufacturerPartLookup = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.locale = Object.assign({ sharedLocales: types.sharedLocalesSchema.getDefault() }, type.distributerSchema.getDefault());
        // #endregion
        // #region Form Hook logic
        this.isLoading = false;
        this.formSubmit = async (payload) => {
            try {
                if (this.isDev) {
                    await new Promise(r => setTimeout(r, 2000));
                    if (0.5 < Math.random()) {
                        if (0.5 < Math.random())
                            this.manufacturerResponse = { message: '', quantity: 2, id: '2', orderType: 'Airplane', partNumber: 'T110715002102', status: 'Pending', manufacturerResult: [] };
                        else
                            this.manufacturerResponse = { message: '', quantity: 2, id: '2', orderType: 'Airplane', partNumber: 'T110715002102', status: 'UnResolved', manufacturerResult: [] };
                    }
                    else {
                        this.manufacturerResponse = {
                            id: '2',
                            message: '',
                            quantity: 2,
                            orderType: 'Airplane',
                            partNumber: 'T110715002102',
                            status: 'Pending',
                            manufacturerResult: [
                                { key: 'item 1', value: `${Math.floor(Math.random() * 100)}` },
                                { key: 'item 2', value: 'Available' },
                                { key: 'item 3', value: `${Math.floor(Math.random() * 100)}` },
                                { key: 'item 4', value: 'Not Available' },
                            ],
                        };
                    }
                    this.form.reset();
                    return;
                }
                const requestPayload = {
                    logId: this.logId,
                    quantity: +payload.quantity,
                    partNumber: payload.partNumber,
                    // @ts-ignore
                    orderType: +payload.orderType,
                };
                const response = await fetchFrom.fetchFrom(this.manufacturerPartLookupEndpoint, { language: this.language, body: requestPayload, method: 'POST' });
                if (!response.ok) {
                    throw new Error(`Request failed with status ${response.status}`);
                }
                const responseType = (await response.json());
                this.form.reset();
                this.manufacturerResponse = responseType;
            }
            catch (error) {
                console.error('❌ Manufacturer Lookup request failed:', error);
                // @ts-ignore
                this.manufacturerResponse = { message: this.locale.RequestFailed };
            }
        };
        this.logId = '';
        this.standAlone = true;
        this.manufacturerPartLookupTitle = 'Manufacture lookup';
        this.form = new getLanguageFromUrl.FormHook(this, manufacturerPartLookupValidation);
    }
    async componentWillLoad() {
        if (!this.language)
            this.language = getLanguageFromUrl.getLanguageFromUrl();
        await Promise.all([this.changeLanguage(this.language)]);
    }
    async changeLanguage(newLanguage) {
        const [sharedLocales, locale] = await Promise.all([getLocalLanguage.getSharedLocal(newLanguage), getLocalLanguage.getLocaleLanguage(newLanguage, 'partLookup.distributor', type.distributerSchema)]);
        this.locale = Object.assign({ sharedLocales }, locale);
    }
    // #endregion
    render() {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        const { formController } = this.form;
        const isComponentOpened = (!!((_a = this === null || this === void 0 ? void 0 : this.partLookup) === null || _a === void 0 ? void 0 : _a.showManufacturerPartLookup) && !this.closeManufacturerPartLookup) || this.standAlone;
        return (index.h(index.Host, { key: '0f036603dff5899811b48162e0344d6946c8475e', translate: "no" }, index.h("flexible-container", { key: '2a46003f17893430fb3575e00a5683c60032e4ea', isOpened: isComponentOpened }, index.h("div", { key: '2ee897f73a17435c7ecb4f59c030b44a1f5799f4', class: "w-full max-w-[96vw] mx-auto pt-[32px]" }, index.h("div", { key: '46c7b44060cfdacac51e5c5f0dff1dfd3c37c5d6', class: "bg-[#f6f6f6] rounded-md p-[16px]" }, index.h("div", { key: '388fff58b142eb48c3d12d51fe36ca600dcbc0b5', class: "flex items-center mb-[12px] justify-center px-[16px] font-bold text-[18px]" }, this.manufacturerPartLookupTitle), index.h("form", Object.assign({ key: '010bbd1acbf35b62577ac97708f3659a3d96ef70', class: "relative manufacturer-form flex flex-col items-center gap-[32px] pt-[8px] pb-[16px]", dir: this.locale.sharedLocales.direction }, formController), index.h("div", { key: 'b33d8a79c10aa573f608d8b901f94aab9511ecb2', class: "flex gap-2" }, index.h("form-input", { form: this.form, name: "partNumber", isLoading: this.isLoading, key: this.locale.sharedLocales.lang, staticValue: ((_b = this.partLookup) === null || _b === void 0 ? void 0 : _b.partNumber) || undefined }), index.h("form-input", { inputProps: { type: 'number', min: 1 }, name: "quantity", isLoading: this.isLoading, key: this.locale.sharedLocales.lang, form: this.form }), index.h("form-select", { clearable: true, form: this.form, name: "orderType", isLoading: this.isLoading, fetcher: manufacturerOrderTypesFetcher, key: this.locale.sharedLocales.lang, language: this.locale.sharedLocales.language })), index.h("form-submit", { key: this.locale.sharedLocales.lang, isLoading: this.isLoading, form: this.form })), index.h("flexible-container", { key: 'b4c245b2e3d5953ff9420c5852f586e585c54b76', isOpened: !!this.manufacturerResponse && !this.isLoading }, index.h("div", { key: '2c83cc980df47ef6a6f42f6b87c35a0ba338cb22', class: "flex flex-col items-center pt-[12px]" }, index.h("div", { key: 'b686301eb396fec496141635635a9abc89c06f98', class: cn.cn('text-center text-[20px] font-semibold py-[12px]') }, !((_d = (_c = this.manufacturerResponse) === null || _c === void 0 ? void 0 : _c.manufacturerResult) === null || _d === void 0 ? void 0 : _d.length) && (((_e = this.manufacturerResponse) === null || _e === void 0 ? void 0 : _e.message) || this.locale.RequestFailed), !!((_g = (_f = this.manufacturerResponse) === null || _f === void 0 ? void 0 : _f.manufacturerResult) === null || _g === void 0 ? void 0 : _g.length) && (index.h("div", { key: '09124847eddd26cb2b478fbe1bd86a3d78799e1c', class: "bg-white rounded-lg border w-[500px]" }, (_h = this.manufacturerResponse) === null || _h === void 0 ? void 0 : _h.manufacturerResult.map(({ key, value }) => (index.h("div", { key: `${key}-${value}`, class: "flex even:bg-slate-100 hover:bg-sky-100/50 border-b w-full text-xl text-center" }, index.h("div", { class: "text-center flex items-center flex-1 max-w-[250px] shrink-0 justify-center py-[10px] px-[16px] border-r" }, key), index.h("div", { class: "text-center flex items-center flex-1 shrink-0 justify-center py-[10px] px-[16px] border-l" }, value))))))))))))));
    }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "language": ["changeLanguage"]
    }; }
};
ManufacturerPartLookup.style = manufacturerPartLookupCss;

exports.manufacturer_part_lookup = ManufacturerPartLookup;
