1import{j as e,d as S,e as C,aX as U,aY as V,aZ as K,B as g,a2 as u,a3 as F,av as ce,aw as le,a1 as de,ay as ue,aB as Ze,a_ as me,b_ as he,a4 as m,a8 as G}from"./index-XQyBZDTl.js";import{h as Le,i as We,f as Ke,r as _}from"./react-BOHO1DJm.js";import{T as ge}from"./textarea-DLhasB9A.js";import{S as P,a as I,b as q,c as T,d as h}from"./select-C3kVhmvh.js";import{u as Ge,a as He,c as Ye,C as Me,o as _e,s as b,d as Ne,n as E,e as xe,_ as M,b as Je}from"./schemas-B7yYgvZK.js";import{C as Xe}from"./checkbox-DFCAm8hb.js";import{C as pe}from"./calendar-B1Hlkhd4.js";import{O as Qe}from"./leadConstants-BliFTlnW.js";import{C as et}from"./chevron-up-DhbJ38Ap.js";import{T as fe}from"./trash-2-CNfqhdJB.js";import{S as tt}from"./save-HfqBhY-2.js";import{f as be,d as ve}from"./de-O0FWX8S5.js";import{Z as st}from"./compat-dFTCsGCo.js";import"./pdf-DDFMIuq6.js";import"./supabase-Di0cMgX3.js";import"./index-CR_WZPb4.js";import"./index-C6N3FhlB.js";import"./isSameDay-BVN6hXvY.js";import"./constructFrom-rJN6zrQ_.js";import"./addDays-DUX3p28w.js";import"./differenceInCalendarMonths-DdVU3xYm.js";import"./startOfMonth-BqpJtJQc.js";import"./endOfMonth-CoG5-XNs.js";const rt=_e({description:b().min(1,"Beschreibung ist erforderlich"),details:Ne(b().min(1)).optional(),quantity:E().min(0),unit:b().optional().default("Stück"),unit_price:E().min(0),total_price:E(),sort_order:E()}),at=_e({customer_id:b().min(1,"Kunde ist erforderlich"),invoice_number:b().min(1,"Rechnungsnummer ist erforderlich"),title:b().min(1,"Titel ist erforderlich"),issue_date:xe(),due_date:xe(),currency:b().min(1),body_markdown:b().default(""),subtotal:E().optional().nullable(),tax:E().optional().nullable(),total:E().optional().nullable(),status:M(["draft","sent","paid","overdue"]),items:Ne(rt).optional(),owner:b().optional().nullable(),billing_cycle:M(["once","monthly","yearly"]).default("monthly"),language:M(["de","en"]).default("de"),include_recipient_vat:Je().default(!1),recipient_vat_id:b().optional().nullable()}).superRefine((c,x)=>{c.include_recipient_vat&&!String(c.recipient_vat_id??"").trim()&&x.addIssue({code:st.custom,message:"USt-IdNr. / VAT ID ist erforderlich, wenn die Option aktiv ist.",path:["recipient_vat_id"]})}),je=c=>c?c.split(/\r?\n/).map(x=>x.replace(/^\s*-\s*/,"").trim()).filter(Boolean):[],ye=c=>{if(!c||c.length===0)return null;const x=c.map(f=>f.trim()).filter(Boolean);return x.length===0?null:x.map(f=>f.startsWith("-")?f:`- ${f}`).join(` 2`)};function Et(){const{id:c}=Le(),[x]=We(),f=Ke(),[B,J]=_.useState(!1),[we,De]=_.useState(!0),[X,H]=_.useState(null),[Se,Ce]=_.useState([]),[Ee,ke]=_.useState([]),[Q,O]=_.useState(null),N=!!c,{register:v,handleSubmit:ee,control:te,formState:{errors:p},reset:$e,watch:a,setValue:r}=Ge({resolver:He(at),defaultValues:{currency:"EUR",status:"draft",language:"de",items:[],subtotal:null,tax:null,total:null,billing_cycle:"monthly",issue_date:new Date,due_date:(()=>{const s=new Date;return s.setDate(s.getDate()+14),s})(),body_markdown:"Wir bedanken uns für die Zusammenarbeit und stellen Ihnen die folgenden Leistungen wie vereinbart in Rechnung.",include_recipient_vat:!1,recipient_vat_id:""}}),{fields:A,append:Re,remove:Fe,replace:Pe,move:se}=Ye({control:te,name:"items"}),re=async s=>{try{const{data:t,error:i}=await m.from("offers").select("title, offer_number, currency, customer_id, language").eq("id",s).single();if(i)throw i;if(t){const l=`Rechnung zu Angebot ${t.offer_number}`;r("title",l),r("currency",t.currency||"EUR"),t.language&&r("language",t.language),t.customer_id&&r("customer_id",t.customer_id)}const{data:n,error:o}=await m.from("offer_items").select("*").eq("offer_id",s).order("sort_order");if(o)throw o;if(n&&n.length>0){const l=n.map((d,w)=>({description:d.description,details:je(d.details),quantity:d.quantity,unit:d.unit||"Stück",unit_price:d.unit_price,total_price:d.total_price||d.quantity*d.unit_price,sort_order:w}));Pe(l)}}catch(t){console.error("Error loading offer:",t)}},ae=async s=>{try{const{data:t,error:i}=await m.from("offers").select("id, offer_number, title").eq("customer_id",s).order("created_at",{ascending:!1});if(i)throw i;ke(t||[]);const{data:n,error:o}=await m.from("customers").select("owner").eq("id",s).single();!o&&(n!=null&&n.owner)&&!N&&r("owner",n.owner)}catch(t){console.error("Error loading offers:",t)}};_.useEffect(()=>{(async()=>{try{if(await Ie(),N&&c)await Te();else{await qe();const t=x.get("customer_id");t&&(r("customer_id",t),await ae(t));const i=x.get("offer_id");i&&(O(i),await re(i))}}catch(t){console.error("Error initializing invoice form:",t),H((t==null?void 0:t.message)||"Fehler beim Laden des Rechnungsformulars.")}finally{De(!1)}})()},[c,N,x,r]);const Y=a("items")||[];_.useEffect(()=>{Y.forEach((t,i)=>{const n=t.quantity||0,o=t.unit_price||0,l=n*o;t.total_price!==l&&r(`items.${i}.total_price`,l,{shouldDirty:!1})});const s=Y.reduce((t,i)=>{const n=i.quantity||0,o=i.unit_price||0;return t+n*o},0);r("subtotal",s,{shouldDirty:!1}),r("tax",0,{shouldDirty:!1}),r("total",s,{shouldDirty:!1})},[Y,a,r]);const Ie=async()=>{try{const{data:s,error:t}=await m.from("customers").select("id, name").order("name");if(t)throw t;Ce(s||[])}catch(s){console.error("Error loading customers:",s),H("Kunden konnten nicht geladen werden. Bitte erneut versuchen.")}},qe=async()=>{try{try{const{data:o}=await m.rpc("generate_invoice_number");if(o){r("invoice_number",o);return}}catch{console.log("RPC function not available, using fallback")}const s=new Date().getFullYear(),{count:t}=await m.from("invoices").select("*",{count:"exact",head:!0}).like("invoice_number",`RE-${s}-%`),i=(t||0)+1,n=`RE-${s}
2-${String(i).padStart(3,"0")}`;r("invoice_number",n)}catch(s){console.error("Error generating invoice number:",s);const t=new Date().getFullYear();r("invoice_number",`RE-${t}-001`)}},Te=async()=>{if(c)try{const{data:s,error:t}=await m.from("invoices").select("*").eq("id",c).single();if(t)throw t;const{data:i,error:n}=await m.from("invoice_items").select("*").eq("invoice_id",c).order("sort_order");if(n)throw n;$e({...s,issue_date:s.issue_date?new Date(s.issue_date):new Date,due_date:s.due_date?new Date(s.due_date):(()=>{const o=new Date;return o.setDate(o.getDate()+14),o})(),body_markdown:s.body_markdown||"Wir bedanken uns für die Zusammenarbeit und stellen Ihnen die folgenden Leistungen wie vereinbart in Rechnung.",include_recipient_vat:!!s.include_recipient_vat,recipient_vat_id:s.recipient_vat_id??"",items:(i==null?void 0:i.map(o=>({...o,details:je(o.details)})))||[]})}catch(s){throw console.error("Error loading invoice:",s),G.error("Fehler beim Laden der Rechnung",{description:s.message}),H("Rechnung konnte nicht geladen werden."),s}},ie=async s=>{J(!0);try{const{items:t,include_recipient_vat:i,recipient_vat_id:n,...o}=s,l={...o,include_recipient_vat:!!i,recipient_vat_id:i&&(n==null?void 0:n.trim())||null},{data:{user:d}}=await m.auth.getUser();if(!d)throw new Error("Nicht angemeldet");const w=(t==null?void 0:t.reduce((j,D)=>{const R=D.quantity||0,y=D.unit_price||0;return j+R*y},0))||0,Z=w,Ve=Q||x.get("offer_id"),Be=x.get("contract_id");if(N&&c){const{error:j}=await m.from("invoices").update({...l,subtotal:w,tax:0,total:Z,issue_date:l.issue_date.toISOString().split("T")[0],due_date:l.due_date.toISOString().split("T")[0]}).eq("id",c);if(j)throw j;if(await m.from("invoice_items").delete().eq("invoice_id",c),t&&t.length>0){const D=t.map((y,L)=>({...y,invoice_id:c,sort_order:L,total_price:(y.quantity||0)*(y.unit_price||0),details:ye(y.details)})),{error:R}=await m.from("invoice_items").insert(D);if(R)throw R}G.success("Rechnung erfolgreich aktualisiert")}else{const{data:j,error:D}=await m.from("invoices").insert({...l,offer_id:Ve||null,contract_id:Be||null,created_by_user_id:d.id,subtotal:w,tax:0,total:Z,issue_date:l.issue_date.toISOString().split("T")[0],due_date:l.due_date.toISOString().split("T")[0]}).select().single();if(D)throw D;if(t&&t.length>0&&j){const R=j.id,y=t.map((W,Oe)=>({...W,invoice_id:R,sort_order:Oe,total_price:(W.quantity||0)*(W.unit_price||0),details:ye(W.details)})),{error:L}=await m.from("invoice_items").insert(y);if(L)throw L}G.success("Rechnung erfolgreich erstellt"),f(`/crm/invoices/${j.id}`);return}f(`/crm/invoices/${c}`)}catch(t){console.error("Error saving invoice:",t),G.error("Fehler beim Speichern",{description:t.message})}finally{J(!1)}},Ae=()=>{Re({description:"",details:[],quantity:1,unit:"Stück",unit_price:0,total_price:0,sort_order:A.length})},k=a("issue_date"),$=a("due_date");a("subtotal"),a("tax");const ze=a("total"),ne=a("currency"),z=a("include_recipient_vat"),Ue=s=>{const t=a(`items.${s}.details`)||[];r(`items.${s}.details`,[...t,""])},oe=(s,t)=>{const n=(a(`items.${s}.details`)||[]).filter((o,l)=>l!==t);r(`items.${s}.details`,n)};return we?e.jsx("div",{className:"space-y-12",children:e.jsx(S,{className:"shadow-soft border-border/40 bg-card",children:e.jsxs(C,{className:"p-6 space-y-4",children:[e.jsx("div",{className:"h-12 w-64 bg-muted animate-pulse rounded"}),e.jsx("div",{className:"h-10 w-full bg-muted animate-pulse rounded"}),e.jsx("div",{className:"h-10 w-full bg-muted animate-pulse rounded"})]})})}):X?e.jsx("div",{className:"space-y-8",children:e.jsxs(S,{className:"shadow-soft border-border/40 bg-card",children:[e.jsxs(U,{className:"pb-5",children:[e.jsx(V,{className:"font-body text-xl font-semibold text-foreground",children:"Fehler beim Laden"}),e.jsx(K,{className:"font-body text-sm text-muted-foreground mt-2",children:X})]}),e.jsxs(C,{className:"flex gap-3",children:[e.jsx(g,{onClick:()=>f(-1),variant:"outline",className:"font-body border-border/40 hover:bg-muted transition-smooth",children:"Zurück"}),e.jsx(g,{onClick:()=>window.location.reload(),className:"font-body bg-primary text-primary-foreground hover:bg-primary-hover transition-smooth",children:"Neu laden"})]})]})}):e.jsxs("div",{className:"space-y-12",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-body text-3xl font-bold text-foreground mb-3",children:N?"Rechnung bearbeiten":"Neue Rechnung"}),e.jsx("p",{className:"text-muted-foreground font-body text-lg max-w-2xl",children:N?"Rechnung aktualisieren":"Erstellen Sie eine neue Rechnung"})]}),e.jsxs("form",{onSubmit:ee(ie),className:"space-y-8",children:[e.jsxs(S,{className:"shadow-soft border-border/40 bg-card",children:[e.jsx(U,{className:"pb-5",children:e.jsx(V,{className:"font-body text-xl font-semibold text-foreground",children:"Grunddaten"})}),e.jsxs(C,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{htmlFor:"customer_id",children:["Kunde ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(P,{value:a("customer_id")||"",onValueChange:async s=>{r("customer_id",s),O(null),await ae(s)},children:[e.jsx(I,{children:e.jsx(q,{placeholder:"Kunde auswählen"})}),e.jsx(T,{children:Se.map(s=>e.jsx(h,{value:s.id,children:s.name},s.id))})]}),p.customer_id&&e.jsx("p",{className:"text-sm text-destructive",children:p.customer_id.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"offer_id",children:"Angebot (optional)"}),e.jsxs(P,{value:Q||"none",onValueChange:async s=>{s==="none"?O(null):(O(s),await re(s))},disabled:!a("customer_id"),children:[e.jsx(I,{id:"offer_id",children:e.jsx(q,{placeholder:"Angebot auswählen"})}),e.jsxs(T,{children:[e.jsx(h,{value:"none",children:"Kein Angebot"}),Ee.map(s=>e.jsxs(h,{value:s.id,children:[s.offer_number," - ",s.title]},s.id))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Positionen und Preise werden aus dem Angebot übernommen"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"currency",children:"Währung"}),e.jsxs(P,{value:a("currency")||"EUR",onValueChange:s=>r("currency",s),children:[e.jsx(I,{id:"currency",children:e.jsx(q,{placeholder:"Währung auswählen"})}),e.jsxs(T,{children:[e.jsx(h,{value:"EUR",children:"EUR (Euro)"}),e.jsx(h,{value:"CHF",children:"CHF (Schweizer Franken)"}),e.jsx(h,{value:"USD",children:"USD (US-Dollar)"}),e.jsx(h,{value:"GBP",children:"GBP (Britisches Pfund)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"language",children:"Sprache"}),e.jsxs(P,{value:a("language")||"de",onValueChange:s=>r("language",s),children:[e.jsx(I,{id:"language",children:e.jsx(q,{placeholder:"Sprache auswählen"})}),e.jsxs(T,{children:[e.jsx(h,{value:"de",children:"Deutsch"}),e.jsx(h,{value:"en",children:"Englisch"})]})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"owner",children:"Zuständig"}),e.jsxs(P,{value:a("owner")||"_none",onValueChange:s=>r("owner",s==="_none"?null:s),children:[e.jsx(I,{children:e.jsx(q,{placeholder:"Zuständig auswählen"})}),e.jsxs(T,{children:[e.jsx(h,{value:"_none",children:"Nicht zugewiesen"}),Qe.map(s=>e.jsx(h,{value:s,children:s},s))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Automatisch vom Kunden übernommen. Kann angepasst werden."})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"billing_cycle",children:"Zahlungsintervall"}),e.jsxs(P,{value:a("billing_cycle")||"monthly",onValueChange:s=>r("billing_cycle",s),children:[e.jsx(I,{id:"billing_cycle",children:e.jsx(q,{placeholder:"Zahlungsintervall wählen"})}),e.jsxs(T,{children:[e.jsx(h,{value:"once",children:"Einmalig"}),e.jsx(h,{value:"monthly",children:"Monatlich"}),e.jsx(h,{value:"yearly",children:"Jährlich"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Wird im Vertrag bei §2 Vergütung übernommen."})]}),e.jsx("div",{})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{htmlFor:"invoice_number",children:["Rechnungsnummer ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(F,{id:"invoice_number",...v("invoice_number"),placeholder:"RE-2025-001"}),p.invoice_number&&e.jsx("p",{className:"text-sm text-destructive",children:p.invoice_number.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{htmlFor:"title",children:["Titel ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(F,{id:"title",...v("title"),placeholder:"Rechnung für Dienstleistungen"}),p.title&&e.jsx("p",{className:"text-sm text-destructive",children:p.title.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{htmlFor:"issue_date",children:["Rechnungsdatum ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(ce,{children:[e.jsx(le,{asChild:!0,children:e.jsx(g,{variant:"outline",className:de("w-full justify-start text-left font-normal",!k&&"text-muted-foreground"),children:k?be(k,"PPP",{locale:ve}):e.jsx("span",{children:"Datum auswählen"})})}),e.jsx(ue,{className:"w-auto p-0",align:"start",children:e.jsx(pe,{mode:"single",selected:k,onSelect:s=>{if(r("issue_date",s||new Date),!$&&s){const t=new Date(s);t.setDate(t.getDate()+14),r("due_date",t)}else if(s&&$){const t=new Date(s);t.setDate(t.getDate()+14),r("due_date",t)}},initialFocus:!0})})]}),p.issue_date&&e.jsx("p",{className:"text-sm text-destructive",children:p.issue_date.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"due_date",children:"Fälligkeitsdatum *"}),e.jsxs(ce,{children:[e.jsx(le,{asChild:!0,children:e.jsx(g,{variant:"outline",className:de("w-full justify-start text-left font-normal",!$&&"text-muted-foreground"),children:$?be($,"PPP",{locale:ve}):e.jsx("span",{children:"Datum auswählen"})})}),e.jsx(ue,{className:"w-auto p-0",align:"start",children:e.jsx(pe,{mode:"single",selected:$||void 0,onSelect:s=>{if(s)r("due_date",s);else if(k){const t=new Date(k);t.setDate(t.getDate()+14),r("due_date",t)}},initialFocus:!0})})]}),p.due_date&&e.jsx("p",{className:"text-sm text-destructive",children:p.due_date.message})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 pt-2 border-t border-border/40",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"text-muted-foreground text-xs font-normal uppercase tracking-wide",children:"Rechnungsvorlage (PDF)"}),e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Me,{name:"include_recipient_vat",control:te,render:({field:s})=>e.jsx(Xe,{id:"include_recipient_vat",checked:s.value,onCheckedChange:t=>s.onChange(t===!0),className:"mt-0.5"})}),e.jsx(u,{htmlFor:"include_recipient_vat",className:"text-sm font-normal leading-snug cursor-pointer text-foreground",children:"Gültige USt-IdNr. / VAT ID des Empfängers auf der Rechnung ausweisen"})]}),e.jsx("p",{className:"text-xs text-muted-foreground pl-7",children:"Im PDF erscheint die Empfängeradresse wie gewohnt; bei Aktivierung zusätzlich die Zeile âVAT ID / USt-IdNr.: â¦â mit der eingetragenen Nummer."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{htmlFor:"recipient_vat_id",className:z?"":"text-muted-foreground",children:["USt-IdNr. / VAT ID ",z&&e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(F,{id:"recipient_vat_id",...v("recipient_vat_id"),placeholder:z?"z. B. DE123456789":"Zuerst Option links aktivieren",autoComplete:"off",readOnly:!z,className:z?"":"bg-muted/50 cursor-not-allowed"}),p.recipient_vat_id&&e.jsx("p",{className:"text-sm text-destructive",children:p.recipient_vat_id.message})]})]})]})]}),e.jsxs(S,{className:"shadow-soft border-border/40 bg-card",children:[e.jsxs(U,{className:"pb-5",children:[e.jsx(V,{className:"font-body text-xl font-semibold text-foreground",children:"Rechnungstext"}),e.jsx(K,{className:"font-body text-sm text-muted-foreground mt-2",children:"Text, der im PDF angezeigt wird"})]}),e.jsx(C,{children:e.jsx("div",{className:"space-y-2",children:e.jsx(ge,{...v("body_markdown"),placeholder:"Wir bedanken uns für die Zusammenarbeit und stellen Ihnen die folgenden Leistungen wie vereinbart in Rechnung.",rows:4,className:"font-mono text-sm"})})})]}),e.jsxs(S,{className:"shadow-soft border-border/40 bg-card",children:[e.jsxs(U,{className:"pb-5",children:[e.jsx(V,{className:"font-body text-xl font-semibold text-foreground",children:"Positionen"}),e.jsx(K,{className:"font-body text-sm text-muted-foreground mt-2",children:"Rechnungspositionen mit Preisen"})]}),e.jsx(C,{children:e.jsxs("div",{className:"space-y-6",children:[A.map((s,t)=>{const i=a(`items.${t}.quantity`)||0,n=a(`items.${t}.unit_price`)||0,o=i*n;return e.jsxs(S,{className:"shadow-soft border-border/40 bg-card",children:[e.jsx(U,{className:"pb-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(V,{className:"font-body text-lg font-semibold text-foreground",children:["Position ",t+1]}),e.jsx(K,{className:"font-body text-sm text-muted-foreground mt-1",children:"Leistungsbeschreibung"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(g,{type:"button",variant:"ghost",size:"icon",onClick:()=>{t>0&&se(t,t-1)},disabled:t===0,className:"h-7 w-7 text-muted-foreground hover:text-foreground disabled:opacity-30 disabled:cursor-not-allowed",title:"Nach oben verschieben",children:e.jsx(et,{className:"h-4 w-4"})}),e.jsx(g,{type:"button",variant:"ghost",size:"icon",onClick:()=>{t<A.length-1&&se(t,t+1)},disabled:t===A.length-1,className:"h-7 w-7 text-muted-foreground hover:text-foreground disabled:opacity-30 disabled:cursor-not-allowed",title:"Nach unten verschieben",children:e.jsx(Ze,{className:"h-4 w-4"})})]}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:()=>Fe(t),className:"text-destructive hover:text-destructive",title:"Position löschen",children:e.jsx(fe,{className:"h-4 w-4"})})]})]})}),e.jsx(C,{children:e.jsxs("div",{className:"grid grid-cols-12 gap-4",children:[e.jsxs("div",{className:"col-span-12 md:col-span-7 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:`items.${t}.description`,children:"Beschreibung"}),e.jsx(ge,{id:`items.${t}.description`,rows:4,...v(`items.${t}.description`),placeholder:"Beschreibung"})]}),e.jsxs("div",{className:"rounded-xl bg-white border border-gray-200 shadow-sm p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(u,{className:"text-[10px] font-medium uppercase tracking-wider text-gray-500",children:"Unterpunkte"}),e.jsxs(g,{type:"button",size:"sm",variant:"ghost",onClick:()=>Ue(t),className:"h-7 px-3 text-xs font-normal text-gray-700 hover:text-gray-900 hover:bg-gray-50 rounded-lg border border-gray-200 transition-all",children:[e.jsx(me,{className:"mr-1.5 h-3.5 w-3.5"}),"Hinzufügen"]})]}),e.jsxs("div",{className:"space-y-2.5",children:[(a(`items.${t}.details`)||[]).map((l,d)=>e.jsxs("div",{className:"flex items-center gap-2.5 group",children:[e.jsx(F,{...v(`items.${t}.details.${d}`),placeholder:"Unterpunkt eingeben",className:"flex-1 text-sm h-10 rounded-lg border border-gray-200 bg-white shadow-sm focus:border-gray-300 focus:ring-1 focus:ring-gray-200 focus:bg-white focus:shadow-md transition-all placeholder:text-gray-400 text-gray-900 font-normal",onBlur:w=>{const Z=a(`items.${t}.details`)||[];!w.target.value.trim()&&Z.length>0&&oe(t,d)}}),e.jsx(g,{type:"button",variant:"ghost",size:"icon",onClick:()=>oe(t,d),className:"h-10 w-10 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-lg flex-shrink-0 transition-all opacity-70 group-hover:opacity-100",children:e.jsx(fe,{className:"h-4 w-4"})})]},`${s.id}-detail-${d}`)),(a(`items.${t}.details`)||[]).length===0&&e.jsx("p",{className:"text-xs text-gray-400 py-3 text-center",children:"Noch keine Unterpunkte hinzugefügt"})]})]})]}),e.jsxs("div",{className:"col-span-12 md:col-span-5 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:`items.${t}.quantity`,chi
2ldren:"Menge"}),e.jsx(F,{id:`items.${t}.quantity`,type:"number",step:"0.01",...v(`items.${t}.quantity`,{valueAsNumber:!0,onChange:()=>{const l=a(`items.${t}.quantity`)||0,d=a(`items.${t}.unit_price`)||0;r(`items.${t}.total_price`,l*d)}})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:`items.${t}.unit_price`,children:"Einzelpreis"}),e.jsx(F,{id:`items.${t}.unit_price`,type:"number",step:"0.01",className:"text-right",...v(`items.${t}.unit_price`,{valueAsNumber:!0,onChange:()=>{const l=a(`items.${t}.quantity`)||0,d=a(`items.${t}.unit_price`)||0;r(`items.${t}.total_price`,l*d)}})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:`items.${t}.total`,children:"Gesamt"}),e.jsx("div",{className:"flex h-10 w-full rounded-md border border-input bg-muted px-3 py-2 text-right font-bold text-sm items-center justify-end",children:he(o,ne)})]})]})]})]})})]},s.id)}),e.jsxs(g,{type:"button",variant:"outline",onClick:Ae,className:"w-full",children:[e.jsx(me,{className:"mr-2 h-4 w-4"}),"Position hinzufügen"]}),A.length>0&&e.jsx(S,{className:"shadow-soft border-border/40 bg-card",children:e.jsx(C,{className:"pt-6",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsx("div",{className:"text-base text-muted-foreground font-body",children:"Rechnungssumme"}),e.jsx("div",{className:"space-y-2 text-right min-w-[240px]",children:e.jsxs("div",{className:"flex justify-between items-center pt-2 border-t border-border/40",children:[e.jsx("span",{className:"text-base font-body font-semibold",children:"Gesamtbetrag:"}),e.jsx("span",{className:"font-body text-xl font-semibold",children:he(ze||0,ne)})]})})]})})})]})})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(g,{type:"button",variant:"outline",onClick:()=>f(-1),className:"font-body border-border/40 hover:bg-muted transition-smooth",children:"Abbrechen"}),e.jsxs(g,{type:"button",variant:"outline",onClick:ee(ie),disabled:B,className:"font-body border-border/40 hover:bg-primary hover:text-primary-foreground hover:border-primary transition-smooth",children:[e.jsx(tt,{className:"mr-2 h-4 w-4"}),B?"Speichern...":"Als Entwurf speichern"]}),e.jsx(g,{type:"submit",disabled:B,className:"bg-primary text-primary-foreground hover:bg-primary-hover transition-smooth font-body tracking-wide shadow-soft hover:shadow-medium",children:B?"Speichern...":N?"Aktualisieren":"Erstellen"})]})]})]})}export{Et as default};
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.