import{r,u as I,j as t,D as l}from"./index-DlcHsm52.js";import{F as a,g,C as N,B as d,a as E,T as F,S as p,I as Q,b as y,r as c,s as T}from"./IdurarOs-j0IoqkpA.js";import{W as k}from"./shared-N8zi2N1N.js";import{c as O}from"./ErpApp-7VdZNpBd.js";import{c as _}from"./currencyList-mYH1Mcza.js";import{u as v}from"./useMoney-DK8w0tFT.js";import{M as R}from"./index-Clbw7Jrz.js";import{R as A}from"./ReloadOutlined-C37-gl6w.js";const P=_();function K(){const[x,h]=r.useState([]),[f,j]=r.useState([]),[C,u]=r.useState(!1),[b,i]=r.useState(!1),[n]=a.useForm(),q=I(g),{moneyFormatter:w}=v(),m=O(q,"quote","create"),o=async()=>{u(!0);const[e,s]=await Promise.all([c.list({entity:"quote",options:{page:1,items:100}}),c.list({entity:"client",options:{page:1,items:100}})]);h((e==null?void 0:e.result)||[]),j((s==null?void 0:s.result)||[]),u(!1)};r.useEffect(()=>{o()},[]);const S=async()=>{const e=await n.validateFields();await c.create({entity:"quote",jsonData:{...e,items:[{itemName:e.itemName,quantity:e.quantity,price:e.price,total:e.quantity*e.price}],total:e.quantity*e.price,subTotal:e.quantity*e.price,currency:e.currency||l}}),T.success("Quote created"),i(!1),n.resetFields(),o()};return t.jsxs(k,{title:"Quote Workbench",description:"Create and manage quotes without leaving the sales flow.",permission:"sales.quote.read",extra:t.jsxs(N,{children:[t.jsx(d,{icon:t.jsx(A,{}),onClick:o,children:"Refresh"}),t.jsx(d,{type:"primary",disabled:!m,onClick:()=>i(!0),children:"New Quote"})]}),children:[t.jsx(E,{rowKey:"_id",loading:C,dataSource:x,pagination:!1,columns:[{title:"Number",dataIndex:"number"},{title:"Client",dataIndex:["client","name"]},{title:"Total",render:(e,s)=>w({amount:s.total||0,currency_code:s.currency||l})},{title:"Status",dataIndex:"status",render:e=>t.jsx(F,{children:e})}]}),t.jsx(R,{title:"New Quote",open:b,onCancel:()=>i(!1),onOk:S,okButtonProps:{disabled:!m},children:t.jsxs(a,{form:n,layout:"vertical",children:[t.jsx(a.Item,{name:"client",label:"Client",rules:[{required:!0}],children:t.jsx(p,{showSearch:!0,placeholder:"Select client",options:f.map(e=>({value:e._id,label:e.name}))})}),t.jsx(a.Item,{name:"itemName",label:"Item",rules:[{required:!0}],children:t.jsx(Q,{})}),t.jsx(a.Item,{name:"quantity",label:"Quantity",initialValue:1,rules:[{required:!0}],children:t.jsx(y,{min:1,style:{width:"100%"}})}),t.jsx(a.Item,{name:"price",label:"Price",initialValue:0,rules:[{required:!0}],children:t.jsx(y,{min:0,style:{width:"100%"}})}),t.jsx(a.Item,{name:"currency",label:"Currency",initialValue:l,children:t.jsx(p,{options:P,showSearch:!0})})]})})]})}export{K as default};
