import{A as e,D as t,N as n,Q as r,U as i,W as a,c as o,d as s,et as c,g as l,h as u,jt as d,l as f,m as p,r as m,s as h,t as g}from"./_plugin-vue_export-helper-vx-p5QAT.js";import{a as _,d as v,t as y}from"./http-CTjL79ty.js";import{E as b,V as x,j as S,y as C}from"./index-DWlOII4H.js";import{t as w}from"./AdminPageSkeleton-DacAHji8.js";import{t as T}from"./BaseEmptyState-B6cM4bRM.js";import{t as E}from"./AdminSelect-CWMyO8tk.js";var D={class:`admin-page`},O={class:`admin-page__head`},k={key:2,class:`admin-table`},A={class:`muted`,dir:`ltr`},j=[`onClick`],M={class:`field`},N={class:`field`},P={class:`field`},F=[`disabled`],I=g(l({__name:`SuggestionsView`,setup(l){let g=c([]),I=c(!0),L=c([]),R=c([]),z=c(!1),B=_(),V=r({customerId:``,productId:``,note:``}),H=h(()=>L.value.map(e=>({value:e.id,label:e.name?.trim()||e.phone}))),U=h(()=>R.value.map(e=>({value:e.id,label:`${e.name} (${e.productCode})`})));async function W(){I.value=!0;try{let[e,t,n]=await Promise.all([S.list(),C.list(),b.list()]);g.value=e,L.value=t,R.value=n}catch(e){B.error(e instanceof y?e.message:`بارگذاری ناموفق بود`)}finally{I.value=!1}}async function G(){try{await S.create({customerId:V.customerId,productId:V.productId,note:V.note.trim()||void 0}),z.value=!1,V.note=``,B.success(`پیشنهاد ثبت شد`),await W()}catch(e){B.error(e instanceof y?e.message:`ثبت ناموفق بود`)}}async function K(e){try{await S.setActive(e.id,!e.isActive),await W()}catch(e){B.error(e instanceof y?e.message:`به‌روزرسانی ناموفق بود`)}}return t(()=>{W()}),(t,r)=>(e(),s(`div`,D,[o(`header`,O,[r[5]||=o(`div`,null,[o(`h1`,null,`پیشنهاد محصول`),o(`p`,null,`پیشنهاد دستی محصول به مشتری`)],-1),o(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,onClick:r[0]||=e=>z.value=!0},`پیشنهاد جدید`)]),I.value?(e(),f(w,{key:0,variant:`table`})):g.value.length?(e(),s(`table`,k,[r[6]||=o(`thead`,null,[o(`tr`,null,[o(`th`,null,`مشتری`),o(`th`,null,`محصول`),o(`th`,null,`یادداشت`),o(`th`,null,`وضعیت`),o(`th`)])],-1),o(`tbody`,null,[(e(!0),s(m,null,n(g.value,t=>(e(),s(`tr`,{key:t.id},[o(`td`,null,d(t.customerName),1),o(`td`,null,[p(d(t.productName)+` `,1),o(`span`,A,`(`+d(t.productCode)+`)`,1)]),o(`td`,null,d(t.note||`—`),1),o(`td`,null,d(t.isActive?`فعال`:`غیرفعال`),1),o(`td`,null,[o(`button`,{type:`button`,class:`link`,onClick:e=>K(t)},d(t.isActive?`غیرفعال`:`فعال`),9,j)])]))),128))])])):(e(),f(T,{key:1,title:`پیشنهادی ثبت نشده`})),u(x,{open:z.value,title:`پیشنهاد محصول`,onClose:r[4]||=e=>z.value=!1},{footer:i(()=>[o(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,disabled:!V.customerId||!V.productId,onClick:G},` ثبت `,8,F)]),default:i(()=>[o(`label`,M,[r[7]||=p(`مشتری `,-1),u(E,{modelValue:V.customerId,"onUpdate:modelValue":r[1]||=e=>V.customerId=e,options:H.value},null,8,[`modelValue`,`options`])]),o(`label`,N,[r[8]||=p(`محصول `,-1),u(E,{modelValue:V.productId,"onUpdate:modelValue":r[2]||=e=>V.productId=e,options:U.value},null,8,[`modelValue`,`options`])]),o(`label`,P,[r[9]||=p(`یادداشت`,-1),a(o(`textarea`,{"onUpdate:modelValue":r[3]||=e=>V.note=e,class:`admin-input`,rows:`3`},null,512),[[v,V.note]])])]),_:1},8,[`open`])]))}}),[[`__scopeId`,`data-v-56e3e728`]]);export{I as default};