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