/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import{s as o}from"./p-lnx3CKt-.js";import{v as n}from"./p-CUREVASG.js";const r={cityId:"City-Id",userId:"User-Id",companyId:"Company-Id",customerName:"Customer-Name",customerPhone:"Customer-Phone",customerEmail:"Customer-Email",companyBranchId:"Company-Branch-Id",cityIntegrationId:"City-Integration-Id",brandIntegrationId:"Brand-Integration-Id",companyIntegrationId:"Company-Integration-Id",companyBranchIntegrationId:"Company-Branch-Integration-Id"},t=async(r,t,e={},{beforeAssignment:a}={})=>{var l;let d;null==t&&(t=(null===(l=r.vehicleLookup)||void 0===l?void 0:l.vin)||""),clearTimeout(r.networkTimeoutRef),r.abortController&&r.abortController.abort(),r.abortController=new AbortController;const s="string"==typeof t,u="string"==typeof t?t:null==t?void 0:t.vin;try{if(r.isLoading=!0,await new Promise((o=>{d=setTimeout(o,1e3),r.networkTimeoutRef=d})),!(u&&0!==u.trim().length||(null==r?void 0:r.isDev)))throw r.isError=!1,r.isLoading=!1,r.vehicleLookup=void 0,new Error("vinNumberRequired");if(!n(u)&&!(null==r?void 0:r.isDev)&&!(null==r?void 0:r.disableVinValidation))throw new Error("invalidVin");const l=s?await i(r,{scopedTimeoutRef:d,vin:u},e):t;if(r.networkTimeoutRef===d){if(!l)throw new Error("wrongResponseFormat");r.vehicleLookup=a?await a(l,{scopedTimeoutRef:d}):l,s&&o.bind(r)(null==r?void 0:r.loadedResponse,l)}r.errorMessage=null,r.isLoading=!1,r.isError=!1}catch(n){if(n&&"AbortError"===(null==n?void 0:n.name))return;o.bind(r)(null==r?void 0:r.errorCallback,n.message),console.error(n),r.setErrorMessage(n.message),r.isLoading=!1}},e=(o,n)=>{o.isError=!0,o.isLoading=!1,o.errorMessage=n,o.vehicleLookup=void 0},i=async(o,n,t={})=>{const{vin:e,scopedTimeoutRef:i}=n,a=n=>{if((null==o?void 0:o.networkTimeoutRef)===i){if(!n&&e)throw new Error("wrongResponseFormat");return n}};if(null==o?void 0:o.isDev)return a(null==o?void 0:o.mockData[e]);{if(!(null==o?void 0:o.baseUrl))throw new Error("noBaseUrl");const n=Object.assign({},t);Object.entries(r).forEach((([r,t])=>{o[r]&&(n[t]=o[r])}));const i=await fetch(`${null==o?void 0:o.baseUrl}${e}?${null==o?void 0:o.queryString}`,{signal:null==o?void 0:o.abortController.signal,headers:n});return a(await i.json())}};export{e as a,t as s}