1import{ce as I,K as q,r as t,s as x,j as e,B as l,ag as w,_ as C,a1 as _,h as k,ah as z,aj as v,I as F,a4 as V,a5 as Y,a6 as K,a7 as M,a8 as R}from"./index-LAef4FAh.js";import{H as U,f as D}from"./HotelAdminLayout-D45NwIyk.js";import{S as $}from"./switch-DU3zvDcN.js";import{D as G,a as J,b as Q,c as W,d as X,e as Z}from"./dialog-DMm6owy5.js";import{P as ee}from"./pen-BXBDyf1S.js";import"./use-mobile-Kd5aMTze.js";import"./sheet-Cyv-LVly.js";import"./index-JglnD_Uo.js";import"./ticket-Bcy--bUf.js";import"./log-in-D7fHSPdv.js";import"./ellipsis-D5DDpfqE.js";const E=[{value:"front_desk",label:"Front Desk"},{value:"cafe",label:"à¸à¸²à¹à¸à¹"},{value:"restaurant",label:"รà¹à¸²à¸à¸à¸²à¸«à¸²à¸£"},{value:"minimart",label:"มิà¸à¸´à¸¡à¸²à¸£à¹à¸ / รà¹à¸²à¸à¸à¹à¸²"},{value:"laundry",label:"à¸à¸±à¸à¸£à¸µà¸"},{value:"transport",label:"รà¸à¸£à¸±à¸à¸ªà¹à¸ / à¸à¸±à¸§à¸£à¹"},{value:"other",label:"à¸à¸·à¹à¸à¹"}],se=Object.fromEntries(E.map(a=>[a.value,a.label]));function he(){const{hotelClient:a}=I(),{toast:i}=q(),[o,O]=t.useState([]),[T,g]=t.useState(!0),[L,r]=t.useState(!1),[n,N]=t.useState(null),[S,b]=t.useState(!1),[c,h]=t.useState(""),[u,j]=t.useState("other"),[f,p]=t.useState(!0),d=t.useCallback(async()=>{if(!a)return;g(!0);const{data:s}=await x.from("outlets").select("*").eq("hotel_client_id",a.id).order("sort_order").order("created_at");O(s||[]),g(!1)},[a]);t.useEffect(()=>{d()},[d]);const y=()=>{N(null),h(""),j("other"),p(!0),r(!0)},A=s=>{N(s),h(s.name),j(s.type),p(s.is_active),r(!0)},H=async()=>{if(!(!c.trim()||!a)){b(!0);try{if(n){const{error:s}=await x.from("outlets").update({name:c.trim(),type:u,is_active:f}).eq("id",n.id);if(s)throw s;i({title:"à¸à¸±à¸à¹à¸à¸à¸à¸¸à¸à¸à¸²à¸¢à¸ªà¸³à¹à¸£à¹à¸"})}else{const s=o.length>0?Math.max(...o.map(B=>B.sort_order))+1:0,{error:m}=await x.from("outlets").insert({hotel_client_id:a.id,name:c.trim(),type:u,is_active:f,sort_order:s});if(m)throw m;i({title:"à¹à¸à¸´à¹à¸¡à¸à¸¸à¸à¸à¸²à¸¢à¸ªà¸³à¹à¸£à¹à¸"})}r(!1),d()}catch(s){i({title:"à¹à¸à¸´à¸à¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸",description:s==null?void 0:s.message,variant:"destructive"})}finally{b(!1)}}},P=async s=>{if(s.is_default){i({title:"à¹à¸¡à¹à¸ªà¸²à¸¡à¸²à¸£à¸à¸¥à¸à¸à¸¸à¸à¸à¸²à¸¢à¹à¸£à¸´à¹à¸¡à¸à¹à¸à¹à¸à¹",variant:"destructive"});return}if(!confirm(`à¸à¹à¸à¸à¸à¸²à¸£à¸¥à¸ "${s.name}" ?`))return;const{error:m}=await x.from("outlets").delete().eq("id",s.id);m?i({title:"à¹à¸¡à¹à¸ªà¸²à¸¡à¸²à¸£à¸à¸¥à¸à¹à¸à¹",description:"à¸à¸²à¸à¸¡à¸µà¸£à¸²à¸¢à¸à¸²à¸£à¸à¸²à¸¢à¸à¸µà¹à¹à¸à¸·à¹à¸à¸¡à¸à¸¢à¸¹à¹",variant:"destructive"}):(i({title:"ลà¸à¸ªà¸³à¹à¸£à¹à¸"}),d())};return e.jsx(U,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"à¸à¸¸à¸à¸à¸²à¸¢ (Outlets)"}),e.jsxs(l,{onClick:y,children:[e.jsx(w,{className:"h-4 w-4 mr-1"})," à¹à¸à¸´à¹à¸¡à¸à¸¸à¸à¸à¸²à¸¢"]})]}),T?e.jsx("p",{className:"text-muted-foreground text-sm",children:"à¸à¸³à¸¥à¸±à¸à¹à¸«à¸¥à¸..."}):o.length===0?e.jsx(C,{children:e.jsxs(_,{className:"py-12 text-center",children:[e.jsx(D,{className:"h-12 w-12 mx-auto text-muted-foreground/40 mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:"ยัà¸à¹à¸¡à¹à¸¡à¸µà¸à¸¸à¸à¸à¸²à¸¢"}),e.jsxs(l,{variant:"outline",className:"mt-4",onClick:y,children:[e.jsx(w,{className:"h-4 w-4 mr-1"})," à¹à¸à¸´à¹à¸¡à¸à¸¸à¸à¸à¸²à¸¢à¹à¸£à¸"]})]})}):e.jsx("div",{className:"grid gap-3",children:o.map(s=>e.jsx(C,{children:e.jsxs(_,{className:"flex items-center justify-between py-4 px-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(D,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-foreground",children:s.name}),s.is_default&&e.jsx(k,{variant:"secondary",className:"text-[10px]",children:"à¸à¹à¸²à¹à¸£à¸´à¹à¸¡à¸à¹à¸"}),!s.is_active&&e.jsx(k,{variant:"outline",className:"text-[10px] text-muted-foreground",children:"à¸à¸´à¸à¹à¸à¹à¸à¸²à¸"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:se[s.type]||s.type})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(l,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>A(s),children:e.jsx(ee,{className:"h-4 w-4"})}),!s.is_default&&e.jsx(l,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>P(s),children:e.jsx(z,{className:"h-4 w-4"})})]})]})},s.id))}),e.jsx(G,{open:L,onOpenChange:r,children:e.jsxs(J,{className:"max-w-sm",children:[e.jsxs(Q,{children:[e.jsx(W,{children:n?"à¹à¸à¹à¹à¸à¸à¸¸à¸à¸à¸²à¸¢":"à¹à¸à¸´à¹à¸¡à¸à¸¸à¸à¸à¸²à¸¢"}),e.jsx(X,{children:n?"à¹à¸à¹à¹à¸à¸à¹à¸à¸¡à¸¹à¸¥à¸à¸¸à¸à¸à¸²à¸¢":"สรà¹à¸²à¸à¸à¸¸à¸à¸à¸²à¸¢à¹à¸«à¸¡à¹à¹à¸à¹à¸£à¸à¹à¸£à¸¡"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs(v,{children:["à¸à¸·à¹à¸à¸à¸¸à¸à¸à¸²à¸¢ ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(F,{value:c,onChange:s=>h(s.target.value),placeholder:"à¹à¸à¹à¸ à¸à¸²à¹à¸à¹à¸£à¸´à¸¡à¸ªà¸£à¸°",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(v,{children:"à¸à¸£à¸°à¹à¸ à¸"}),e.jsxs(V,{value:u,onValueChange:j,children:[e.jsx(Y,{className:"mt-1",children:e.jsx(K,{})}),e.jsx(M,{children:E.map(s=>e.jsx(R,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{children:"à¹à¸à¸´à¸à¹à¸à¹à¸à¸²à¸"}),e.jsx($,{checked:f,onCheckedChange:p})]})]}),e.jsxs(Z,{children:[e.jsx(l,{variant:"outline",onClick:()=>r(!1),children:"ยà¸à¹à¸¥à¸´à¸"}),e.jsx(l,{onClick:H,disabled:S||!c.trim(),children:S?"à¸à¸³à¸¥à¸±à¸à¸à¸±à¸à¸à¸¶à¸...":n?"à¸à¸±à¸à¸à¸¶à¸":"à¹à¸à¸´à¹à¸¡"})]})]})})]})})}export{he as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.