import{m as b,r as x,a as y,j as s,L as z}from"./app-D_lWdAF1.js";import{B as j,A}from"./Add-B_lToW0R.js";import{F as n,C as I}from"./Close-CmjhMxa1.js";import{I as o}from"./input-iieIymNx.js";import{S as l,C as N,a as L}from"./CardContent-ngFHB7Px.js";import{A as S}from"./app-layout-DBWaGSby.js";import{I as i}from"./input-error-Dz46bbCi.js";import{T as _,G as a}from"./Typography-D06EX7-K.js";import"./app-gFGt7Tbg.js";import"./app-logo-icon-B18IWF-o.js";import"./slots-DhmpWYGS.js";import"./index-DKsctv8k.js";import"./index--DsFJTFe.js";const B=[{title:"Invoices",href:"/invoices"},{title:"Create",href:"#"}];function K(c){const{data:r,setData:t,post:h,errors:d,reset:p}=b({customer_id:"",interior_designer_id:"",address:{customer_address_id:"",address_line_1:"",address_line_2:"",city:"",state:"",postal_code:"",country:"India"}}),g=c.customers??[],C=c.interior_designers??[],[v,m]=x.useState([]),f=e=>{e.preventDefault(),h(route("invoices.store"),{onFinish:()=>{}})};return x.useEffect(()=>{r.customer_id&&(m([]),p("address"),y.post(route("customer_addresses.options"),{customer_id:r.customer_id}).then(e=>{const{data:u}=e;u.success&&m(u.data)}).catch(e=>{console.error("Failed to fetch addresses",e)}))},[r.customer_id]),s.jsxs(S,{breadcrumbs:B,children:[s.jsx(z,{title:"Create Invoice"}),s.jsxs(n,{children:[s.jsx(n.Title,{children:s.jsx(_,{variant:"h6",gutterBottom:!0,children:"Create Invoice"})}),s.jsx(n.Body,{children:s.jsx("form",{onSubmit:f,children:s.jsxs(a,{container:!0,spacing:2,children:[s.jsxs(a,{size:12,children:[s.jsx(l,{options:g,label:"Customer",value:r.customer_id,onChange:e=>t("customer_id",e.target.value)}),s.jsx(i,{message:d.customer_id,className:"mt-2"})]}),s.jsx(a,{size:12,children:s.jsx(l,{options:C,label:"Interior Designer",value:r.interior_designer_id,onChange:e=>t("interior_designer_id",e.target.value)})}),r.customer_id!=""&&s.jsxs(a,{size:12,children:[s.jsx(l,{create:"true",options:v,label:"Address",value:r.address.customer_address_id,onChange:e=>t("address",{...r.address,customer_address_id:e.target.value})}),s.jsx(i,{message:d["address.customer_address_id"],className:"mt-2"})]}),r.address.customer_address_id=="0"&&s.jsx(N,{variant:"outlined",className:"w-full",children:s.jsxs(L,{children:[s.jsx(_,{variant:"h5",component:"div",children:"Create New Address"}),s.jsxs(a,{container:!0,spacing:2,style:{marginTop:"20px"},children:[s.jsxs(a,{size:12,children:[s.jsx(o,{size:"small",label:"Address Line 1",onChange:e=>t("address",{...r.address,address_line_1:e.target.value})}),s.jsx(i,{message:d["address.address_line_1"],className:"mt-2"})]}),s.jsxs(a,{size:12,children:[s.jsx(o,{size:"small",label:"Address Line 2",onChange:e=>t("address",{...r.address,address_line_2:e.target.value})}),s.jsx(i,{message:d["address.address_line_2"],className:"mt-2"})]}),s.jsxs(a,{size:4,children:[s.jsx(o,{size:"small",label:"City",onChange:e=>t("address",{...r.address,city:e.target.value})}),s.jsx(i,{message:d["address.city"],className:"mt-2"})]}),s.jsxs(a,{size:4,children:[s.jsx(o,{size:"small",label:"State",onChange:e=>t("address",{...r.address,state:e.target.value})}),s.jsx(i,{message:d["address.state"],className:"mt-2"})]}),s.jsxs(a,{size:4,children:[s.jsx(o,{size:"small",label:"Postal code",onChange:e=>t("address",{...r.address,postal_code:e.target.value})}),s.jsx(i,{message:d["address.postal_code"],className:"mt-2"})]}),s.jsx(a,{size:12,children:s.jsx(o,{size:"small",value:r.address.country,disabled:!0,label:"Country"})})]})]})}),s.jsxs(a,{size:12,children:[s.jsx(j,{type:"submit",startIcon:s.jsx(A,{}),children:"Create"}),s.jsx(j,{style:{marginLeft:"10px"},color:"error",href:route("invoices.index"),startIcon:s.jsx(I,{}),children:"Cancel"})]})]})})})]})]})}export{K as default};
