import{H as g,r as c,s as p,ar as v,j as a,w as y,L as h,b as d}from"./index-DHiKqTn6.js";import{N,r as C,P as w}from"./en-US-BHI7lbCO.js";import{H as E}from"./house-D_3Onipo.js";import{C as _}from"./credit-card-CBlRgKpv.js";import{C as A}from"./Footer-DIHGzGNa.js";function x(o={}){const{user:l}=g(),{table:i,onInsert:e,onUpdate:t,onDelete:s,enabled:n=!0}=o;return c.useEffect(()=>{if(!n||!l||!i)return;const u=p.channel(`realtime-${i}`).on("postgres_changes",{event:"*",schema:"public",table:i},r=>{r.eventType==="INSERT"&&e?e(r.new):r.eventType==="UPDATE"&&t?t(r.new):r.eventType==="DELETE"&&s&&s(r.old)}).subscribe();return()=>{p.removeChannel(u)}},[i,n,l,e,t,s]),{isConnected:!0,subscribe:c.useCallback((u,r)=>{const f=p.channel(u).on("broadcast",{event:"message"},b=>{r(b.payload)}).subscribe();return()=>{p.removeChannel(f)}},[])}}const B=()=>{const{user:o}=g(),[l,i]=c.useState({automations:0,dashboard:0}),[e,t]=c.useState(!0),s=c.useCallback(async()=>{if(!o?.id){t(!1);return}try{const{data:n}=await N.list(),u=(n?.automations||[]).filter(m=>m.is_enabled&&!m.last_run_at).length,{data:r}=await C.list(),b=(r||[]).filter(m=>m.build_status==="building").length;i({automations:u,dashboard:b})}catch(n){console.error("Error fetching nav badges:",n)}finally{t(!1)}},[o?.id]);return c.useEffect(()=>{s()},[s]),x({table:"automation_configs",onUpdate:()=>{s()},enabled:!!o?.id}),x({table:"app_projects",onUpdate:()=>{s()},enabled:!!o?.id}),{badges:l,loading:e}},H=[{icon:E,label:"Home",path:"/dashboard",badgeKey:"dashboard"},{icon:_,label:"Credits",path:"/subscription"},{icon:w,label:"Build",path:"/builder",isCenter:!0},{icon:A,label:"Help",path:"/help"},{icon:y,label:"Settings",path:"/settings"}],I=()=>{const o=v(),{badges:l}=B(),i=e=>e&&l[e]||0;return a.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 md:hidden bg-background/80 backdrop-blur-xl border-t border-border/50 safe-area-bottom",children:a.jsx("div",{className:"flex items-center justify-around h-16 px-1 max-w-md mx-auto",children:H.map(e=>{const t=o.pathname===e.path,s=e.icon,n=i(e.badgeKey);return e.isCenter?a.jsxs(h,{to:e.path,className:"relative -mt-5 flex flex-col items-center",children:[a.jsx("div",{className:d("w-13 h-13 rounded-full flex items-center justify-center shadow-lg transition-all duration-300",t?"bg-primary scale-110 shadow-primary/30":"bg-primary/90 hover:bg-primary"),children:a.jsx(s,{className:"w-6 h-6 text-primary-foreground"})}),a.jsx("span",{className:d("text-[10px] font-medium mt-1 transition-colors",t?"text-primary":"text-muted-foreground"),children:e.label})]},e.path):a.jsxs(h,{to:e.path,className:d("flex flex-col items-center justify-center flex-1 h-full gap-0.5 transition-all duration-200 relative",t?"text-primary":"text-muted-foreground"),children:[t&&a.jsx("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-8 h-0.5 bg-primary rounded-full"}),a.jsxs("div",{className:"relative",children:[a.jsx(s,{className:d("w-5 h-5 transition-all duration-200",t&&"scale-110")}),n>0&&a.jsx("span",{className:"absolute -top-1.5 -right-1.5 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-bold bg-primary text-primary-foreground rounded-full animate-in zoom-in-50 duration-200",children:n>9?"9+":n})]}),a.jsx("span",{className:d("text-[10px] font-medium transition-colors",t?"text-primary":"text-muted-foreground"),children:e.label})]},e.path)})})})};export{I as M,x as u};
