import{$t as e,An as t,Cn as n,F as r,L as i,Nn as a,On as o,Rt as s,W as c,Zt as l,_n as u,an as d,en as f,kt as p,mn as m,nn as h,on as g,rn as _,tn as v,wn as y,zt as b}from"./app-4kCgdoJR.js";var x={class:`border-b border-gray-200 p-4 sm:px-6 dark:border-gray-700`},S={class:`text-base leading-6 font-semibold text-gray-900 dark:text-gray-100`},C={class:`mt-1 text-sm`},w={class:`rounded-b-lg bg-gray-100 p-6 dark:bg-gray-800`},T={for:`change_hall_id`,class:`mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300`},E={for:`change_table_id`,class:`mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300`},D={key:0,class:`mt-1 text-xs text-gray-500 dark:text-gray-400`},O={class:`flex gap-2`},k={__name:`ChangeTable`,props:[`show`,`halls`,`currentHallId`,`currentTableId`],emits:[`close`,`changed`],setup(k,{emit:A}){let{t:j}=s({}),M=k,N=A,P=null,F=o(!1),I=o(null),L=o(null),R=e(()=>M.halls.find(e=>e.id==I.value)?.tables||[]),z=e(()=>R.value.filter(e=>e.available||e.status===`available`||e.id==M.currentTableId));n(()=>M.show,e=>{e&&(P=M.currentTableId,I.value=M.currentHallId,L.value=M.currentTableId)}),m(()=>{P=M.currentTableId,I.value=M.currentHallId,L.value=M.currentTableId});async function B(){if(!I.value||!L.value){b({group:`main`,type:`error`,title:`Error!`,text:j(`Please select both hall and table.`)});return}if(I.value===M.currentHallId&&L.value===M.currentTableId){N(`close`);return}F.value=!0,await c.post(route(`pos.table-status`),{hall_id:I.value,table_id:L.value}).then(e=>{e.data.available?(N(`changed`,{hall_id:I.value,table_id:L.value}),b({group:`main`,type:`success`,title:`Success!`,text:j(`Table changed successfully.`)})):b({group:`main`,type:`error`,title:`Error!`,text:j(`Selected table is not available. It is already assigned to Order #: {order_number}`,{order_number:e.data.order.number})})}).catch(()=>{b({group:`main`,type:`error`,title:`Error!`,text:j(`Failed to check table availability. Please try again.`)},1e4)}).finally(()=>F.value=!1)}return(e,n)=>(u(),v(t(p),{show:k.show,maxWidth:`sm`,closeable:!0,onClose:n[3]||=e=>N(`close`),overflow:!0},{default:y(()=>[f(`div`,null,[f(`div`,x,[f(`h3`,S,a(e.$t(`Change Table`)),1),f(`p`,C,a(e.$t(`Select a new table for this order.`)),1)]),f(`div`,w,[f(`form`,{onSubmit:l(B,[`prevent`]),autocomplete:`off`,class:`flex flex-col items-stretch gap-4`},[f(`div`,null,[f(`label`,T,a(e.$t(`Hall`)),1),g(t(i),{json:``,keyboard:``,valueKey:`id`,labelKey:`name`,id:`change_hall_id`,modelValue:I.value,"onUpdate:modelValue":n[0]||=e=>I.value=e,inputClass:`focus rounded-md shadow-sm border-gray-300 dark:border-gray-700`,suggestions:k.halls.map(e=>({id:e.id,name:e.name}))},null,8,[`modelValue`,`suggestions`])]),f(`div`,null,[f(`label`,E,a(e.$t(`Table`)),1),g(t(i),{json:``,keyboard:``,valueKey:`value`,labelKey:`label`,id:`change_table_id`,modelValue:L.value,"onUpdate:modelValue":n[1]||=e=>L.value=e,disabled:!I.value,inputClass:`focus rounded-md shadow-sm border-gray-300 dark:border-gray-700`,suggestions:z.value.map(n=>({value:n.id,label:`${n.name} (${n.seats} ${e.$t(`Seats`)})${n.id==t(P)?` - `+e.$t(`Current`):``}`}))},null,8,[`modelValue`,`disabled`,`suggestions`]),I.value&&z.value.length===0?(u(),_(`p`,D,a(e.$t(`No available tables in selected hall.`)),1)):h(``,!0)]),f(`div`,O,[f(`button`,{type:`button`,onClick:n[2]||=e=>N(`close`),class:`btn-secondary flex-1 justify-center`},a(e.$t(`Cancel`)),1),g(t(r),{class:`flex-1 justify-center`,loading:F.value},{default:y(()=>[d(a(e.$t(`Change Table`)),1)]),_:1},8,[`loading`])])],32)])])]),_:1},8,[`show`]))}};export{k as default};