/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import{s as o}from"./p-lnx3CKt-.js";import{f as n}from"./p-CJnc-a42.js";const r=async(r,i,{beforeAssignment:t}={})=>{const l=(null==r?void 0:r.localLoadingName)?null==r?void 0:r.localLoadingName:"isLoading";let e;null==i&&(i=(null==r?void 0:r.searchString)||""),clearTimeout(r.networkTimeoutRef),r.abortController&&r.abortController.abort(),r.abortController=new AbortController;const s="string"==typeof i,a="string"==typeof i?i:null==i?void 0:i.partNumber;try{if(!a||0===a.trim().length)return r.isError=!1,r[l]=!1,r.searchString="",void(r.partLookup=void 0);r[l]=!0,await new Promise((o=>{e=setTimeout(o,1e3),r.networkTimeoutRef=e})),r.searchString=a;const u=s?await async function(o,r){const{scopedTimeoutRef:i}=r,t=n=>{if((null==o?void 0:o.networkTimeoutRef)===i){if(!n&&(null==o?void 0:o.searchString))throw new Error("wrongResponseFormat");return n}};if(null==o?void 0:o.isDev)return t(null==o?void 0:o.mockData[null==o?void 0:o.searchString]);{if(!(null==o?void 0:o.endpoint))throw new Error("noBaseUrl");const r={signal:null==o?void 0:o.abortController.signal,additionalPath:"/"+o.searchString},i=await n(o.endpoint,r);if(204===i.status)throw new Error("noPartsFound");if(!i.ok)throw new Error("wildCard");return t(await i.json())}}(r,{scopedTimeoutRef:e}):i;if(r.networkTimeoutRef===e){if(!u)throw new Error("wrongResponseFormat");r.partLookup=t?await t(u,{scopedTimeoutRef:e}):u,s&&o.bind(r)(null==r?void 0:r.loadedResponse,u)}r.errorMessage=null,r[l]=!1,r.isError=!1}catch(n){if(n&&"AbortError"===(null==n?void 0:n.name))return;o.bind(r)(r.errorCallback,n.message),console.error(n),r.setErrorMessage(n.message)}},i=(o,n)=>{const r=(null==o?void 0:o.localLoadingName)?null==o?void 0:o.localLoadingName:"isLoading";o.isError=!0,o[r]=!1,o.errorMessage=n,o.partLookup=void 0};export{i as a,r as s}