1 line
No EOL
25 KiB
JavaScript
1 line
No EOL
25 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,54858,e=>{"use strict";let t="/api/v1";async function r(e,t){let r=await e.text();if(!r)return t;try{let e=JSON.parse(r);return e.detail??e.message??r}catch{return r}}async function s(e,t){let r=await fetch("/api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,password:t}),credentials:"include"});if(!r.ok){let e=Error(await r.text()||`HTTP ${r.status}`);throw e.status=r.status,e}return r.json()}async function i(e,r){let s=await fetch(`${t}${e}`,{cache:"no-store",credentials:"include"});if(!s.ok)throw Error(`API request failed: ${s.status}`);return s.json()}async function a(e,s,i,a){let n=await fetch(`${t}${e}`,{method:i,headers:{"Content-Type":"application/json"},body:JSON.stringify(a),credentials:"include"});if(!n.ok)throw Error(await r(n,`API request failed: ${n.status}`));return n.json()}async function n(e,s){let i=await fetch(`${t}${e}`,{method:"DELETE",credentials:"include"});if(!i.ok)throw Error(await r(i,`API request failed: ${i.status}`))}async function l(e,s,i){let a=await fetch(`${t}${e}`,{...i,headers:{"Content-Type":"application/json",...i?.headers??{}},credentials:"include"});if(!a.ok)throw Error(await r(a,`API request failed: ${a.status}`));return a.json()}e.s(["API_BASE",0,t,"apiDelete",0,n,"apiFetch",0,l,"apiGet",0,i,"apiSend",0,a,"login",0,s,"normalizeValidationPayload",0,function(e){return{...e,...Object.fromEntries(["contact_id","examiner_id"].map(t=>[t,e[t]||null]))}}])},66027,e=>{"use strict";let t;var r=e.i(75555),s=e.i(73911),i=e.i(40143),a=e.i(86491),n=e.i(15823),l=e.i(93803),o=e.i(19273),u=e.i(80166),d=class extends n.Subscribable{constructor(e,t){super(),this.options=t,this.#e=e,this.#t=null,this.#r=(0,l.pendingThenable)(),this.bindMethods(),this.setOptions(t)}#e;#s=void 0;#i=void 0;#a=void 0;#n;#l;#r;#t;#o;#u;#d;#c;#h;#p;#m=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.size&&(this.#s.addObserver(this),c(this.#s,this.options)?this.#b():this.updateResult(),this.#f())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return h(this.#s,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return h(this.#s,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#g(),this.#x(),this.#s.removeObserver(this)}setOptions(e){let t=this.options,r=this.#s;if(this.options=this.#e.defaultQueryOptions(e),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled&&"function"!=typeof this.options.enabled&&"boolean"!=typeof(0,o.resolveQueryBoolean)(this.options.enabled,this.#s))throw Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#y(),this.#s.setOptions(this.options),t._defaulted&&!(0,o.shallowEqualObjects)(this.options,t)&&this.#e.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#s,observer:this});let s=this.hasListeners();s&&p(this.#s,r,this.options,t)&&this.#b(),this.updateResult(),s&&(this.#s!==r||(0,o.resolveQueryBoolean)(this.options.enabled,this.#s)!==(0,o.resolveQueryBoolean)(t.enabled,this.#s)||(0,o.resolveStaleTime)(this.options.staleTime,this.#s)!==(0,o.resolveStaleTime)(t.staleTime,this.#s))&&this.#v();let i=this.#j();s&&(this.#s!==r||(0,o.resolveQueryBoolean)(this.options.enabled,this.#s)!==(0,o.resolveQueryBoolean)(t.enabled,this.#s)||i!==this.#p)&&this.#R(i)}getOptimisticResult(e){var t,r;let s=this.#e.getQueryCache().build(this.#e,e),i=this.createResult(s,e);return t=this,r=i,(0,o.shallowEqualObjects)(t.getCurrentResult(),r)||(this.#a=i,this.#l=this.options,this.#n=this.#s.state),i}getCurrentResult(){return this.#a}trackResult(e,t){return new Proxy(e,{get:(e,r)=>(this.trackProp(r),t?.(r),"promise"===r&&(this.trackProp("data"),this.options.experimental_prefetchInRender||"pending"!==this.#r.status||this.#r.reject(Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(e,r))})}trackProp(e){this.#m.add(e)}getCurrentQuery(){return this.#s}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),r=this.#e.getQueryCache().build(this.#e,t);return r.fetch().then(()=>this.createResult(r,t))}fetch(e){return this.#b({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#a))}#b(e){this.#y();let t=this.#s.fetch(this.options,e);return e?.throwOnError||(t=t.catch(o.noop)),t}#v(){this.#g();let e=(0,o.resolveStaleTime)(this.options.staleTime,this.#s);if(s.environmentManager.isServer()||this.#a.isStale||!(0,o.isValidTimeout)(e))return;let t=(0,o.timeUntilStale)(this.#a.dataUpdatedAt,e);this.#c=u.timeoutManager.setTimeout(()=>{this.#a.isStale||this.updateResult()},t+1)}#j(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#s):this.options.refetchInterval)??!1}#R(e){this.#x(),this.#p=e,!s.environmentManager.isServer()&&!1!==(0,o.resolveQueryBoolean)(this.options.enabled,this.#s)&&(0,o.isValidTimeout)(this.#p)&&0!==this.#p&&(this.#h=u.timeoutManager.setInterval(()=>{(this.options.refetchIntervalInBackground||r.focusManager.isFocused())&&this.#b()},this.#p))}#f(){this.#v(),this.#R(this.#j())}#g(){void 0!==this.#c&&(u.timeoutManager.clearTimeout(this.#c),this.#c=void 0)}#x(){void 0!==this.#h&&(u.timeoutManager.clearInterval(this.#h),this.#h=void 0)}createResult(e,t){let r,s=this.#s,i=this.options,n=this.#a,u=this.#n,d=this.#l,h=e!==s?e.state:this.#i,{state:b}=e,f={...b},g=!1;if(t._optimisticResults){let r=this.hasListeners(),n=!r&&c(e,t),l=r&&p(e,s,t,i);(n||l)&&(f={...f,...(0,a.fetchState)(b.data,e.options)}),"isRestoring"===t._optimisticResults&&(f.fetchStatus="idle")}let{error:x,errorUpdatedAt:y,status:v}=f;r=f.data;let j=!1;if(void 0!==t.placeholderData&&void 0===r&&"pending"===v){let e;n?.isPlaceholderData&&t.placeholderData===d?.placeholderData?(e=n.data,j=!0):e="function"==typeof t.placeholderData?t.placeholderData(this.#d?.state.data,this.#d):t.placeholderData,void 0!==e&&(v="success",r=(0,o.replaceData)(n?.data,e,t),g=!0)}if(t.select&&void 0!==r&&!j)if(n&&r===u?.data&&t.select===this.#o)r=this.#u;else try{this.#o=t.select,r=t.select(r),r=(0,o.replaceData)(n?.data,r,t),this.#u=r,this.#t=null}catch(e){this.#t=e}this.#t&&(x=this.#t,r=this.#u,y=Date.now(),v="error");let R="fetching"===f.fetchStatus,w="pending"===v,N="error"===v,S=w&&R,Q=void 0!==r,O={status:v,fetchStatus:f.fetchStatus,isPending:w,isSuccess:"success"===v,isError:N,isInitialLoading:S,isLoading:S,data:r,dataUpdatedAt:f.dataUpdatedAt,error:x,errorUpdatedAt:y,failureCount:f.fetchFailureCount,failureReason:f.fetchFailureReason,errorUpdateCount:f.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:f.dataUpdateCount>h.dataUpdateCount||f.errorUpdateCount>h.errorUpdateCount,isFetching:R,isRefetching:R&&!w,isLoadingError:N&&!Q,isPaused:"paused"===f.fetchStatus,isPlaceholderData:g,isRefetchError:N&&Q,isStale:m(e,t),refetch:this.refetch,promise:this.#r,isEnabled:!1!==(0,o.resolveQueryBoolean)(t.enabled,e)};if(this.options.experimental_prefetchInRender){let t=void 0!==O.data,r="error"===O.status&&!t,i=e=>{r?e.reject(O.error):t&&e.resolve(O.data)},a=()=>{i(this.#r=O.promise=(0,l.pendingThenable)())},n=this.#r;switch(n.status){case"pending":e.queryHash===s.queryHash&&i(n);break;case"fulfilled":(r||O.data!==n.value)&&a();break;case"rejected":r&&O.error===n.reason||a()}}return O}updateResult(){let e=this.#a,t=this.createResult(this.#s,this.options);if(this.#n=this.#s.state,this.#l=this.options,void 0!==this.#n.data&&(this.#d=this.#s),(0,o.shallowEqualObjects)(t,e))return;this.#a=t;let r=()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,r="function"==typeof t?t():t;if("all"===r||!r&&!this.#m.size)return!0;let s=new Set(r??this.#m);return this.options.throwOnError&&s.add("error"),Object.keys(this.#a).some(t=>this.#a[t]!==e[t]&&s.has(t))};this.#w({listeners:r()})}#y(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#s)return;let t=this.#s;this.#s=e,this.#i=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#f()}#w(e){i.notifyManager.batch(()=>{e.listeners&&this.listeners.forEach(e=>{e(this.#a)}),this.#e.getQueryCache().notify({query:this.#s,type:"observerResultsUpdated"})})}};function c(e,t){return!1!==(0,o.resolveQueryBoolean)(t.enabled,e)&&void 0===e.state.data&&("error"!==e.state.status||!1!==(0,o.resolveQueryBoolean)(t.retryOnMount,e))||void 0!==e.state.data&&h(e,t,t.refetchOnMount)}function h(e,t,r){if(!1!==(0,o.resolveQueryBoolean)(t.enabled,e)&&"static"!==(0,o.resolveStaleTime)(t.staleTime,e)){let s="function"==typeof r?r(e):r;return"always"===s||!1!==s&&m(e,t)}return!1}function p(e,t,r,s){return(e!==t||!1===(0,o.resolveQueryBoolean)(s.enabled,e))&&(!r.suspense||"error"!==e.state.status)&&m(e,r)}function m(e,t){return!1!==(0,o.resolveQueryBoolean)(t.enabled,e)&&e.isStaleByTime((0,o.resolveStaleTime)(t.staleTime,e))}e.i(47167);var b=e.i(71645),f=e.i(12598);e.i(43476);var g=b.createContext((t=!1,{clearReset:()=>{t=!1},reset:()=>{t=!0},isReset:()=>t})),x=b.createContext(!1);x.Provider;var y=(e,t,r)=>t.fetchOptimistic(e).catch(()=>{r.clearReset()});e.s(["useQuery",0,function(e,t){return function(e,t,r){let a,n=b.useContext(x),l=b.useContext(g),u=(0,f.useQueryClient)(r),d=u.defaultQueryOptions(e);u.getDefaultOptions().queries?._experimental_beforeQuery?.(d);let c=u.getQueryCache().get(d.queryHash),h=!1!==e.subscribed;if(d._optimisticResults=n?"isRestoring":h?"optimistic":void 0,d.suspense){let e=e=>"static"===e?e:Math.max(e??1e3,1e3),t=d.staleTime;d.staleTime="function"==typeof t?(...r)=>e(t(...r)):e(t),"number"==typeof d.gcTime&&(d.gcTime=Math.max(d.gcTime,1e3))}a=c?.state.error&&"function"==typeof d.throwOnError?(0,o.shouldThrowError)(d.throwOnError,[c.state.error,c]):d.throwOnError,(d.suspense||d.experimental_prefetchInRender||a)&&!l.isReset()&&(d.retryOnMount=!1),b.useEffect(()=>{l.clearReset()},[l]);let p=!u.getQueryCache().get(d.queryHash),[m]=b.useState(()=>new t(u,d)),v=m.getOptimisticResult(d),j=!n&&h;if(b.useSyncExternalStore(b.useCallback(e=>{let t=j?m.subscribe(i.notifyManager.batchCalls(e)):o.noop;return m.updateResult(),t},[m,j]),()=>m.getCurrentResult(),()=>m.getCurrentResult()),b.useEffect(()=>{m.setOptions(d)},[d,m]),d?.suspense&&v.isPending)throw y(d,m,l);if((({result:e,errorResetBoundary:t,throwOnError:r,query:s,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&s&&(i&&void 0===e.data||(0,o.shouldThrowError)(r,[e.error,s])))({result:v,errorResetBoundary:l,throwOnError:d.throwOnError,query:c,suspense:d.suspense}))throw v.error;if(u.getDefaultOptions().queries?._experimental_afterQuery?.(d,v),d.experimental_prefetchInRender&&!s.environmentManager.isServer()&&v.isLoading&&v.isFetching&&!n){let e=p?y(d,m,l):c?.promise;e?.catch(o.noop).finally(()=>{m.updateResult()})}return d.notifyOnChangeProps?v:m.trackResult(v)}(e,d,t)}],66027)},54616,e=>{"use strict";var t=e.i(71645),r=e.i(14272),s=e.i(40143),i=e.i(15823),a=e.i(19273),n=class extends i.Subscribable{#e;#a=void 0;#N;#S;constructor(e,t){super(),this.#e=e,this.setOptions(t),this.bindMethods(),this.#Q()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){let t=this.options;this.options=this.#e.defaultMutationOptions(e),(0,a.shallowEqualObjects)(this.options,t)||this.#e.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#N,observer:this}),t?.mutationKey&&this.options.mutationKey&&(0,a.hashKey)(t.mutationKey)!==(0,a.hashKey)(this.options.mutationKey)?this.reset():this.#N?.state.status==="pending"&&this.#N.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#N?.removeObserver(this)}onMutationUpdate(e){this.#Q(),this.#w(e)}getCurrentResult(){return this.#a}reset(){this.#N?.removeObserver(this),this.#N=void 0,this.#Q(),this.#w()}mutate(e,t){return this.#S=t,this.#N?.removeObserver(this),this.#N=this.#e.getMutationCache().build(this.#e,this.options),this.#N.addObserver(this),this.#N.execute(e)}#Q(){let e=this.#N?.state??(0,r.getDefaultState)();this.#a={...e,isPending:"pending"===e.status,isSuccess:"success"===e.status,isError:"error"===e.status,isIdle:"idle"===e.status,mutate:this.mutate,reset:this.reset}}#w(e){s.notifyManager.batch(()=>{if(this.#S&&this.hasListeners()){let t=this.#a.variables,r=this.#a.context,s={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type==="success"){try{this.#S.onSuccess?.(e.data,t,r,s)}catch(e){Promise.reject(e)}try{this.#S.onSettled?.(e.data,null,t,r,s)}catch(e){Promise.reject(e)}}else if(e?.type==="error"){try{this.#S.onError?.(e.error,t,r,s)}catch(e){Promise.reject(e)}try{this.#S.onSettled?.(void 0,e.error,t,r,s)}catch(e){Promise.reject(e)}}}this.listeners.forEach(e=>{e(this.#a)})})}},l=e.i(12598);e.s(["useMutation",0,function(e,r){let i=(0,l.useQueryClient)(r),[o]=t.useState(()=>new n(i,e));t.useEffect(()=>{o.setOptions(e)},[o,e]);let u=t.useSyncExternalStore(t.useCallback(e=>o.subscribe(s.notifyManager.batchCalls(e)),[o]),()=>o.getCurrentResult(),()=>o.getCurrentResult()),d=t.useCallback((e,t)=>{o.mutate(e,t).catch(a.noop)},[o]);if(u.error&&(0,a.shouldThrowError)(o.options.throwOnError,[u.error]))throw u.error;return{...u,mutate:d,mutateAsync:u.mutate}}],54616)},55436,e=>{"use strict";let t=(0,e.i(75254).default)("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);e.s(["Search",0,t],55436)},55557,e=>{"use strict";var t=e.i(43476),r=e.i(54616),s=e.i(66027),i=e.i(75254);let a=(0,i.default)("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),n=(0,i.default)("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);var l=e.i(55436);let o=(0,i.default)("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]),u=(0,i.default)("UserRoundCheck",[["path",{d:"M2 21a8 8 0 0 1 13.292-6",key:"bjp14o"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);var d=e.i(71645),c=e.i(28779),h=e.i(54858);let p={Erstvalidierung:"Erstvalidierung",Revalidierung:"Revalidierung",Leistungsbeurteilung:"Leistungsbeurteilung"};function m({label:e,value:r}){return(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-white p-4",children:[(0,t.jsx)("p",{className:"text-xs uppercase tracking-wide text-text-light",children:e}),(0,t.jsx)("p",{className:"mt-2 font-medium text-text",children:r})]})}e.s(["default",0,function(){let{token:e,user:i}=(0,c.useAuth)(),[b,f]=(0,d.useState)(""),[g,x]=(0,d.useState)(""),[y,v]=(0,d.useState)(""),[j,R]=(0,d.useState)(""),[w,N]=(0,d.useState)(""),[S,Q]=(0,d.useState)("Erstvalidierung"),[O,k]=(0,d.useState)(""),E=(0,s.useQuery)({queryKey:["quickstart-customers",b,e],queryFn:()=>(0,h.apiGet)(`/customers?page=1&page_size=12${b.trim()?`&search=${encodeURIComponent(b.trim())}`:""}`,e??""),enabled:!!e}),T=(0,s.useQuery)({queryKey:["quickstart-customer-data",g,e],queryFn:()=>(0,h.apiGet)(`/customers/${g}/quickstart-data`,e??""),enabled:!!(e&&g)});(0,d.useEffect)(()=>{v(""),R(""),N(""),k("")},[g]),(0,d.useEffect)(()=>{let e=T.data;if(e&&(1===e.locations.length&&v(e.locations[0].id),1===e.contacts.length&&R(e.contacts[0].id),1===e.devices.length&&N(e.devices[0].id),"Revalidierung"===S&&e.devices.length>0&&!w)){let t=e.validations[0]?.device_id;t&&N(t)}},[T.data,w,S]);let I=E.data?.items.find(e=>e.id===g)??T.data?.customer??null,C=T.data?.devices.find(e=>e.id===w)??null,M=T.data?.locations.find(e=>e.id===y)??null,_=T.data?.contacts.find(e=>e.id===j)??null,P=i?`${i.first_name} ${i.last_name}`:"nicht angemeldet",q=(0,d.useMemo)(()=>w?T.data?.validations.find(e=>e.device_id===w)??null:null,[T.data?.validations,w]),L=(0,r.useMutation)({mutationFn:async()=>(0,h.apiFetch)("/validations/quick-start",e??"",{method:"POST",body:JSON.stringify({customer_id:g,location_id:y||null,contact_id:j||null,device_id:w||null,validation_type:S})}),onSuccess:e=>{window.location.replace(`/validations/${e.id}/edit`)},onError:e=>k(e.message)}),D=E.data?.items??[],F=!!g&&!!w&&(T.data?.locations.length??0)>0&&(T.data?.locations.length,!!y)&&!L.isPending;return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("header",{className:"rounded-lg border border-border bg-surface p-6 shadow-soft",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 text-primary",children:[(0,t.jsx)(o,{className:"h-5 w-5"}),(0,t.jsx)("p",{className:"text-sm font-medium uppercase tracking-wide",children:"Quickstart"})]}),(0,t.jsx)("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Neue Validierung starten"}),(0,t.jsx)("p",{className:"mt-2 max-w-3xl text-text-light",children:"Wir fassen die wichtigsten Entscheidungen zusammen und öffnen danach direkt die bestehende Validierungsbearbeitung."}),(0,t.jsxs)("div",{className:"mt-4 flex flex-wrap gap-2 text-sm text-text-light",children:[(0,t.jsx)("span",{className:"rounded-full border border-border bg-background px-3 py-1",children:"1 Kunde"}),(0,t.jsx)("span",{className:"rounded-full border border-border bg-background px-3 py-1",children:"2 Gerät"}),(0,t.jsx)("span",{className:"rounded-full border border-border bg-background px-3 py-1",children:"3 Validierungsart"}),(0,t.jsx)("span",{className:"rounded-full border border-border bg-background px-3 py-1",children:"4 Erstellen"})]})]}),(0,t.jsxs)("section",{className:"grid gap-4 xl:grid-cols-[1.1fr_1fr]",children:[(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsx)("h2",{className:"text-xl font-semibold",children:"1. Kunde"}),I&&(0,t.jsx)("span",{className:"rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-xs font-medium text-primary",children:"Ausgewählt"})]}),E.isError&&(0,t.jsx)("p",{className:"mt-3 rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 text-sm text-danger",children:"Kunden konnten nicht geladen werden."}),(0,t.jsxs)("label",{className:"mt-4 flex h-12 items-center gap-2 rounded-lg border border-border px-3",children:[(0,t.jsx)(l.Search,{className:"h-4 w-4 text-primary"}),(0,t.jsx)("input",{value:b,onChange:e=>f(e.target.value),className:"flex-1 outline-none",placeholder:"Kundenname, Ort, PLZ, Ansprechpartner"})]}),(0,t.jsxs)("div",{className:"mt-4 grid gap-3",children:[D.map(e=>{let r=e.id===g;return(0,t.jsxs)("button",{type:"button",onClick:()=>x(e.id),className:`rounded-lg border p-4 text-left transition ${r?"border-primary bg-primary/5 shadow":"border-border bg-background hover:border-primary/40 hover:bg-white"}`,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-base font-semibold",children:e.name}),(0,t.jsx)("p",{className:"mt-1 text-sm text-text-light",children:e.city||"Ort nicht erfasst"})]}),r&&(0,t.jsx)(u,{className:"h-5 w-5 text-primary"})]}),(0,t.jsx)("p",{className:"mt-2 text-sm text-text-light",children:"practice"===e.customer_type?"Praxis":"Klinik"})]},e.id)}),E.isLoading&&(0,t.jsx)("p",{className:"rounded-lg border border-dashed border-border p-4 text-sm text-text-light",children:"Kunden werden geladen..."}),!E.isLoading&&!E.isError&&0===D.length&&(0,t.jsx)("p",{className:"rounded-lg border border-dashed border-border p-4 text-sm text-text-light",children:"Keine Kunden gefunden."})]})]}),(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsx)("h2",{className:"text-xl font-semibold",children:"2. Gerät"}),C&&(0,t.jsx)("span",{className:"rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-xs font-medium text-primary",children:"Ausgewählt"})]}),T.isError&&(0,t.jsx)("p",{className:"mt-3 rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 text-sm text-danger",children:"Kundendaten konnten nicht geladen werden."}),(0,t.jsxs)("div",{className:"mt-4 grid gap-3",children:[(T.data?.devices??[]).map(e=>{let r=e.id===w,s=T.data?.validations.find(t=>t.device_id===e.id)??null;return(0,t.jsxs)("button",{type:"button",onClick:()=>N(e.id),className:`rounded-lg border p-4 text-left transition ${r?"border-primary bg-primary/5 shadow":"border-border bg-background hover:border-primary/40 hover:bg-white"}`,children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("p",{className:"text-base font-semibold",children:[e.manufacturer," ",e.model]}),(0,t.jsxs)("p",{className:"mt-1 text-sm text-text-light",children:["Seriennummer ",e.serial_number]}),(0,t.jsx)("p",{className:"mt-1 text-sm text-text-light",children:e.location_id?"Standort hinterlegt":"Standort nicht erfasst"})]}),r&&(0,t.jsx)(u,{className:"h-5 w-5 text-primary"})]}),(0,t.jsxs)("div",{className:"mt-3 grid gap-2 text-sm text-text-light sm:grid-cols-2",children:[(0,t.jsx)("span",{children:s?`Letzte Validierung: ${s.report_number}`:"Keine letzte Validierung erfasst"}),(0,t.jsx)("span",{children:s?.next_validation_on?`Naechste Revalidierung: ${s.next_validation_on}`:"Naechste Revalidierung nicht erfasst"})]})]},e.id)}),T.isLoading&&g&&(0,t.jsx)("p",{className:"rounded-lg border border-dashed border-border p-4 text-sm text-text-light",children:"Geräte werden geladen..."}),g&&!T.isLoading&&!T.isError&&(T.data?.devices.length??0)===0&&(0,t.jsx)("p",{className:"rounded-lg border border-dashed border-border p-4 text-sm text-text-light",children:"Keine Geräte gefunden."})]})]})]}),(0,t.jsxs)("section",{className:"grid gap-4 lg:grid-cols-3",children:[(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft",children:[(0,t.jsx)("h2",{className:"text-xl font-semibold",children:"3. Validierungsart"}),(0,t.jsx)("div",{className:"mt-4 grid gap-3",children:Object.entries(p).map(([e,r])=>{let s=S===e;return(0,t.jsxs)("button",{type:"button",onClick:()=>Q(e),className:`rounded-lg border px-4 py-3 text-left transition ${s?"border-primary bg-primary/5":"border-border bg-background hover:border-primary/40 hover:bg-white"}`,children:[(0,t.jsx)("p",{className:"font-medium",children:r}),(0,t.jsx)("p",{className:"mt-1 text-sm text-text-light",children:"Erstvalidierung"===e?"Neue Vorlage mit Standardchecklisten.":"Revalidierung"===e?"Letzte abgeschlossene oder freigegebene Validierung als Basis.":"Letzte Validierung als leistungsbezogene Grundlage."})]},e)})})]}),(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft lg:col-span-2",children:[(0,t.jsx)("h2",{className:"text-xl font-semibold",children:"4. Übernahme vorhandener Daten"}),(0,t.jsxs)("div",{className:"mt-4 grid gap-4 md:grid-cols-2",children:[(0,t.jsx)(m,{label:"Standort",value:M?M.name:T.data?.locations.length===1?"Automatisch übernommen":"Bitte auswählen"}),(0,t.jsx)(m,{label:"Ansprechpartner",value:_?_.full_name:T.data?.contacts.length===1?"Automatisch übernommen":"Bitte auswählen"}),(0,t.jsx)(m,{label:"Prüfer",value:P}),(0,t.jsx)(m,{label:"Vorherige Validierung",value:q?q.report_number:"Keine vorhanden"})]}),(T.data?.validations.length??0)>0&&(0,t.jsxs)("div",{className:"mt-5 rounded-lg border border-border bg-background p-4",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold uppercase tracking-wide text-text-light",children:"Letzte Validierungen"}),(0,t.jsx)("div",{className:"mt-3 grid gap-3",children:T.data?.validations.slice(0,3).map(e=>(0,t.jsxs)("div",{className:"flex flex-col gap-1 rounded-lg border border-border bg-white px-4 py-3 text-sm sm:flex-row sm:items-center sm:justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-text",children:e.report_number}),(0,t.jsxs)("p",{className:"text-text-light",children:[e.validation_type??"Validierung"," · ",e.performed_on??"nicht erfasst"]})]}),(0,t.jsx)("p",{className:"text-text-light",children:e.next_validation_on?`Naechste Revalidierung: ${e.next_validation_on}`:"Naechste Revalidierung nicht erfasst"})]},e.id))})]}),I&&(0,t.jsx)("div",{className:"mt-4 rounded-lg border border-border bg-background p-4 text-sm text-text-light",children:T.isLoading?"Vorhandene Daten werden geladen...":"Vorhandene Daten stehen bereit."})]})]}),(0,t.jsx)("footer",{className:"sticky bottom-4 z-20 rounded-lg border border-border bg-surface/95 p-4 shadow-soft backdrop-blur",children:(0,t.jsxs)("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[(0,t.jsx)("div",{className:"text-sm text-text-light",children:O?(0,t.jsx)("p",{className:"text-danger",children:O}):(0,t.jsx)("p",{children:"Nach dem Erstellen öffnet sich direkt die Bearbeitungsseite."})}),(0,t.jsxs)("button",{type:"button",disabled:!F,title:F?void 0:"Bitte Kunde und Gerät auswählen",onClick:()=>L.mutate(),className:"btn btn-primary h-12 min-w-64",children:[L.isPending?(0,t.jsx)(n,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(a,{className:"h-4 w-4"}),"Validierung erstellen und bearbeiten"]})]})})]})}],55557)}]); |