import{r as c,j as e,a as d}from"./app-D_lWdAF1.js";import{D as x,S as D,A as g,a as T}from"./show-html-DbV63_wc.js";import{B as w,I as z}from"./input-iieIymNx.js";import{A as S,P as W,C as k}from"./app-layout-DBWaGSby.js";import{G as r,T as n}from"./Typography-D06EX7-K.js";import{C as B,a as E}from"./CardContent-ngFHB7Px.js";import"./app-gFGt7Tbg.js";import"./app-logo-icon-B18IWF-o.js";import"./Add-B_lToW0R.js";import"./index-DKsctv8k.js";import"./index--DsFJTFe.js";function q(v){const{invoice_id:o}=v,b=[{title:"Invoices",href:"/invoices"},{title:"Invoice Items",href:"#"}],[s,h]=c.useState({}),[u,j]=c.useState({}),l=async()=>{if(o){const{data:i}=await d.get(route("invoices.show",{invoice:o,with:"items"}));i.success&&(f(!1),h(i.data))}},p=async i=>{i.invoice_id=o;const{data:t}=await d.post(route("invoices.items.store",{invoice:o}),{...i});t.success&&(l(),j(a=>({...a,[i.section_id]:!1})))},y=async i=>{if(confirm("are you sure you want to delete this item")){const{data:a}=await d.delete(route("invoices.items.destroy",{invoice:o,item:i}));a.success&&l()}},m=c.useRef(null),_=i=>{const t=i.target.value;h({...s,notes:t}),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{d.post(route("invoices.update.notes",{invoice:o}),{notes:t})},800)},[I,f]=c.useState(!1),C=async i=>{i.invoice_id=o;const{data:t}=await d.post(route("invoices.sections.store",{invoice:o}),i);t.success&&l()},A=i=>{j(t=>({...t,[i]:!t[i]}))};return c.useEffect(()=>{f(!0),l()},[o]),e.jsx(S,{breadcrumbs:b,children:e.jsxs(W,{elevation:3,sx:{p:4},style:{backgroundColor:"rgb(253 244 235 / 28%)"},children:[e.jsx(w,{open:I,style:{zIndex:111111,color:"#fff"},children:e.jsx(k,{color:"inherit"})}),e.jsxs(r,{container:!0,spacing:2,children:[e.jsxs(r,{size:8,children:[e.jsx(n,{variant:"h4",sx:{fontWeight:"bold"},children:s.business_name}),e.jsx("b",{children:s.user_name}),e.jsx("br",{}),e.jsx("b",{children:"Phone:"})," ",e.jsx("a",{href:"tel:{{ $user_mobile }}",children:s.user_mobile}),e.jsx("br",{}),e.jsx("b",{children:"Email:"})," ",e.jsx("a",{href:"mailto:{{ $user_email }}",children:s.user_email}),e.jsx("br",{})]}),e.jsxs(r,{size:4,textAlign:"right",children:[e.jsx(n,{variant:"h4",sx:{fontWeight:"bold"},children:"Invoice"}),e.jsx("b",{children:"Invoice:"})," ",s.invoice_number_display,e.jsx("br",{})]})]}),e.jsx(x,{sx:{my:3}}),e.jsxs(r,{container:!0,spacing:2,children:[e.jsxs(r,{size:6,children:[e.jsx(n,{fontWeight:"bold",children:"To:"}),e.jsx(n,{style:{marginTop:"20px",fontWeight:"bold"},children:s.customer_name}),e.jsx(D,{content:s.customer_address})]}),s.interior_designer_id&&e.jsxs(r,{size:6,children:[e.jsx(n,{fontWeight:"bold",children:"Interior Designer:"}),e.jsx(n,{style:{marginTop:"20px",fontWeight:"bold"},children:s.interior_designer_name}),s.interior_designer_mobile&&e.jsx(n,{children:e.jsx("a",{href:`tel:${s.interior_designer_mobile}`,children:s.interior_designer_mobile})}),s.interior_designer_email&&e.jsx(n,{children:e.jsx("a",{href:`mailto:${s.interior_designer_email}`,children:s.interior_designer_email})})]})]}),e.jsx(x,{sx:{my:3}}),s.sections&&s.sections.map((i,t)=>e.jsx(B,{style:{marginTop:"20px",borderLeft:"4px solid rgb(229 168 107)",borderRadius:"10px 0px 0px 10px"},children:e.jsxs(E,{style:{backgroundColor:"#fffdf7"},children:[e.jsx(n,{gutterBottom:!0,variant:"h5",component:"div",children:i.title}),e.jsxs(n,{variant:"body2",sx:{color:"text.secondary"},children:[i.items&&i.items.length>0?i.items.map(a=>e.jsx("div",{style:{marginBottom:"10px"},children:e.jsx(g,{onItemAdd:p,onItemDelete:y,item:a,onlyDisplay:!0},a.id)})):e.jsx("div",{children:"No items Added"}),e.jsx("br",{}),e.jsx("a",{onClick:()=>A(i.id),href:"javascript:void(0)",style:{cursor:"pointer",textDecoration:"underline"},children:u[i.id]?"Cancel":"Add Item"}),u[i.id]&&e.jsx("div",{style:{marginTop:"10px"},children:e.jsx(g,{onItemAdd:a=>p({...a,invoice_section_id:i.id}),section_id:i.id})})]})]})},i.id||t)),e.jsx(r,{container:!0,style:{marginTop:"20px"},children:e.jsx(r,{size:12,children:e.jsx(T,{onCreate:C})})}),e.jsx(x,{sx:{my:3}}),e.jsx(r,{container:!0,spacing:2,children:e.jsx(r,{size:12,children:e.jsx(z,{defaultValue:s.notes,onChange:i=>_(i),size:"small",label:"Note",fullWidth:!0,multiline:!0,rows:3})})})]})})}export{q as default};
