import{r as m,o as D,a as n,b as r,g as V,d as t,f as _,N as $,F as f,j as h,t as l,q as S,z as j,y as A,e as F,m as x,k as c,A as R}from"./app-kAt5lVqd.js";const P={class:"p-8"},T={class:"bg-white rounded-lg shadow overflow-x-auto"},U={class:"w-full"},z={class:"px-6 py-4 font-medium"},B={class:"px-6 py-4"},M={class:"px-6 py-4"},q={class:"px-6 py-4"},L=["onUpdate:modelValue","onChange"],E={class:"px-6 py-4 font-bold"},I={class:"px-6 py-4"},G={class:"px-6 py-4 text-right"},H=["onClick"],J=["onClick"],K={key:0,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4"},Q={class:"bg-white rounded-lg w-full max-w-2xl max-h-[90vh] overflow-y-auto"},W={class:"sticky top-0 bg-white border-b px-6 py-4 flex justify-between items-center"},X={class:"text-2xl font-bold"},Y={class:"p-6 space-y-4"},Z={class:"border-t pt-4"},tt={class:"flex justify-between font-bold text-lg"},et={class:"text-orange-600"},lt={__name:"Orders",setup(st){const{success:y,error:i}=R(),g=m([]),o=m(null),p=async()=>{try{const{data:a}=await c.get("/orders");g.value=a.data||a}catch{i("Failed to load orders")}},w=a=>({pending:"bg-yellow-100 text-yellow-800",accepted:"bg-blue-100 text-blue-800",preparing:"bg-purple-100 text-purple-800",ready:"bg-indigo-100 text-indigo-800",picked_up:"bg-orange-100 text-orange-800",delivered:"bg-green-100 text-green-800",cancelled:"bg-red-100 text-red-800"})[a]||"bg-gray-100 text-gray-800",k=a=>new Date(a).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),C=async a=>{try{const{data:e}=await c.get(`/orders/${a.id}`);o.value=e}catch{i("Failed to load order details")}},O=async a=>{try{await c.put(`/orders/${a.id}/status`,{status:a.status}),y("Order status updated")}catch{i("Failed to update status"),p()}},N=async a=>{if(confirm("Cancel this order?"))try{await c.post(`/orders/${a}/cancel`),y("Order cancelled"),p()}catch{i("Failed to cancel order")}};return D(p),(a,e)=>{var v;return r(),n("div",P,[V($),e[9]||(e[9]=t("div",{class:"flex justify-between items-center mb-6"},[t("h1",{class:"text-3xl font-bold"},"Order Management")],-1)),t("div",T,[t("table",U,[e[2]||(e[2]=t("thead",{class:"bg-gray-50"},[t("tr",null,[t("th",{class:"px-6 py-3 text-left"},"Order #"),t("th",{class:"px-6 py-3 text-left"},"Customer"),t("th",{class:"px-6 py-3 text-left"},"Restaurant"),t("th",{class:"px-6 py-3 text-left"},"Status"),t("th",{class:"px-6 py-3 text-left"},"Total"),t("th",{class:"px-6 py-3 text-left"},"Date"),t("th",{class:"px-6 py-3 text-right"},"Actions")])],-1)),t("tbody",null,[(r(!0),n(f,null,h(g.value,s=>{var d,b;return r(),n("tr",{key:s.id,class:"border-t"},[t("td",z,"#"+l(s.order_number||s.id),1),t("td",B,l(((d=s.user)==null?void 0:d.name)||"N/A"),1),t("td",M,l(((b=s.restaurant)==null?void 0:b.name)||"N/A"),1),t("td",q,[S(t("select",{"onUpdate:modelValue":u=>s.status=u,onChange:u=>O(s),class:A([w(s.status),"px-3 py-1 rounded-full text-sm font-medium border-0 cursor-pointer"])},[...e[1]||(e[1]=[F('<option value="pending">Pending</option><option value="accepted">Accepted</option><option value="preparing">Preparing</option><option value="ready">Ready</option><option value="picked_up">Picked Up</option><option value="delivered">Delivered</option><option value="cancelled">Cancelled</option>',7)])],42,L),[[j,s.status]])]),t("td",E,"Rs "+l(s.total_amount||s.total||0),1),t("td",I,l(k(s.created_at)),1),t("td",G,[t("button",{onClick:u=>C(s),class:"text-blue-600 hover:text-blue-800 mr-3"},"View",8,H),s.status==="pending"?(r(),n("button",{key:0,onClick:u=>N(s.id),class:"text-red-600 hover:text-red-800"},"Cancel",8,J)):_("",!0)])])}),128))])])]),o.value?(r(),n("div",K,[t("div",Q,[t("div",W,[t("h2",X,"Order #"+l(o.value.order_number||o.value.id),1),t("button",{onClick:e[0]||(e[0]=s=>o.value=null),class:"text-gray-500 hover:text-gray-700 text-2xl"},"×")]),t("div",Y,[t("div",null,[e[6]||(e[6]=t("h3",{class:"font-bold mb-2"},"Customer Details",-1)),t("p",null,[e[3]||(e[3]=t("strong",null,"Name:",-1)),x(" "+l((v=o.value.user)==null?void 0:v.name),1)]),t("p",null,[e[4]||(e[4]=t("strong",null,"Phone:",-1)),x(" "+l(o.value.delivery_phone),1)]),t("p",null,[e[5]||(e[5]=t("strong",null,"Address:",-1)),x(" "+l(o.value.delivery_address),1)])]),t("div",null,[e[7]||(e[7]=t("h3",{class:"font-bold mb-2"},"Order Items",-1)),(r(!0),n(f,null,h(o.value.items,s=>{var d;return r(),n("div",{key:s.id,class:"flex justify-between py-2 border-b"},[t("span",null,l((d=s.product)==null?void 0:d.name)+" x "+l(s.quantity),1),t("span",null,"Rs "+l(s.total_price),1)])}),128))]),t("div",Z,[t("div",tt,[e[8]||(e[8]=t("span",null,"Total",-1)),t("span",et,"Rs "+l(o.value.total_amount||o.value.total),1)])])])])])):_("",!0)])}}};export{lt as default};
