1import{s as e,j as s}from"./index-B-01gp8C.js";import{r as a}from"./vendor-react-7UJKJIhU.js";import{z as t,aD as r,ay as l,C as i,b as n,a as c,m as d,u as o,am as m,M as x,P as h,c as g}from"./vendor-ui-DJKmmfZX.js";import"./vendor-supabase-CDTnsVBO.js";function b(){const[b,j]=a.useState([]),[p,f]=a.useState(!0),[y,u]=a.useState("upcoming"),[v,N]=a.useState(null);a.useEffect(()=>{w()},[y]);const w=async()=>{try{f(!0);const s=(new Date).toISOString().split("T")[0];let a=e.from("reservations").select("*").order("date",{ascending:!0}).order("time",{ascending:!0});"upcoming"===y&&(a=a.gte("date",s));const{data:t,error:r}=await a;if(r)throw r;j(t||[])}catch(s){t.error("NepodaÅilo se naÄÃst rezervace")}finally{f(!1)}},z=async(s,a)=>{try{const l=b.find(e=>e.id===s);if(!l)return void t.error("Rezervace nebyla nalezena");const{error:i}=await e.from("reservations").update({status:a}).eq("id",s);if(i)throw i;const n="confirmed"===a?"https://ywyxgkacawjjsqhdfhay.supabase.co/functions/v1/send-reservation-confirmation-email":"https://ywyxgkacawjjsqhdfhay.supabase.co/functions/v1/send-reservation-rejection-email";try{await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl3eXhna2FjYXdqanNxaGRmaGF5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjM5NzUwOTgsImV4cCI6MjA3OTU1MTA5OH0.zPvyfUG4z0tYqFpuzHO20i2s9DXHg-yZyUzlvFNgHUQ"},body:JSON.stringify({token:l.action_token})})}catch(r){}t.success("confirmed"===a?"Rezervace byla potvrzena":"Rezervace byla odmÃtnuta"),w(),N(null)}catch(l){t.error("NepodaÅilo se aktualizovat rezervaci")}},k=e=>new Date(e).toLocaleDateString("cs-CZ",{weekday:"long",year:"numeric",month:"long",day:"numeric"}),C=e=>{switch(e){case"confirmed":return s.jsxs("span",{className:"inline-flex items-center gap-1 px-3 py-1 bg-green-100 text-green-800 rounded-lg text-sm font-semibold",children:[s.jsx(o,{className:"w-4 h-4"}),"Potvrzeno"]});case"rejected":return s.jsxs("span",{className:"inline-flex items-center gap-1 px-3 py-1 bg-red-100 text-red-800 rounded-lg text-sm font-semibold",children:[s.jsx(m,{className:"w-4 h-4"}),"OdmÃtnuto"]});default:return s.jsxs("span",{className:"inline-flex items-center gap-1 px-3 py-1 bg-amber-100 text-amber-800 rounded-lg text-sm font-semibold",children:[s.jsx(n,{className:"w-4 h-4"}),"Äeká na potvrzenÃ"]})}},I=e=>{switch(e){case"confirmed":return"border-l-4 border-l-green-500";case"rejected":return"border-l-4 border-l-red-500";default:return"border-l-4 border-l-amber-500"}};return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[s.jsx("h1",{className:"text-3xl font-display font-bold text-gray-900",children:"Rezervace"}),s.jsxs("div",{className:"flex items-center gap-2 bg-white rounded-lg border border-gray-200 p-1",children:[s.jsxs("button",{onClick:()=>u("upcoming"),className:"px-4 py-2 rounded-md text-sm font-medium transition "+("upcoming"===y?"bg-amber-600 text-white":"text-gray-600 hover:bg-gray-100"),children:[s.jsx(r,{className:"w-4 h-4 inline mr-2"}),"NadcházejÃcÃ"]}),s.jsx("button",{onClick:()=>u("all"),className:"px-4 py-2 rounded-md text-sm font-medium transition "+("all"===y?"bg-amber-600 text-white":"text-gray-600 hover:bg-gray-100"),children:"VÅ¡echny"})]})]}),p?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx(l,{className:"w-8 h-8 text-amber-600 animate-spin"})}):0===b.length?s.jsxs("div",{className:"text-center py-12 bg-white rounded-lg border border-gray-200",children:[s.jsx(i,{className:"w-16 h-16 text-gray-400 mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"upcoming"===y?"Žádné nadcházejÃcà rezervace":"Žádné rezervace"}),s.jsx("p",{className:"text-gray-600",children:"upcoming"===y?"ZatÃm nemáte žádné nadcházejÃcà rezervace.":"ZatÃm nebyla vytvoÅena žádná rezervace."})]}):s.jsx("div",{className:"grid gap-4",children:b.map(e=>s.jsx("div",{className:`bg-white rounded-lg border border-gray-200 shadow-sm hover:shadow-md transition ${I(e.status)}`,children:s.jsxs("div",{className:"p-6",children:[s.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4 mb-4",children:[s.jsxs("div",{className:"flex-1",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[s.jsx("h3",{className:"text-xl font-display font-bold text-gray-900",children:e.name}),C(e.status)]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 text-sm text-gray-600",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(i,{className:"w-4 h-4 text-amber-600"}),k(e.date)]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(n,{className:"w-4 h-4 text-amber-600"}),e.time]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(c,{className:"w-4 h-4 text-amber-600"}),e.guests," ",1===e.guests?"host":e.guests<5?"hosté":"hostů"]})]})]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsxs("button",{onClick:()=>N(e),className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition flex items-center gap-2 text-sm font-medium",children:[s.jsx(d,{className:"w-4 h-4"}),"Detail"]}),"pending"===e.status&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{onClick:()=>z(e.id,"confirmed"),className:"px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition flex items-center gap-2 text-sm font-medium",children:[s.jsx(o,{className:"w-4 h-4"}),"Potvrdit"]}),s.jsxs("button",{onClick:()=>z(e.id,"rejected"),className:"px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition flex items-center gap-2 text-sm font-medium",children:[s.jsx(m,{className:"w-4 h-4"}),"OdmÃtnout"]})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 pt-4 border-t border-gray-100",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:[s.jsx(x,{className:"w-4 h-4 text-gray-400"}),s.jsx("a",{href:`mailto:${e.email}`,className:"hover:text-amber-600",children:e.email})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:[s.jsx(h,{className:"w-4 h-4 text-gray-400"}),s.jsx("a",{href:`tel:${e.phone}`,className:"hover:text-amber-600",children:e.phone})]})]}),e.message&&s.jsx("div",{className:"mt-4 pt-4 border-t border-gray-100",children:s.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[s.jsx(g,{className:"w-4 h-4 text-gray-400 mt-0.5 flex-shrink-0"}),s.jsx("p",{className:"text-gray-600",children:e.message})]})})]})},e.id))}),v&&s.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50",onClick:()=>N(null),children:s.jsxs("div",{className:"bg-white rounded-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto",onClick:e=>e.stopPropagation(),children:[s.jsxs("div",{className:"p-6 border-b border-gray-200",children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsx("h2",{className:"text-2xl font-display font-bold text-gray-900",children:"Detail rezervace"}),s.jsx("button",{onClick:()=>N(null),className:"text-gray-400 hover:text-gray-600",children:s.jsx(m,{className:"w-6 h-6"})})]}),C(v.status)]}),s.jsxs("div",{className:"p-6 space-y-6",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-1",children:"Jméno"}),s.jsx("p",{className:"text-gray-900",children:v.name})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-1",children:"Email"}),s.jsx("a",{href:`mailto:${v.email}`,className:"text-amber-600 hover:underline",children:v.email})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-1",children:"Telefon"}),s.jsx("a",{href:`tel:${v.phone}`,className:"text-amber-600 hover:underline",children:v.phone})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-1",children:"PoÄet hostů"}),s.jsx("p",{className:"text-gray-900",children:v.guests})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-1",children:"Datum"}),s.jsx("p",{className:"text-gray-900",children:k(v.date)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-1",children:"Äas"}),s.jsx("p",{className:"text-gray-900",children:v.time})]})]}),v.message&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-2",children:"Poznámka"}),s.jsx("p",{className:"text-gray-900 bg-gray-50 p-4 rounded-lg whitespace-pre-wrap",children:v.message})]}),s.jsxs("div",{className:"pt-4 border-t border-gray-200",children:[s.jsx("label",{className:"block text-sm font-semibold text-gray-600 mb-2",children:"Odkazy pro zákaznÃka"}),s.jsx("div",{className:"space-y-2 text-sm",children:s.jsxs("div",{children:[s.jsx("span",{className:"text-gray-600",children:"Zobrazit: "}),s.jsx("a",{href:`${window.location.origin}/rezervace/zobrazit?token=${v.action_token}`,target:"_blank",rel:"noopener noreferrer",className:"text-amber-600 hover:underline break-all",children:`${window.location.origin}/rezervace/zobrazit?token=${v.action_token}`})]})})]}),"pending"===v.status&&s.jsxs("div",{className:"flex gap-3 pt-4 border-t border-gray-200",children:[s.jsxs("button",{onClick:()=>z(v.id,"confirmed"),className:"flex-1 px-4 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition flex items-center justify-center gap-2 font-medium",children:[s.jsx(o,{className:"w-5 h-5"}),"Potvrdit rezervaci"]}),s.jsxs("button",{onClick:()=>z(v.id,"rejected"),className:"flex-1 px-4 py-3 bg-red-600 text-white rounded-lg hover:bg-red-700 transition flex items-center justify-center gap-2 font-medium",children:[s.jsx(m,{className:"w-5 h-5"}),"OdmÃtnout rezervaci"]})]}),s.jsx("div",{className:"pt-4 border-t border-gray-200",children:s.jsx("button",{onClick:()=>(async s=>{if(confirm("Opravdu chcete smazat tuto rezervaci?"))try{const{error:a}=await e.from("reservations").delete().eq("id",s);if(a)throw a;t.success("Rezervace byla smazána"),w(),N(null)}catch(a){t.error("NepodaÅilo se smazat rezervaci")}})(v.id),className:"w-full px-4 py-2 bg-red-50 text-red-600 rounded-lg hover:bg-red-100 transition text-sm font-medium",children:"Smazat rezervaci"})})]})]})})]})}export{b as ReservationsPage};
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.