import{a as f}from"./axios-vendor.B9ygI19o.js";import{P as S,H,S as R}from"./frontend-modules.DdrmqCxF.js";import{_ as U,L as N,a as q}from"./frontend-components.Cb0sJqJc.js";import{d as b,a as l,o as n,F as p,r as y,f as k,e as _,w as C,g as B,t as A,n as v,b as o,c as m,h as T}from"./vue-vendor.BKvPJiPW.js";const V={name:"Module",components:{StationsModule:R,HowDoesItWorkModule:H,PricingModule:S},emits:["open-auth"],props:{module:{type:Object,required:!0}},data(){return{menuItems:[],category:null,articles:[]}},async mounted(){await this.loadModuleContent()},watch:{module:{handler(){this.loadModuleContent()},deep:!0}},async serverPrefetch(){await this.loadModuleContent()},methods:{handleDelegatedAuth(e){const t=e.target.closest("[data-open-auth]");if(!t)return;e.preventDefault(),e.stopPropagation();const i=t.dataset.openAuth||"login";this.$emit("open-auth",i)},async loadModuleContent(){this.module.module_type==="menu"&&this.module.menu_id?await this.loadMenu():this.module.module_type==="category"&&this.module.category_id?await this.loadCategory():this.module.module_type==="articles"&&this.module.category_id?await this.loadArticles():this.module.module_type==="stations"||this.module.module_type==="how-does-it-work"||this.module.module_type},async loadMenu(){var e;try{const i=((e=(await f.get(`/menus/${this.module.menu_id}`)).data.data)==null?void 0:e.items)||[];this.menuItems=this.flattenMenuItems(i)}catch(t){console.error("Error loading menu for module:",t),this.menuItems=[]}},async loadCategory(){try{const e=await f.get(`/categories/${this.module.category_id}`);e.data.success&&e.data.data&&(this.category=e.data.data)}catch(e){console.error("Error loading category for module:",e),this.category=null}},async loadArticles(){try{const e={category_id:this.module.category_id,published:1};let i=(await f.get("/articles",{params:e})).data.data||[];this.module.articles_count&&this.module.articles_count>0&&(i=i.slice(0,this.module.articles_count)),this.articles=i}catch(e){console.error("Error loading articles for module:",e),this.articles=[]}},flattenMenuItems(e){const t=[];return e.forEach(i=>{if(i.published){const d={...i};i.children&&i.children.length&&(d.children=this.flattenMenuItems(i.children)),t.push(d)}}),t},getMenuItemLink(e){return e.item_type==="external"&&e.link?e.link:e.is_default===1||e.is_default==="1"||e.is_default===!0?"/":e.alias?`/${e.alias}`:"/"},getArticleLink(e){return e.alias?`/${e.alias}`:"/"}}},j=["innerHTML"],F={key:1,class:"module-menu"},W={key:0,class:"menu-list"},z={key:0,class:"submenu"},G={key:1,class:"module-empty"},J={key:2,class:"module-categories"},K={key:0,class:"category-info"},Q={key:0},X={key:1,class:"module-empty"},Y={key:3,class:"module-articles"},Z={key:0,class:"articles-list"},$=["innerHTML"],ee={key:1,class:"module-empty"},te={key:4,class:"module-stations"},oe={key:5,class:"module-how-does-it-work"},se={key:6,class:"module-pricing"},ne=["innerHTML"];function ie(e,t,i,d,r,s){const c=b("router-link"),g=b("StationsModule"),w=b("HowDoesItWorkModule"),M=b("PricingModule");return n(),l("div",{class:v(["module",`module-${i.module.position}`]),onClickCapture:t[1]||(t[1]=(...u)=>s.handleDelegatedAuth&&s.handleDelegatedAuth(...u))},[i.module.module_type==="html"?(n(),l("div",{key:0,class:"module-content",innerHTML:i.module.content},null,8,j)):i.module.module_type==="menu"?(n(),l("nav",F,[r.menuItems.length?(n(),l("ul",W,[(n(!0),l(p,null,y(r.menuItems,u=>(n(),l("li",{key:u.id,class:"menu-item"},[k(c,{to:s.getMenuItemLink(u)},{default:C(()=>[B(A(u.title),1)]),_:2},1032,["to"]),u.children&&u.children.length?(n(),l("ul",z,[(n(!0),l(p,null,y(u.children,h=>(n(),l("li",{key:h.id,class:"submenu-item"},[k(c,{to:s.getMenuItemLink(h)},{default:C(()=>[B(A(h.title),1)]),_:2},1032,["to"])]))),128))])):_("",!0)]))),128))])):(n(),l("div",G,"אין פריטים בתפריט"))])):i.module.module_type==="category"?(n(),l("div",J,[r.category?(n(),l("div",K,[r.category.description?(n(),l("p",Q,A(r.category.description),1)):_("",!0)])):(n(),l("div",X,"קטגוריה לא נמצאה"))])):i.module.module_type==="articles"?(n(),l("div",Y,[r.articles.length?(n(),l("div",Z,[(n(!0),l(p,null,y(r.articles,u=>(n(),l("article",{key:u.id,class:"article-item"},[k(c,{to:s.getArticleLink(u)},{default:C(()=>[B(A(u.title),1)]),_:2},1032,["to"]),u.introtext?(n(),l("div",{key:0,class:"article-intro",innerHTML:u.introtext},null,8,$)):_("",!0)]))),128))])):(n(),l("div",ee,"אין מאמרים בקטגוריה זו"))])):i.module.module_type==="stations"?(n(),l("div",te,[k(g)])):i.module.module_type==="how-does-it-work"?(n(),l("div",oe,[k(w)])):i.module.module_type==="pricing"?(n(),l("div",se,[k(M,{onOpenAuth:t[0]||(t[0]=u=>e.$emit("open-auth",u))})])):(n(),l("div",{key:7,class:"module-content",innerHTML:i.module.content},null,8,ne))],34)}const le=U(V,[["render",ie]]),ae={name:"Template",components:{Module:le,ComponentRouter:q,LoginModal:N},data(){return{modules:[],menuItems:[],componentLoaded:!1,articlesMap:{},categoriesMap:{},showAuthModal:!1,mobileMenuOpen:!1,authTab:"login",componentsCache:{},user:null}},computed:{currentMenuItemId(){var s,c,g,w,M;const e=(w=(g=(c=(s=this.$route)==null?void 0:s.meta)==null?void 0:c.componentData)==null?void 0:g.menuItem)==null?void 0:w.id;if(e)return Number(e);const i=(((M=this.$route)==null?void 0:M.path)||"/").split("/").filter(Boolean);if(i.length===0){const u=this.menuItems.find(h=>h.published&&(h.is_default===1||h.is_default==="1"||h.is_default===!0));return u?Number(u.id):null}const d=i[0],r=this.menuItems.find(u=>u.published&&u.alias===d);return r?Number(r.id):null},filteredModules(){const e=this.currentMenuItemId;return this.modules.filter(t=>{if(t.show_on_all===1||t.show_on_all===!0||t.show_on_all==="1")return!0;if(!e)return!1;let d=[];if(Array.isArray(t.menu_item_ids))d=t.menu_item_ids;else if(typeof t.menu_item_ids=="string")try{const r=JSON.parse(t.menu_item_ids);Array.isArray(r)&&(d=r)}catch{}return d.map(Number).includes(Number(e))})},modulesByPosition(){const e={};return this.filteredModules.forEach(t=>{e[t.position]||(e[t.position]=[]),e[t.position].push(t)}),e},hasSSRData(){var e;return((e=this.$route.meta)==null?void 0:e.componentData)||!1},isAuthenticated(){return!!this.user},currentUser(){return this.user}},created(){this.hasSSRData&&(this.componentLoaded=!0),typeof window>"u"&&(this.loadModules(),this.loadArticles(),this.loadCategories(),this.loadMenu())},async serverPrefetch(){await this.loadModules(),await this.loadArticles(),await this.loadCategories(),await this.loadMenu(),this.componentLoaded=!0},activated(){this.loadModules(),this.loadMenu()},async mounted(){this.hasSSRData?(await this.loadModules(),await this.loadMenu()):(await this.loadModules(),await this.loadArticles(),await this.loadCategories(),await this.loadMenu(),this.componentLoaded=!0),await this.loadUser(),typeof window<"u"&&(document.addEventListener("click",this.handleAuthButtonClick),this.$route.query&&this.$route.query.auth==="login"&&!this.isAuthenticated&&this.$nextTick(()=>{this.openAuth("login"),this.$router.replace({path:this.$route.path,query:{}})}))},watch:{$route(e,t){t&&t.path!==e.path&&(this.componentLoaded=!1,this.$nextTick(()=>{this.componentLoaded=!0})),this.loadModules(),this.closeMobileMenu(),typeof window<"u"&&window.scrollTo({top:0,left:0,behavior:"auto"}),e.query&&e.query.auth==="login"&&!this.isAuthenticated&&this.$nextTick(()=>{this.openAuth("login"),this.$router.replace({path:e.path,query:{}})})}},methods:{toggleMobileMenu(){this.mobileMenuOpen=!this.mobileMenuOpen,typeof document<"u"&&(this.mobileMenuOpen?document.body.style.overflow="hidden":document.body.style.overflow="")},closeMobileMenu(){this.mobileMenuOpen=!1,typeof document<"u"&&(document.body.style.overflow="")},openAuth(e="login"){if(this.isAuthenticated){this.$router.push("/user");return}this.authTab=e,this.showAuthModal=!0},closeAuth(){this.showAuthModal=!1,this.loadUser()},async loadUser(){var e;if(!(typeof window>"u"))try{const t=await f.get("/auth/check");t.data.success&&t.data.user?this.user=t.data.user:this.user=null}catch(t){((e=t.response)==null?void 0:e.status)!==401&&console.error("Error loading user:",t),this.user=null}},handleAuthButtonClick(e){const t=e.target.closest('.cta-button, .user-button, [data-open-auth="login"]');t&&(t.tagName==="A"&&t.getAttribute("href")==="/user"||this.isAuthenticated||(e.preventDefault(),e.stopPropagation(),this.openAuth("login")))},isActive(e){const t=this.getMenuItemLink(e);return this.$route.path===t},async loadModules(){try{const e=await f.get("/modules?published=1");this.modules=e.data.data||[]}catch(e){console.error("Error loading modules:",e)}},async loadArticles(){try{const t=(await f.get("/articles?published=1")).data.data||[];this.articlesMap={},t.forEach(i=>{this.articlesMap[i.id]=i})}catch(e){console.error("Error loading articles:",e)}},async loadCategories(){try{const t=(await f.get("/categories?published=1")).data.data||[];this.categoriesMap={},t.forEach(i=>{this.categoriesMap[i.id]=i})}catch(e){console.error("Error loading categories:",e)}},async loadMenu(){var e;try{const i=(await f.get("/menus")).data.data||[],d=[];for(const r of i){const s=await f.get(`/menus/${r.id}`),c=await this.flattenMenuItems(((e=s.data.data)==null?void 0:e.items)||[]);d.push(...c)}this.menuItems=d}catch(t){console.error("Error loading menu:",t)}},async flattenMenuItems(e){const t=[];for(const i of e)if(i.published){if(i.component_id&&i.component_enabled!==void 0&&i.component_enabled!=1)continue;if(i.item_type==="article"){if(!await this.isComponentEnabled("com_content"))continue}else if(i.item_type==="category"&&!await this.isComponentEnabled("com_categories"))continue;if(t.push(i),i.children){const d=await this.flattenMenuItems(i.children);t.push(...d)}}return t},async isComponentEnabled(e){if(this.componentsCache[e]!==void 0)return this.componentsCache[e];try{const d=((await f.get("/components")).data.data||[]).find(s=>s.name===e),r=d?d.enabled===1||d.enabled===!0:!0;return this.componentsCache[e]=r,r}catch(t){return console.error("Error checking component status:",t),this.componentsCache[e]=!0,!0}},getMenuItemLink(e){return e.item_type==="external"&&e.link?e.link:e.is_default===1||e.is_default==="1"||e.is_default===!0?"/":e.alias?`/${e.alias}`:e.link?e.link:"/"}},beforeUnmount(){typeof window<"u"&&(window.removeEventListener("storage",this.handleStorageChange),document.removeEventListener("click",this.handleAuthButtonClick))}},re={class:"template"},ue={key:0,class:"modules-header"},de={class:"main-nav"},ce={class:"container nav-bar"},he={class:"nav-brand"},me=["aria-expanded"],fe={key:0,id:"menu",class:"desktop-menu"},pe={class:"nav-cta"},ye={class:"mobile-menu-content"},_e={class:"mobile-menu-cta"},ge={key:1,class:"modules-content-top"},ke={class:"main-content"},be={class:"container"},we={class:"content-main"},Me={key:1,class:"loading"},ve={key:2,class:"modules-content-bottom"},Ae={class:"container"},Ce={class:"main-footer"},De={class:"container"},Ie={class:"footer-content"},Be={key:0,class:"footer-section footer-nav"},xe={key:1,class:"footer-section footer-support"};function Le(e,t,i,d,r,s){var u,h,x,L,O,E,P;const c=b("Module"),g=b("router-link"),w=b("ComponentRouter"),M=b("LoginModal");return n(),l("div",re,[(u=s.modulesByPosition.header)!=null&&u.length?(n(),l("div",ue,[(n(!0),l(p,null,y(s.modulesByPosition.header,a=>(n(),m(c,{key:a.id,module:a,onOpenAuth:s.openAuth},null,8,["module","onOpenAuth"]))),128))])):_("",!0),o("nav",de,[o("div",ce,[o("div",he,[k(g,{to:"/",class:"brand-link"},{default:C(()=>[...t[4]||(t[4]=[o("div",{class:"brand-icon"},[o("svg",{viewBox:"0 0 64 64","aria-hidden":"true",focusable:"false"},[o("circle",{cx:"18",cy:"44",r:"10",stroke:"white","stroke-width":"4",fill:"none"}),o("circle",{cx:"46",cy:"44",r:"10",stroke:"white","stroke-width":"4",fill:"none"}),o("path",{d:"M18 44 28 26h12l6 12h-9",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"}),o("path",{d:"M33 38l-5-12",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round"}),o("path",{d:"M37 26l-4-8",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round"}),o("path",{d:"M35 18h7",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round"})])],-1),o("div",{class:"brand-text"},[o("div",{class:"brand-title"},"BikeBox"),o("div",{class:"brand-subtitle"},"חווית אופניים חכמה וסוגרת")],-1)])]),_:1})]),o("button",{class:"burger-menu-btn",onClick:t[0]||(t[0]=(...a)=>s.toggleMobileMenu&&s.toggleMobileMenu(...a)),"aria-expanded":r.mobileMenuOpen,"aria-label":"תפריט"},[o("span",{class:v(["burger-line",{active:r.mobileMenuOpen}])},null,2),o("span",{class:v(["burger-line",{active:r.mobileMenuOpen}])},null,2),o("span",{class:v(["burger-line",{active:r.mobileMenuOpen}])},null,2)],8,me),(h=s.modulesByPosition.sidebar)!=null&&h.length?(n(),l("div",fe,[(n(!0),l(p,null,y(s.modulesByPosition.sidebar,a=>(n(),m(c,{key:a.id,module:a,onOpenAuth:s.openAuth},null,8,["module","onOpenAuth"]))),128))])):_("",!0),o("div",pe,[s.isAuthenticated?(n(),m(g,{key:0,to:"/user",class:"cta-button user-button"},{default:C(()=>{var a,D,I;return[t[5]||(t[5]=o("i",{class:"fas fa-user"},null,-1)),B(" "+A(((a=s.currentUser)==null?void 0:a.user)||((D=s.currentUser)==null?void 0:D.name)||((I=s.currentUser)==null?void 0:I.username)||"משתמש"),1)]}),_:1})):(n(),l("button",{key:1,type:"button",class:"cta-button",onClick:t[1]||(t[1]=a=>s.openAuth("login"))},"כניסה לאזור אישי"))])]),o("div",{class:v(["mobile-menu-overlay",{open:r.mobileMenuOpen}]),onClick:t[2]||(t[2]=(...a)=>s.closeMobileMenu&&s.closeMobileMenu(...a))},null,2),(x=s.modulesByPosition.sidebar)!=null&&x.length?(n(),l("div",{key:0,class:v(["mobile-menu",{open:r.mobileMenuOpen}])},[o("div",ye,[(n(!0),l(p,null,y(s.modulesByPosition.sidebar,a=>(n(),m(c,{key:a.id,module:a,onOpenAuth:s.openAuth},null,8,["module","onOpenAuth"]))),128)),o("div",_e,[s.isAuthenticated?(n(),m(g,{key:0,to:"/user",class:"cta-button user-button",onClick:s.closeMobileMenu},{default:C(()=>{var a,D,I;return[t[6]||(t[6]=o("i",{class:"fas fa-user"},null,-1)),B(" "+A(((a=s.currentUser)==null?void 0:a.user)||((D=s.currentUser)==null?void 0:D.name)||((I=s.currentUser)==null?void 0:I.username)||"משתמש"),1)]}),_:1},8,["onClick"])):(n(),l("button",{key:1,type:"button",class:"cta-button",onClick:t[3]||(t[3]=a=>{s.openAuth("login"),s.closeMobileMenu()})},"כניסה לאזור אישי"))])])],2)):_("",!0)]),t[12]||(t[12]=o("div",{id:"test"},null,-1)),(L=s.modulesByPosition["content-top"])!=null&&L.length?(n(),l("div",ge,[(n(!0),l(p,null,y(s.modulesByPosition["content-top"],a=>(n(),m(c,{key:a.id,module:a,onOpenAuth:s.openAuth},null,8,["module","onOpenAuth"]))),128))])):_("",!0),o("main",ke,[o("div",be,[o("div",we,[r.componentLoaded?(n(),m(w,{key:0})):(n(),l("div",Me,"טוען..."))])])]),(O=s.modulesByPosition["content-bottom"])!=null&&O.length?(n(),l("div",ve,[o("div",Ae,[(n(!0),l(p,null,y(s.modulesByPosition["content-bottom"],a=>(n(),m(c,{key:a.id,module:a,onOpenAuth:s.openAuth},null,8,["module","onOpenAuth"]))),128))])])):_("",!0),o("footer",Ce,[o("div",De,[o("div",Ie,[t[9]||(t[9]=o("div",{class:"footer-section footer-company"},[o("div",{class:"footer-logo"},[o("span",{class:"logo-text"},"BikeBox"),o("div",{class:"logo-icon"},[o("svg",{viewBox:"0 0 64 64","aria-hidden":"true",focusable:"false"},[o("circle",{cx:"18",cy:"44",r:"10",stroke:"white","stroke-width":"4",fill:"none"}),o("circle",{cx:"46",cy:"44",r:"10",stroke:"white","stroke-width":"4",fill:"none"}),o("path",{d:"M18 44 28 26h12l6 12h-9",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"}),o("path",{d:"M33 38l-5-12",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round"}),o("path",{d:"M37 26l-4-8",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round"}),o("path",{d:"M35 18h7",stroke:"white","stroke-width":"4",fill:"none","stroke-linecap":"round"})])])]),o("p",{class:"footer-description"}," פתרונות חניה חכמים לאופניים. שומרים על הסביבה ועל הרכוש שלכם, ומפנים מקום במדרכות ובחניונים - הכל עם אבטחת אנטי-גניבה מתקדמת. "),o("div",{class:"footer-social"},[o("a",{href:"#",class:"social-icon","aria-label":"Facebook"},[o("i",{class:"fab fa-facebook-f"})]),o("a",{href:"#",class:"social-icon","aria-label":"Twitter"},[o("i",{class:"fab fa-twitter"})]),o("a",{href:"#",class:"social-icon","aria-label":"Instagram"},[o("i",{class:"fab fa-instagram"})])])],-1)),(E=s.modulesByPosition.sidebar)!=null&&E.length?(n(),l("div",Be,[t[7]||(t[7]=o("h3",{class:"footer-title"},"ניווט מהיר",-1)),(n(!0),l(p,null,y(s.modulesByPosition.sidebar,a=>(n(),m(c,{key:a.id,module:a,onOpenAuth:s.openAuth},null,8,["module","onOpenAuth"]))),128))])):_("",!0),(P=s.modulesByPosition.footer)!=null&&P.length?(n(),l("div",xe,[t[8]||(t[8]=o("h3",{class:"footer-title"},"תמיכה",-1)),(n(!0),l(p,null,y(s.modulesByPosition.footer,a=>(n(),m(c,{key:a.id,module:a,onOpenAuth:s.openAuth},null,8,["module","onOpenAuth"]))),128))])):_("",!0),t[10]||(t[10]=T('
',1))]),t[11]||(t[11]=T('',1))])]),k(M,{show:r.showAuthModal,"default-tab":r.authTab,onClose:s.closeAuth,onUserUpdated:s.loadUser},null,8,["show","default-tab","onClose","onUserUpdated"])])}const Ue=U(ae,[["render",Le]]);export{le as M,Ue as T};