import{i as _,x as M,c as i,a as e,t as l,f as u,g as h,d as p,v as m,F as b,k as y,e as v,y as V,w as k,T as j,r as c,h as B,o as n}from"./index-DWNalbut.js";import{u as $}from"./contacts-B_I94NMP.js";import{u as z}from"./index-DeJ0q2c_.js";const E={class:"p-4 sm:p-6"},K={class:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6"},T={class:"text-pulse-muted text-sm"},U={class:"mb-6"},S={class:"relative w-full sm:max-w-md"},F={class:"card hidden md:block"},D={class:"table-container"},H={class:"table"},L=["onClick"],q={class:"flex items-center gap-3"},P={class:"w-9 h-9 rounded-full bg-primary-600 flex items-center justify-center text-white text-sm font-medium flex-shrink-0"},A={class:"font-medium text-white"},G={class:"text-pulse-muted"},I={class:"text-pulse-muted"},R={key:0,class:"text-pulse-text"},J={key:1,class:"text-pulse-muted"},O={class:"text-pulse-muted"},Q={class:"md:hidden space-y-3"},W=["onClick"],X={class:"flex items-start gap-3"},Y={class:"w-10 h-10 rounded-full bg-primary-600 flex items-center justify-center text-white text-sm font-medium flex-shrink-0"},Z={class:"flex-1 min-w-0"},ee={class:"font-medium text-white"},te={key:0,class:"text-sm text-pulse-muted"},se={key:1,class:"text-sm text-primary-400"},le={class:"mt-2 flex flex-wrap gap-2"},oe=["href"],ne=["href"],ie={key:0,class:"card p-8 sm:p-12 text-center"},ae={key:0,class:"fixed inset-0 z-50 flex items-end sm:items-center justify-center p-0 sm:p-4"},re={class:"relative card w-full sm:max-w-lg rounded-b-none sm:rounded-b-xl max-h-[90vh] overflow-y-auto"},de={class:"px-4 sm:px-6 py-4 border-b border-pulse-border sticky top-0 bg-pulse-card z-10"},ue={class:"flex items-center justify-between"},pe={class:"grid grid-cols-1 sm:grid-cols-2 gap-4"},me={class:"flex flex-col-reverse sm:flex-row gap-3 pt-2"},ke={__name:"ContactsView",setup(ve){const f=B(),a=$(),x=c(""),r=c(!1),o=c({firstName:"",lastName:"",email:"",phone:"",position:""});_(()=>{a.fetchContacts()});const g=z(()=>{a.fetchContacts({search:x.value})},300);M(x,g);async function C(){if(!(!o.value.firstName||!o.value.lastName))try{const d=await a.createContact(o.value);r.value=!1,o.value={firstName:"",lastName:"",email:"",phone:"",position:""},f.push(`/contacts/${d.id}`)}catch(d){console.error("Error:",d)}}function w(d){var t,s;return(((t=d.firstName)==null?void 0:t[0])||"")+(((s=d.lastName)==null?void 0:s[0])||"")}return(d,t)=>(n(),i("div",E,[e("div",K,[e("div",null,[t[13]||(t[13]=e("h1",{class:"text-xl sm:text-2xl font-bold text-white"},"Kontakte",-1)),e("p",T,l(u(a).meta.total)+" Kontakte",1)]),e("button",{onClick:t[0]||(t[0]=s=>r.value=!0),class:"btn-primary w-full sm:w-auto"},[...t[14]||(t[14]=[e("svg",{class:"w-5 h-5 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),h(" Neuer Kontakt ",-1)])])]),e("div",U,[e("div",S,[t[15]||(t[15]=e("svg",{class:"absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-pulse-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)),p(e("input",{"onUpdate:modelValue":t[1]||(t[1]=s=>x.value=s),type:"text",class:"input pl-10 w-full",placeholder:"Suchen..."},null,512),[[m,x.value]])])]),e("div",F,[e("div",D,[e("table",H,[t[16]||(t[16]=e("thead",null,[e("tr",null,[e("th",null,"Name"),e("th",null,"E-Mail"),e("th",null,"Telefon"),e("th",null,"Firma"),e("th",null,"Position")])],-1)),e("tbody",null,[(n(!0),i(b,null,y(u(a).contacts,s=>(n(),i("tr",{key:s.id,class:"cursor-pointer",onClick:N=>u(f).push(`/contacts/${s.id}`)},[e("td",null,[e("div",q,[e("div",P,l(w(s)),1),e("div",null,[e("p",A,l(s.firstName)+" "+l(s.lastName),1)])])]),e("td",G,l(s.email||"-"),1),e("td",I,l(s.phone||"-"),1),e("td",null,[s.company?(n(),i("span",R,l(s.company.name),1)):(n(),i("span",J,"-"))]),e("td",O,l(s.position||"-"),1)],8,L))),128))])])])]),e("div",Q,[(n(!0),i(b,null,y(u(a).contacts,s=>(n(),i("div",{key:s.id,class:"card p-4 cursor-pointer active:scale-[0.98] transition-transform",onClick:N=>u(f).push(`/contacts/${s.id}`)},[e("div",X,[e("div",Y,l(w(s)),1),e("div",Z,[e("p",ee,l(s.firstName)+" "+l(s.lastName),1),s.position?(n(),i("p",te,l(s.position),1)):v("",!0),s.company?(n(),i("p",se,l(s.company.name),1)):v("",!0),e("div",le,[s.email?(n(),i("a",{key:0,href:`mailto:${s.email}`,onClick:t[2]||(t[2]=k(()=>{},["stop"])),class:"inline-flex items-center gap-1 text-xs text-pulse-muted hover:text-white px-2 py-1 bg-pulse-dark rounded"},[t[17]||(t[17]=e("svg",{class:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})],-1)),h(" "+l(s.email),1)],8,oe)):v("",!0),s.phone?(n(),i("a",{key:1,href:`tel:${s.phone}`,onClick:t[3]||(t[3]=k(()=>{},["stop"])),class:"inline-flex items-center gap-1 text-xs text-pulse-muted hover:text-white px-2 py-1 bg-pulse-dark rounded"},[t[18]||(t[18]=e("svg",{class:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"})],-1)),h(" "+l(s.phone),1)],8,ne)):v("",!0)])]),t[19]||(t[19]=e("svg",{class:"w-5 h-5 text-pulse-muted flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 5l7 7-7 7"})],-1))])],8,W))),128))]),!u(a).loading&&!u(a).contacts.length?(n(),i("div",ie,[t[20]||(t[20]=e("svg",{class:"w-12 sm:w-16 h-12 sm:h-16 mx-auto mb-4 text-pulse-muted opacity-50",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"})],-1)),t[21]||(t[21]=e("p",{class:"text-pulse-muted"},"Noch keine Kontakte vorhanden",-1)),e("button",{onClick:t[4]||(t[4]=s=>r.value=!0),class:"btn-primary mt-4"}," Ersten Kontakt anlegen ")])):v("",!0),(n(),V(j,{to:"body"},[r.value?(n(),i("div",ae,[e("div",{class:"absolute inset-0 bg-black/60",onClick:t[5]||(t[5]=s=>r.value=!1)}),e("div",re,[e("div",de,[e("div",ue,[t[23]||(t[23]=e("h2",{class:"text-lg font-semibold text-white"},"Neuer Kontakt",-1)),e("button",{onClick:t[6]||(t[6]=s=>r.value=!1),class:"p-2 text-pulse-muted hover:text-white sm:hidden"},[...t[22]||(t[22]=[e("svg",{class:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])])])]),e("form",{onSubmit:k(C,["prevent"]),class:"p-4 sm:p-6 space-y-4"},[e("div",pe,[e("div",null,[t[24]||(t[24]=e("label",{class:"label"},"Vorname *",-1)),p(e("input",{"onUpdate:modelValue":t[7]||(t[7]=s=>o.value.firstName=s),type:"text",class:"input",required:""},null,512),[[m,o.value.firstName]])]),e("div",null,[t[25]||(t[25]=e("label",{class:"label"},"Nachname *",-1)),p(e("input",{"onUpdate:modelValue":t[8]||(t[8]=s=>o.value.lastName=s),type:"text",class:"input",required:""},null,512),[[m,o.value.lastName]])])]),e("div",null,[t[26]||(t[26]=e("label",{class:"label"},"E-Mail",-1)),p(e("input",{"onUpdate:modelValue":t[9]||(t[9]=s=>o.value.email=s),type:"email",class:"input",placeholder:"name@firma.de"},null,512),[[m,o.value.email]])]),e("div",null,[t[27]||(t[27]=e("label",{class:"label"},"Telefon",-1)),p(e("input",{"onUpdate:modelValue":t[10]||(t[10]=s=>o.value.phone=s),type:"tel",class:"input",placeholder:"+49 123 456789"},null,512),[[m,o.value.phone]])]),e("div",null,[t[28]||(t[28]=e("label",{class:"label"},"Position",-1)),p(e("input",{"onUpdate:modelValue":t[11]||(t[11]=s=>o.value.position=s),type:"text",class:"input",placeholder:"z.B. Geschäftsführer"},null,512),[[m,o.value.position]])]),e("div",me,[e("button",{type:"button",onClick:t[12]||(t[12]=s=>r.value=!1),class:"btn-secondary flex-1"}," Abbrechen "),t[29]||(t[29]=e("button",{type:"submit",class:"btn-primary flex-1"}," Erstellen ",-1))])],32)])])):v("",!0)]))]))}};export{ke as default};