PageSourceSearch

https://chauffeur.nl/assets/KvkLookup-DJWkzC0b.js

js chauffeur.nl collected 2026-10-06 19:06:07 UTC 7,809 bytes, 1 lines download raw bytes

1import{r as t,j as r}from"./vendor-react-CgtGWQid.js";import{I as y}from"./Input-N_Ddmq9n.js";import{s as W,L as V,B as H,a as J}from"./index-BRA2WhLB.js";import{C as T,a as M,p as X}from"./utils-DeRcbYAZ.js";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new n.Error().stack;o&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[o]="4fe3e92c-7b27-4dc8-bf1c-5ce678b2dc5f",n._sentryDebugIdIdentifier="sentry-dbid-4fe3e92c-7b27-4dc8-bf1c-5ce678b2dc5f")}catch{}})();function O(n){return/^\d{8}$/.test(n.replace(/\s/g,""))}function ne(n){return n.straatnaam?`${n.straatnaam} ${n.huisnummer||""}`.trim():""}function Y(){const[n,o]=t.useState([]),[g,c]=t.useState(!1),[k,d]=t.useState(null),[$,N]=t.useState(null),[E,K]=t.useState(!1),[S,x]=t.useState(null),j=t.useRef(null),h=t.useRef(null),i=t.useCallback(async(f,a)=>{const{data:s,error:l}=await W.functions.invoke("kvk-lookup",{body:f});if(a?.aborted)return null;if(l){let m="Er is een fout opgetreden";try{const b=l.context;if(b instanceof Response){const u=await b.json();typeof u?.error=="string"&&(m=u.error)}else typeof s?.error=="string"&&(m=s.error)}catch{}throw new Error(m)}if(!s?.success)throw new Error(s?.error||"Er is een fout opgetreden");return s.data},[]),L=t.useCallback(async f=>{const a=f.replace(/\s/g,"");if(!a)return o([]),d(null),null;if(!O(a))return d("Een KVK-nummer bestaat uit 8 cijfers"),o([]),null;c(!0),d(null);try{const s=await i({action:"search",kvkNummer:a});if(!s)return null;const l=s.results??[];return o(l),l}catch(s){const l=s instanceof Error?s.message:"Zoeken mislukt";return d(l),o([]),null}finally{c(!1)}},[i]),v=t.useCallback(async f=>(j.current?.abort(),h.current&&clearTimeout(h.current),!f||f.length<2?(o([]),d(null),c(!1),null):(c(!0),d(null),new Promise(a=>{h.current=setTimeout(async()=>{const s=new AbortController;j.current=s;try{const l=await i({action:"search",naam:f},s.signal);if(!l){a(null);return}const m=l.results??[];o(m),a(m)}catch(l){if(s.signal.aborted){a(null);return}const m=l instanceof Error?l.message:"Zoeken mislukt";d(m),o([]),a(null)}finally{s.signal.aborted||c(!1)}},300)}))),[i]),R=t.useCallback(async f=>{const a=f.replace(/\s/g,"");if(!O(a))return x("Een KVK-nummer bestaat uit 8 cijfers"),null;K(!0),x(null);try{const s=await i({action:"profile",kvkNummer:a});return s?(N(s),s):null}catch(s){const l=s instanceof Error?s.message:"Profiel ophalen mislukt";return x(l),null}finally{K(!1)}},[i]),C=t.useCallback(()=>{j.current?.abort(),h.current&&clearTimeout(h.current),o([]),d(null),N(null),x(null)},[]);return{searchByKvk:L,searchByName:v,searchResults:n,searchLoading:g,searchError:k,clearSearch:C,fetchProfile:R,profileData:$,profileLoading:E,profileError:S}}function te({kvkNumber:n,onKvkChange:o,onCompanyDataFetched:g,disabled:c=!1,required:k=!1,label:d="KVK-nummer",showSearchByName:$=!1,hideProfileButton:N=!1,nameFirst:E=!1,companyName:K,onCompanyNameChange:S}){const{searchByKvk:x,searchByName:j,searchResults:h,searchLoading:i,searchError:L,clearSearch:v,fetchProfile:R,profileLoading:C,profileError:f}=Y(),[a,s]=t.useState(null),[l,m]=t.useState(""),[b,u]=t.useState(!1),B=t.useRef(null),P=t.useRef(!1);t.useEffect(()=>{function e(p){B.current&&!B.current.contains(p.target)&&u(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),t.useEffect(()=>{if(P.current){P.current=!1;return}s(null)},[n]);const I=e=>({kvkNummer:e.kvkNummer,naam:e.naam,handelsnamen:[],rechtsvorm:null,sbiCode:null,sbiOmschrijving:null,straatnaam:e.adres?.straatnaam??null,huisnummer:e.adres?.huisnummer!=null?String(e.adres.huisnummer):null,postcode:e.adres?.postcode??null,plaats:e.adres?.plaats??null,website:null}),Z=()=>{!n||n.replace(/\s/g,"").length!==8||x(n).then(e=>{e&&e.length>0&&(s(e[0].naam),g(I(e[0])))}).catch(console.error)},Q=()=>{n&&R(n).then(e=>{e&&(s(e.naam),g(e))}).catch(console.error)},_=e=>{m(e),e.length>=2?(u(!0),j(e).catch(console.error)):(v(),u(!1))},[U,z]=t.useState(""),A=e=>{z(e);const p=e.replace(/\s/g,"");p.length>=2?/^\d+$/.test(p)&&p.length===8?x(p).then(()=>{u(!0)}).catch(console.error):/^\d+$/.test(p)?(v(),u(!1)):(u(!0),j(e).catch(console.error)):(v(),u(!1))},F=e=>
1{P.current=!0,o(e.kvkNummer),E?(S?.(e.naam),z(""),u(!1)):(m(""),u(!1)),s(e.naam),g(I(e)),R(e.kvkNummer).then(p=>{p&&g(p)}).catch(console.error)},w=L||f,G=i||C,D=()=>r.jsxs(r.Fragment,{children:[b&&h.length>0&&r.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-md border bg-popover shadow-lg max-h-60 overflow-auto scrollbar-thin",children:h.map(e=>r.jsx("button",{type:"button",className:J("w-full text-left px-3 py-2.5 hover:bg-accent transition-colors","border-b last:border-b-0 border-border/50"),onClick:()=>F(e),children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(X,{className:"h-4 w-4 mt-0.5 text-muted-foreground shrink-0"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"font-medium text-sm truncate",children:e.naam}),r.jsxs("div",{className:"text-xs text-muted-foreground flex gap-2",children:[r.jsxs("span",{children:["KVK: ",e.kvkNummer]}),e.adres?.plaats&&r.jsxs("span",{children:["• ",e.adres.plaats]})]})]})]})},e.kvkNummer))}),b&&i&&h.length===0&&r.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-md border bg-popover shadow-lg px-3 py-2.5",children:r.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[r.jsx(V,{className:"h-4 w-4 animate-spin"}),r.jsx("span",{children:"Zoeken..."})]})}),b&&!i&&h.length===0&&!L&&r.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-md border bg-popover shadow-lg px-3 py-2.5",children:r.jsx("p",{className:"text-sm text-muted-foreground",children:"Geen resultaten gevonden"})})]});return E?r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"relative",ref:B,children:[r.jsxs("div",{className:"flex gap-2 items-end",children:[r.jsx("div",{className:"flex-1",children:r.jsx(y,{label:"Zoek in KVK-register",value:U,onChange:e=>A(e.target.value),placeholder:"Bedrijfsnaam of KVK-nummer...",disabled:c})}),i&&r.jsx("div",{className:"shrink-0 mb-2.5",children:r.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})})]}),D()]}),r.jsx(y,{label:"Bedrijfsnaam",value:K??"",onChange:e=>S?.(e.target.value),placeholder:"Wordt ingevuld vanuit KVK",disabled:c}),r.jsx(y,{label:`${d}${k?" *":""}`,value:n,onChange:e=>o(e.target.value),onBlur:Z,placeholder:"12345678",maxLength:8,disabled:c,error:w??void 0}),a&&!w&&r.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-green-600",children:[r.jsx(T,{className:"h-4 w-4 shrink-0"}),r.jsx("span",{children:a})]})]}):r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex gap-2 items-end",children:[r.jsx("div",{className:"flex-1",children:r.jsx(y,{label:`${d}${k?" *":""}`,value:n,onChange:e=>o(e.target.value),onBlur:Z,placeholder:"12345678",maxLength:8,disabled:c,error:w??void 0})}),!N&&r.jsxs(H,{type:"button",variant:"outline",size:"default",disabled:c||G||!n||n.replace(/\s/g,"").length!==8,onClick:Q,className:"shrink-0 mb-0",style:{marginBottom:w?"1.625rem":0},children:[C?r.jsx(V,{className:"h-4 w-4 animate-spin mr-2"}):r.jsx(M,{className:"h-4 w-4 mr-2"}),"Zoek in KVK"]})]}),a&&!w&&r.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-green-600",children:[r.jsx(T,{className:"h-4 w-4 shrink-0"}),r.jsx("span",{children:a})]}),$&&r.jsxs("div",{className:"relative",ref:B,children:[r.jsx(y,{label:"Of zoek op bedrijfsnaam",value:l,onChange:e=>_(e.target.value),placeholder:"Zoek op bedrijfsnaam...",disabled:c}),i&&l&&r.jsx("div",{className:"absolute right-3 top-[2.375rem]",children:r.jsx(V,{className:"h-4 w-4 animate-spin text-muted-foreground"})}),D()]})]})}export{te as K,ne as f};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.