import{r as d}from"./index-BMcVAjQW.js";import{s}from"./client-BVfsVemL.js";function p(n,o,c){return n.map(t=>({id:t.id,name:t.name,game:t.game,price:t.price,status:t.status,description:t.description,image:t.image_url??void 0,createdAt:new Date(t.created_at).getTime(),readyEstimateAt:t.ready_estimate_at,whatsappNumber:t.whatsapp_number,whatsappChannelUrl:t.whatsapp_channel_url,rentalPackages:o.filter(e=>e.product_id===t.id).sort((e,a)=>e.sort_order-a.sort_order).map(e=>({id:e.id,duration:e.duration,price:e.price})),gallery:c.filter(e=>e.product_id===t.id).sort((e,a)=>e.sort_order-a.sort_order).map(e=>e.image_url)}))}function m(){const[n,o]=d.useState([]),[c,t]=d.useState(!0),e=async()=>{const[{data:a},{data:i},{data:r}]=await Promise.all([s.from("products").select("*").order("sort_order",{ascending:!0}).order("created_at",{ascending:!1}),s.from("rental_packages").select("*"),s.from("product_images").select("*")]);o(p(a??[],i??[],r??[])),t(!1)};return d.useEffect(()=>{e();const i=`products-realtime-${`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}`,r=s.channel(i);return r.on("postgres_changes",{event:"*",schema:"public",table:"products"},()=>{e()}).on("postgres_changes",{event:"*",schema:"public",table:"rental_packages"},()=>{e()}).on("postgres_changes",{event:"*",schema:"public",table:"site_settings"},()=>{e()}).subscribe(),()=>{s.removeChannel(r)}},[]),{products:n,loading:c,refetch:e}}export{m as u};
