@anker-in/headless-ui 1.0.20-alpha.1761288173557 → 1.0.20-alpha.1761288487826

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use client";import{Fragment as J,jsx as e,jsxs as n}from"react/jsx-runtime";import xe,{forwardRef as X,useCallback as _,useEffect as E,useImperativeHandle as Ne,useMemo as M,useRef as R,useState as D}from"react";import{Picture as K,Text as f,Button as B,Container as Y,Link as F,Heading as oe}from"../../components/index.js";import{withLayout as ke}from"../../shared/Styles.js";import{cn as x,atobID as we}from"../../helpers/utils.js";import Ce,{useNavContext as O}from"./NavProvider.js";import{HeaderNavigationMenu as T,HeaderNavigationBlockType as j,HeaderNavigationActionBlockType as I}from"./types.js";import"react-responsive";import{debounce as Se}from"es-toolkit";import Me from"jump.js";import{useGSAP as ne}from"@gsap/react";import{gsap as le}from"gsap";import{WithSidebar as se,WithSupports as re,WithMulticol as ie,WithGroupCategory as ce}from"./withCategory.js";import{Menu as De,Close as de,User as Le,RightArrow as Pe,LeftArrow as ze,DownArrow as Z,Polygon as Ee}from"./icons/index.js";import He from"../NavigationSearch/index.js";const Be=X((t,a)=>{const{data:{headerNavigation:l}={},buildProps:o,event:s,profile:c,theme:y="light",isTop:r=!1,searchResult:v,onSearch:N,isSearching:L,keywords:h}=t,u=R(null),[d,m]=D(!1),[p,i]=D(!1),[g,S]=D(!1),[C,P]=D(!1),k=R(null),A=()=>{const w=document?.querySelector("body")?.offsetWidth||0;P(w<=1440)};E(()=>(A(),window.addEventListener("resize",A),()=>{window.removeEventListener("resize",A)}),[]),Ne(a,()=>k.current),E(()=>{k.current&&r&&Me(k.current,{duration:0,offset:k.current?.getBoundingClientRect()?.bottom||0})},[r]),E(()=>{s&&(s.search=()=>m(!0))},[s]),ne(()=>{u?.current&&d&&le.fromTo(u.current,{height:0},{height:"auto",duration:.3})},[d]),E(()=>{document.documentElement.style.overflow=d?"hidden":"auto"},[d]);const W=M(()=>l?.headerBar?.actions?.find(w=>w?.blockType===I.Search)?.searchBar?.[0]||{},[l]);return e(Ce,{buildProps:o,profile:c,isMobile:C,event:s,payloadData:l,children:e("header",{"data-ui-component-id":"HeaderNavigation",className:"relative z-[100]",ref:k,children:n("div",{className:x("hover:text-black hover:bg-white",y==="light"?"text-black":"text-white",{}),onClick:()=>S(!0),children:[e(Te,{data:l,className:"hidden desktop:block",theme:y,onNavItemClick:()=>S(!0)}),e(Fe,{data:l,className:"block desktop:hidden"}),d&&n("div",{className:"absolute z-[60] top-0 left-0 w-full bg-black/70 flex flex-col",style:{height:`calc(100dvh - ${k?.current?.getBoundingClientRect()?.top}px)`},children:[e("div",{ref:u,className:x("overflow-y-auto",{}),children:e(He,{data:W,keywords:h,isSearching:L,searchResult:v,onSearch:w=>{N?.(w)},onClose:()=>{N?.(),m(!1)}})}),e("div",{className:"flex-1 bg-transparent",onClick:()=>m(!1)})]})]})})})}),Te=X((t,a)=>{const{data:l,onNavItemClick:o,className:s,theme:c}=t,{event:y,profile:r}=O(),[v,N]=D(!1),L=M(()=>ce(l?.categories?.filter(b=>b?.pcShow)),[l]),[h,u]=D(null),[d,m]=D([]),p=R(null),[i,g]=D(!1),S=R(null),C=R(null),P=R(L.map(b=>Array(b?.length||0).fill(null)));E(()=>{L?.length&&m(L?.map((b,z)=>b?.map((H,$)=>({groupIndex:z,index:$,open:!1}))))},[L]);const k=M(()=>{let b=null;for(const z of d){for(const H of z)if(H.open){b=H;break}if(b)break}return b},[d]);E(()=>{document.documentElement.style.overflow=k?.open||i?"hidden":"auto"},[k?.open,i]);const A=(b,z,H)=>{g(!1),h?.components?.[0]?.blockType===j.Links?h?.components?.[0]?.url&&window.open(h?.components?.[0]?.url):(b.stopPropagation(),o?.(),u(L[z][H]),m($=>$.map(V=>V.map(q=>q.groupIndex===z&&q.index===H?{...q,open:!q.open}:{...q,open:!1}))))},W=()=>{m(b=>b.map(z=>z.map(H=>({...H,open:!1}))))},w=M(()=>{if(h)return h?.components?.[0]?.blockType},[h]),ee=se(Re,h),U=ie(Ae,h),he=re($e,{categoriesItem:h,currentNavItemRef:P.current?.[k?.groupIndex||0]?.[k?.index||0]}),ye=M(()=>{switch(w){case j.Sidebar:return e(ee,{});case j.Supports:return e(he,{});case j.Multicol:return e(U,{});default:return null}},[w,h]),te=M(()=>l?.headerBar?.actions?.filter(b=>b?.pcShow),[l]),G=M(()=>te?.find(b=>b?.blockType===I.Profile),[te]),ae=_(()=>{g(b=>!b)},[]);return E(()=>{if(p?.current){const b=p.current;return b.addEventListener("click",ae),()=>{b.removeEventListener("click",ae)}}},[ae]),ne(()=>{k?.open&&le.fromTo(C?.current,{height:0},{height:"auto"})},[k?.open]),n(Y,{className:x("relative h-[96px]",s),children:[n("div",{ref:S,onClick:W,className:"flex h-full flex-col justify-end gap-4",children:[n("div",{className:"flex items-center justify-between",children:[e(fe,{}),e(ve,{ref:p,actions:te,activeStatus:i})]}),e("div",{className:"flex justify-between",children:L?.map((b,z)=>e("div",{className:"flex gap-3",children:b?.map((H,$)=>e("div",{ref:V=>{P.current[z][$]=V},className:"group cursor-pointer",children:n("div",{className:"relative",children:[n("div",{className:"flex items-center gap-1 pb-4",onClick:V=>A(V,z,$),children:[e(f,{html:H.text,className:"text-sm font-bold leading-[1.4]"}),e(Z,{className:x("opacity-0 size-4 group-hover:opacity-100 transition-opacity duration-500",{"rotate-180":k?.groupIndex===z&&k?.index===$,"opacity-100":v&&k?.groupIndex===z&&k?.index===$})})]}),e("div",{className:x("absolute bottom-0 left-0 h-[2px] w-0 transition-all duration-500",{"w-[calc(100%-20px)]":k?.groupIndex===z&&k?.index===$},c==="dark"?"bg-white":"bg-[#1D1D1F]")})]})},H.id))},`groupCategory-${z}`))})]}),n("div",{className:x("border-t border-b-[#E4E5E6] text-black absolute left-0 top-full z-[999] flex w-full flex-col bg-black/70 overflow-hidden",{hidden:!(k?.open&&h)}),onMouseEnter:()=>N(!0),onMouseLeave:()=>N(!1),style:{height:`calc(100dvh - ${S?.current?.getBoundingClientRect()?.bottom}px)`},children:[e("div",{ref:C,className:x("relative z-50",{"overflow-hidden":w!==j.Supports}),children:ye}),e("div",{className:"flex-1 bg-transparent",onClick:W})]}),i&&n("div",{className:"absolute left-0 z-[999] flex w-full bg-black/70 h-[100dvh] top-full",children:[e("div",{className:"absolute w-[272px] bg-white p-4",style:{right:`calc(100% - ${p?.current?.getBoundingClientRect()?.right}px)`,top:"-36px"},children:r?.email?n(J,{children:[e(f,{html:r?.nick_name||G?.welcome,className:"text-sm font-bold"}),e("div",{className:"h-[1px] mt-2 bg-[#D9D9D9]"}),e("div",{className:"mt-2",children:G?.profiles?.map(b=>e(Q,{className:"py-2",label:b?.title,href:b?.url},b.id))})]}):n(J,{children:[e(Ee,{className:"absolute -top-2 text-white right-[46px] z-30"}),e(f,{html:G?.benefits_title,className:"text-sm font-bold leading-[1.4]"}),e("div",{className:"mt-2 flex flex-col gap-1",children:G?.benefits?.map(b=>n("div",{className:"flex items-center gap-[6px]",children:[e(K,{source:b.benefitIcon?.url,className:"size-4",alt:b.benefit,width:16,height:16}),e(f,{html:b.benefit,className:"text-sm font-bold leading-[1.4]"})]},b.id))}),n("div",{className:"mt-4 flex items-center gap-2",children:[e(B,{variant:"secondary",size:"lg",onClick:()=>y?.join?.(),children:e(f,{html:G?.primaryButton||"Join Now",className:"font-bold"})}),e(B,{variant:"primary",size:"lg",onClick:()=>y?.login?.(),children:e(f,{html:G?.secondaryButton||"Log In",className:"font-bold"})})]})]})}),e("div",{className:"flex-1 bg-transparent",onClick:()=>g(!1)})]})]})}),Re=xe.memo(({sidebarCategoriesMetadata:t,seriesMetadata:a})=>{const{buildProps:l}=O(),[o,s]=D([]),[c,y]=D(-1),r=R(null),v=_(()=>{const u=t?.subcategories;if(!u?.length)return;const d=u.findIndex(i=>!!i?.subSubCategories),m=u.findIndex(i=>!i?.subSubCategories),p=u.map((i,g)=>({index:g,open:d===g||m===g}));s(p)},[t]);E(()=>{v()},[v]);const N=M(()=>{const u=t?.subcategories?.[o?.find(m=>m.open)?.index||0],d=a?.find(m=>m?.label?.toLowerCase()===u?.label?.toLowerCase())||{};if(u?.collections){const m=l?.categories?.[u?.collections]||{};return{label:d?.label,isCollection:!0,banner:d?.banner,primary:d?.primary,series:[{products:m?.products}]}}else if(u?.subSubCategories){const m=u?.subSubCategories?.[c],p=a?.find(i=>i?.label?.toLowerCase()===m?.label?.toLowerCase())||{};if(m?.collections){const i=l?.categories?.[m?.collections]||{};return{label:p?.label,isCollection:!0,banner:p?.banner,primary:p?.primary,series:[{products:i?.products}]}}else return p}else return d},[t,o,c,a]),L=_((u,d)=>{if(d?.subSubCategories?.length>0?y(0):y(-1),d?.subSubCategories?.length>0)s(m=>m.map(p=>p.index===u?{...p,open:!0}:{...p,open:!1}));else{const p=t?.subcategories?.findIndex(i=>!!i?.subSubCategories);s(i=>i.map(g=>({...g,open:g.index===u||g.index===p})))}},[t,v]),h=(u,d)=>{s(m=>m.map(p=>p.index===u?{...p,open:!0}:{...p,open:!1})),y(d)};return n(Y,{childClassName:"lg-desktop:gap-12 flex bg-white gap-8",children:[n("div",{className:"lg-desktop:basis-[356px] flex basis-[284px] flex-col gap-4 py-4",style:{userSelect:"none"},ref:r,children:[e("div",{className:"desktop:h-[416px] flex flex-col overflow-y-auto",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:t?.subcategories?.map((u,d)=>{const m=Array.isArray(u?.subSubCategories)&&u?.subSubCategories?.length>0;return n("div",{children:[n("div",{className:x("flex cursor-pointer items-center justify-between",{"bg-[#F5F5F7]":!m&&o?.find(p=>p.index===d)?.open}),onClick:()=>{L(d,u)},children:[e(f,{html:u.label,className:"p-4 text-sm font-bold leading-[1.4]"}),m&&e(Z,{className:x("size-4",{"rotate-180":o?.find(p=>p.index===d)?.open})})]}),o?.find(p=>p.index===d)?.open&&e("div",{className:"flex flex-col",children:u.subSubCategories?.map((p,i)=>e(f,{html:p.label,onClick:()=>h(d,i),className:x("cursor-pointer hover:bg-[#F5F5F7] px-6 py-4 text-sm font-bold leading-[1.4] text-[#6D6D6F]",{"bg-[#F5F5F7]":c===i})},`subSubItem-${d}-${i}`))})]},`subcategoryItem-${d}`)})}),t&&e("div",{className:"flex",children:n("div",{className:"flex flex-col gap-4",children:[t?.primary&&e(B,{as:"a",href:t?.primary?.url,variant:"primary",size:"lg",className:"text-sm lg-desktop:text-base",children:t?.primary?.label}),t?.secondary&&e(B,{as:"a",href:t?.secondary?.url,variant:"link",size:"lg",className:"justify-start !p-0 text-sm lg-desktop:text-base",children:t?.secondary?.label})]})})]}),n("div",{className:"flex-1 py-4",children:[Reflect.ownKeys(N).length>0&&n("div",{className:"mb-4 flex items-center justify-between",children:[e("div",{className:"flex items-center gap-2",children:e(f,{html:N?.label,className:"text-xl lg-desktop:text-2xl font-bold leading-[1.4]"})}),e(F,{href:N?.guide?.url,className:"text-sm lg-desktop:text-base leading-[1.2] text-[#6D6D6F]",children:N?.guide?.label})]}),e("div",{className:"flex flex-col gap-4 overflow-y-auto h-[426px]",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:N?.series?.map((u,d)=>n("div",{children:[u.label&&e(f,{html:u.label,className:"text-sm mb-2 font-bold leading-[1.4] text-[#6D6D6F]"}),n("div",{className:"grid grid-cols-3 gap-4",children:[!!N?.banner&&e(F,{asChild:!N?.banner?.href,href:N?.banner?.href,children:n("div",{className:"relative [&_img]:hover:scale-105 [&_img]:hover:transition-all [&_img]:hover:duration-300",children:[e(K,{source:N?.banner?.imageUrl,className:"h-[114px] laptop:h-[120px]",imgClassName:"object-cover h-full"}),n("div",{className:"absolute bottom-0 left-0 right-0 p-4",children:[e(oe,{size:2,html:N?.banner?.title||"Buy in Guide",className:"font-bold text-white"}),e(f,{html:N?.banner?.desc||"20.000mAh",className:"text-sm text-white font-bold"})]})]})}),u.products?.map((m,p)=>e(ue,{product:m,isCollection:N?.isCollection},`seriesProductItem-${p}`))]})]},`seriesItem-${d}`))})]})]})}),Ae=({multicolMetadata:t})=>{const a=R(null);return e("div",{ref:a,children:e(Y,{childClassName:"bg-white",className:"h-full",children:e("div",{className:"flex gap-4 py-4",children:t?.map((l,o)=>e("div",{className:"w-1/4",children:e(me,{item:l})},`multicolItem-${l?.label}-${o}`))})})})},$e=({supportsMetadata:t,currentNavItemRef:a})=>{const l=R(null),[o,s]=D(null),[c,y]=D(0);E(()=>{if(l?.current){const v=l?.current?.getBoundingClientRect();y(v.height)}},[l]);const r=Se(()=>{if(a){const v=a.getBoundingClientRect();s(v)}},500);return E(()=>(r(),window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r)}),[r]),E(()=>{if(a){const v=a.getBoundingClientRect();s(v)}},[a]),e("div",{className:"absolute top-0 h-full bg-white transition-all duration-500 overflow-hidden",style:{right:`calc(100% - ${o?.right}px)`,height:c},children:e("div",{ref:l,className:"p-4",children:t?.map(v=>e("div",{className:"py-2",children:e(F,{href:v.url,className:"text-sm font-bold leading-[1.4] no-underline",children:v.label})},v.id))})})},ue=({product:t,isCollection:a})=>{const{buildProps:l}=O();let o=a?t:l?.products?.find(r=>r.handle===t.handle);const s=o?.variants?.find(r=>r.sku===t.sku)||o?.variants?.[0],c=M(()=>`/products/${o?.handle}?variant=${we(s?.id)}`,[o?.handle,s?.id]),y=M(()=>o?.tags?.filter?.(r=>r?.startsWith?.("CLtag"))?.map?.(r=>r?.replace?.("CLtag:",""))?.slice?.(0,2),[o?.tags]);return s?.availableForSale?n("div",{className:"flex shrink-0 items-center gap-4 bg-[#F5F5F7] px-4 py-3 [&_img]:hover:scale-105",children:[e("div",{className:"shrink-0",children:e(K,{source:`${s?.image?.url||t?.images?.[0]?.url}}`,width:90,height:90,className:"size-[96px]",imgClassName:"object-contain h-full"})}),n("div",{className:"relative",children:[e("div",{className:"flex gap-1",children:Array.isArray(y)&&y?.map(r=>e(f,{as:"p",html:r,className:"text-brand-0 whitespace-nowrap mb-1 inline-block h-[24px] rounded-full border-[1.6px] border-[#00BEFA] px-[6px] text-sm font-bold !leading-[22px]"}))}),e(F,{href:c,className:"no-underline hover:text-current",children:e(f,{className:"lg-desktop:h-[44px] lg-desktop:text-base line-clamp-2 h-[40px] text-sm font-bold leading-[1.4]",html:o?.title||t?.name})}),t?.desc&&e(f,{as:"p",html:t?.desc,className:"lg-desktop:text-sm line-clamp-1 mt-1 text-xs font-bold leading-[1.4] text-[#6D6D6F]"})]})]}):null},me=({item:t,allPicture:a})=>n(J,{children:[t?.columns&&n(J,{children:[e(f,{html:t.label,as:"div",className:"my-2 text-sm font-bold leading-[1.4] text-[#6D6D6F]"}),e("div",{className:"mt-2 flex flex-col",children:t.columns?.map(l=>n("div",{className:"py-2 flex items-center gap-1",children:[e(F,{href:l.url,className:"text-sm font-bold leading-[1.4] no-underline",children:l.label}),l?.badge&&e(f,{as:"p",html:l?.badge||"badge",className:"text-sm font-bold !leading-[24px] text-brand-0 h-[24px] rounded-full border-[1.6px] border-[var(--brand-color-0)] px-[6px]"})]},l.label))})]}),t?.imageUrl&&n("div",{className:x("laptop:h-[280px] desktop:h-[224px] lg-desktop:h-[280px] h-[240px] max-w-[358px] tablet:max-w-[346px] laptop:max-w-[440px] desktop:w-full relative overflow-hidden",{"tablet:max-w-none laptop:max-w-none":a}),children:[e(K,{source:t.imageUrl,width:404,height:280,className:"size-full",imgClassName:"object-cover h-full hover:scale-105 transition-all duration-300"}),n(F,{href:t.url,className:"absolute bottom-4 left-4 z-10 flex flex-col justify-end no-underline",children:[e(f,{html:t.title,className:x("lg-desktop:text-2xl text-xl font-bold leading-[1.2] text-white",{"text-black":t?.theme==="dark"})}),t.subtitle&&e(f,{html:t.subtitle,className:x("text-sm font-bold leading-[1.4] text-white",{"text-black":t?.theme==="dark"})}),t?.primary?.label&&e(B,{as:"a",href:t?.primary?.url,variant:"link",size:"lg",className:x("text-sm font-bold mr-auto !p-0 leading-[1.4] text-white",{"text-black":t?.theme==="dark"}),children:t?.primary?.label||"more"})]})]})]}),Fe=X(({data:t,className:a},l)=>{const o=M(()=>ce(t?.categories?.filter(w=>w?.mobileShow)),[t]),{currentMenu:s,setCurrentMenu:c,subSubCategory:y}=O(),[r,v]=D(!1),[N,L]=D(0),[h,u]=D(null),d=R(null);E(()=>{if(d?.current&&r){const w=d?.current?.getBoundingClientRect();L(window?.innerHeight-(w?.bottom||0))}},[r]),ne(()=>{le.fromTo(d.current,{height:0},{height:N,duration:.3})},[N]),E(()=>{document.documentElement.style.overflow=r?"hidden":"auto"},[r]);const m=M(()=>h?.components?.[0]?.blockType,[h]),p=re(Oe,{categoriesItem:h}),i=se(Ie,h),g=ie(_e,h),S=M(()=>{switch(m){case j.Sidebar:return e(i,{});case j.Supports:return e(p,{});case j.Multicol:return e(g,{});default:return null}},[m,h,p]),C=_(()=>{v(!1),L(0),c&&c(T.Primary)},[v,L,c]),P=M(()=>t?.headerBar?.actions?.filter(w=>w?.mobileShow&&w?.blockType!==I.Profile),[t]),k=M(()=>t?.headerBar?.actions?.find(w=>w?.mobileShow&&w?.blockType===I.Profile)||{},[t]),A=M(()=>{switch(s){case T.Primary:return e(Ue,{actions:P,menuOpen:r,onMenuOpenClose:()=>{v(!1),L(0)},onMenuOpenClick:()=>v(!0)});case T.Secondary:return e(ge,{title:h?.text,onMenuOpenClose:C,onMenuBackClick:()=>c?.(T.Primary)});case T.Third:return e(ge,{title:y?.label,onMenuOpenClose:C,onMenuBackClick:()=>c?.(T.Secondary)});default:return null}},[r,s,c,h,P,y,C]),W=_((w,ee)=>{const U=Array.isArray(o)?Array.isArray(o[w])?o[w][ee]:{}:{};u(U),U?.components?.[0]?.blockType===j.Links?U?.components?.[0]?.url&&window.open(U?.components?.[0]?.url):c?.(T.Secondary)},[o,c]);return n(Y,{className:x("relative h-[52px]",a),children:[A,r&&e("div",{ref:d,className:"absolute left-0 top-full text-black border-t border-[#E4E5E6] z-[999] w-full overflow-y-auto bg-white",style:{height:N},children:s===T.Primary?e(je,{categories:o,onPrimaryMenuClick:W,profileAction:k}):S})]})}),je=({categories:t,onPrimaryMenuClick:a,profileAction:l})=>n("div",{className:"flex h-full flex-col justify-between",children:[e("div",{className:"tablet:px-8 laptop:px-16 p-4",children:t?.map((o,s)=>n("div",{className:"",children:[o?.map((c,y)=>e(Q,{label:c.text,onClick:()=>a(s,y),icon:c.components?.[0]?.icon},c.id)),e("div",{className:x("my-2 h-px w-full bg-[#E5E5E7]",{hidden:s===t.length-1})})]},`groupCategory-${s}`))}),e(We,{profileAction:l})]}),Ie=({sidebarCategoriesMetadata:t,seriesMetadata:a})=>{const{currentMenu:l,setCurrentMenu:o,subSubCategory:s,setSubSubCategory:c,setCurrentSeriesMetadata:y,currentSeriesMetadata:r,buildProps:v}=O(),[N,L]=D([]),[h,u]=D([]);E(()=>{t?.subcategories?.length&&L(t?.subcategories?.map((i,g)=>({index:g,open:!1})))},[t]),E(()=>{s?.subSubCategories?.length&&u(s?.subSubCategories?.map((i,g)=>({index:g,open:g===0})))},[s]);const d=_((i,g)=>{o&&o(T.Third),c?.(i);const S=a?.find(C=>g!==void 0?i?.subSubCategories?.[g]?.label?.toLowerCase()===C.label?.toLowerCase():i?.label?.toLowerCase()===C.label?.toLowerCase())||{};if(i?.collections){const C=v?.categories?.[i?.collections]||{};y?.({label:S?.label,isCollection:!0,banner:S?.banner,primary:S?.primary,series:[{products:C?.products}]})}else y?.(S)},[a,t,o,c,y]),m=M(()=>a?.find(i=>!!i?.guide)?.guide,[a,t]);return M(()=>{switch(l){case T.Secondary:return n("div",{className:"tablet:px-8 laptop:px-16 flex h-full flex-col justify-between tablet:justify-start tablet:gap-16 p-4",children:[e("div",{children:t?.subcategories?.map((i,g)=>e("div",{children:e(Q,{label:i?.label,active:N.find(S=>S.index===g)?.open,onClick:()=>{d(i)}})},`${i.label}-${g}`))}),n("div",{className:"tablet:items-start flex flex-col items-center gap-4",children:[t?.primary&&e(B,{as:"a",href:t?.primary?.url,variant:"primary",size:"lg",className:"tablet:w-auto w-full text-base",children:t?.primary?.label}),t?.secondary&&e(B,{as:"a",href:t?.secondary?.url,variant:"link",size:"lg",className:"tablet:w-auto tablet:px-0 w-full py-0 text-base",children:t?.secondary?.label})]})]});case T.Third:return n("div",{className:"tablet:px-8 laptop:px-16 p-4",children:[s?.subSubCategories?s?.subSubCategories?.map((i,g)=>{const S=a?.find(P=>P.label.toLowerCase()===i?.label?.toLowerCase())||{};let C={};if(i?.collections){const P=v?.categories?.[i?.collections]||{};C={label:S?.label,isCollection:!0,banner:S?.banner,primary:S?.primary,series:[{products:P?.products}]}}else C=S;return n("div",{children:[Reflect.ownKeys(i).length>0&&e(pe,{matchSeriesMetadata:C,onSubSubCategoryItemClick:()=>u(P=>P.map((k,A)=>({...k,open:A===g}))),expanded:!!h?.find(P=>P.index===g)?.open}),h?.find(P=>P.index===g)?.open&&n(J,{children:[e(be,{matchSeriesMetadata:C}),C?.primary&&e("div",{className:"text-center my-4",children:e(B,{as:"a",href:C?.primary?.url,className:"text-base no-underline leading-[1.2]",variant:"secondary",size:"base",children:C?.primary?.label})})]})]},`${i.label}-${g}`)}):n(J,{children:[Reflect.ownKeys(r).length>0&&e(pe,{matchSeriesMetadata:r}),e(be,{matchSeriesMetadata:r}),r?.primary&&e("div",{className:"text-center my-4 ",children:e(B,{as:"a",href:r?.primary?.url,variant:"secondary",size:"base",className:"text-base no-underline leading-[1.2]",children:r?.primary?.label})})]}),m&&e(F,{href:m?.url,children:e("div",{className:"mt-4",children:e(f,{html:m?.label,className:"text-sm font-bold leading-[1.2] text-[#6D6D6F]"})})})]});default:return null}},[l,t,o,a,N,h,c,s,y,r])},pe=({matchSeriesMetadata:t,onSubSubCategoryItemClick:a,expanded:l})=>n("div",{className:"tablet:pt-0 py-4 flex items-center justify-between",onClick:a,children:[t?.label&&e(f,{html:t?.label,className:"text-sm font-bold leading-[1.4]"}),a&&e(Z,{className:x("size-5",{"rotate-180":l})})]}),be=({matchSeriesMetadata:t})=>e("div",{className:"flex flex-col gap-2 laptop:gap-3",children:!!t?.series?.length&&t?.series?.map((a,l)=>n("div",{children:[a.label&&e(f,{html:a.label,className:"text-sm mb-2 font-bold leading-[1.4] text-[#3D3D3F]"}),n("div",{className:"laptop:grid-cols-3 laptop:gap-4 tablet:grid tablet:grid-cols-2 tablet:gap-3 flex flex-col gap-2",children:[!!t?.banner&&e(F,{asChild:!t?.banner?.href,href:t?.banner?.href,children:n("div",{className:"relative [&_img]:hover:scale-105 [&_img]:hover:transition-all [&_img]:hover:duration-300",children:[e(K,{source:t?.banner?.imageUrl,className:"h-[114px] laptop:h-[120px]",imgClassName:"object-cover h-full"}),n("div",{className:"absolute bottom-0 left-0 right-0 p-4",children:[e(oe,{size:2,html:t?.banner?.title||"Buy in Guide",className:x("font-bold text-white",{"text-black":t?.banner?.theme==="dark"})}),e(f,{html:t?.banner?.desc||"20.000mAh",className:x("text-sm text-white font-bold",{"text-black":t?.banner?.theme==="dark"})})]})]})}),a.products?.map((o,s)=>e(ue,{product:o,isCollection:t?.isCollection},`seriesProductItem-${l}-${s}`))]})]},`seriesItem-${l}`))}),Oe=({supportsMetadata:t})=>e("div",{className:"tablet:px-8 laptop:px-16 p-4",children:t?.map(a=>e(Q,{href:a.url,label:a.label,onClick:()=>{}},a.id))}),_e=({multicolMetadata:t})=>{const a=M(()=>!t?.some(l=>!!l.columns),[t]);return e("div",{className:x("tablet:py-4 tablet:px-8 laptop:px-16 flex flex-col gap-4 tablet:gap-6 p-4",{"tablet:grid tablet:grid-cols-2 tablet:gap-3 laptop:gap-4":a}),children:t?.map((l,o)=>e("div",{children:e(me,{item:l,allPicture:a})},`multicolItem-${l?.label}-${o}`))})},We=({profileAction:t})=>{const[a,l]=D(!1),{profile:o,event:s}=O();return n("div",{className:x("tablet:px-8 laptop:px-16 bg-[#F5F5F7] px-4 py-6",{"p-4":a}),children:[n("div",{className:"flex items-center justify-between",onClick:()=>l(!a),children:[n("div",{className:"flex items-center gap-[14px]",children:[e("div",{className:"flex size-[40px] shrink-0 items-center justify-center rounded-full bg-white",children:e(Le,{})}),e(f,{html:o?.nick_name||t?.welcome,className:"text-base font-bold leading-[1.4]"})]}),!o?.email&&e(Z,{className:x("size-5 laptop:size-4",{"rotate-180":a})})]}),o?.email&&e("div",{className:"mt-4",children:t?.profiles?.map(c=>e(Q,{label:c?.title,href:c?.url},c.id))}),a&&!o?.email&&n("div",{className:"mt-4",children:[e(f,{html:t?.benefits_title,className:"text-sm font-bold leading-[1.4]"}),e("div",{className:"mt-2 flex flex-col gap-1",children:t?.benefits?.map(c=>n("div",{className:"flex items-center gap-[6px]",children:[e(K,{source:c.benefitIcon?.url,className:"size-4",alt:c.benefit,width:16,height:16}),e(f,{html:c.benefit,className:"text-sm font-bold leading-[1.4]"})]},c.id))})]}),!o?.email&&n("div",{className:"mt-4 flex items-center gap-3",children:[e(B,{className:"tablet:flex-none flex-1",variant:"secondary",size:"base",onClick:()=>s?.join?.(),children:e(f,{html:t?.primaryButton||"Join Now",className:"text-sm font-bold leading-[1.4]"})}),e(B,{className:"tablet:flex-none flex-1",variant:"primary",size:"base",onClick:()=>s?.login?.(),children:e(f,{html:t?.secondaryButton||"Log In",className:"text-sm font-bold leading-[1.4]"})})]})]})},Ue=({menuOpen:t,onMenuOpenClose:a,onMenuOpenClick:l,actions:o})=>n("div",{className:"flex h-full items-center justify-between gap-4",children:[e(fe,{}),n("div",{className:"desktop:gap-6 flex items-center gap-4",children:[e(ve,{actions:o}),t?e(de,{className:"size-5",onClick:()=>a()}):e(De,{className:"size-5",onClick:()=>l()})]})]}),fe=()=>{const{payloadData:t,isMobile:a}=O();return e("div",{className:"[&>svg]:w-full hover:text-brand-0 cursor-pointer",onClick:()=>{window.location.href="/"},dangerouslySetInnerHTML:{__html:a?t?.headerBar?.mobileLogo:t?.headerBar?.desktopLogo}})},ve=X(({actions:t,activeStatus:a=!1},l)=>{const{event:o}=O(),[s,c]=D(null),y=_((r,v)=>{switch(c(v),r?.blockType){case I.Search:o?.search?.();break;case I.Cart:o?.cart?.();break;case I.Profile:o?.profile?.();break;case I.Livestream:o?.livestream?.();break;default:return()=>{}}},[o]);return e("div",{className:"desktop:gap-6 flex items-center gap-4",children:Array.isArray(t)&&t?.map((r,v)=>e("div",{ref:r.blockType===I.Profile?l:null,onClick:()=>y(r,v),children:e(f,{html:r.icon,className:x("cursor-pointer size-5",{"text-brand-0":a&&s===v})})},r.id))})}),ge=({title:t,onMenuOpenClose:a,onMenuBackClick:l})=>n("div",{className:"flex h-full items-center gap-3",children:[e(ze,{className:"size-5",onClick:()=>l()}),e(f,{html:t,className:"flex-1 text-center text-base font-bold leading-[1.4]"}),e(de,{className:"size-5",onClick:()=>a()})]}),Q=({label:t,href:a,onClick:l,active:o,icon:s,className:c})=>e("div",{className:x("flex cursor-pointer items-center justify-between py-4",c),onClick:l,children:n(F,{href:a,asChild:!a,className:"flex w-full items-center justify-between no-underline",children:[n("div",{className:"flex items-center gap-4",children:[e(f,{html:t,className:x("text-sm font-bold leading-[1.4]",{underline:s})}),s&&e(f,{html:s})]}),e(Pe,{className:x("size-5 laptop:size-4",{"rotate-90":o})})]})});var it=ke(Be);export{it as default};
1
+ "use client";import{Fragment as J,jsx as e,jsxs as n}from"react/jsx-runtime";import xe,{forwardRef as X,useCallback as _,useEffect as E,useImperativeHandle as Ne,useMemo as M,useRef as R,useState as D}from"react";import{Picture as K,Text as f,Button as H,Container as Y,Link as j,Heading as oe}from"../../components/index.js";import{withLayout as ke}from"../../shared/Styles.js";import{cn as N,atobID as we}from"../../helpers/utils.js";import Ce,{useNavContext as O}from"./NavProvider.js";import{HeaderNavigationMenu as T,HeaderNavigationBlockType as F,HeaderNavigationActionBlockType as I}from"./types.js";import"react-responsive";import{debounce as Se}from"es-toolkit";import Me from"jump.js";import{useGSAP as ne}from"@gsap/react";import{gsap as le}from"gsap";import{WithSidebar as se,WithSupports as re,WithMulticol as ie,WithGroupCategory as ce}from"./withCategory.js";import{Menu as De,Close as de,User as Le,RightArrow as Pe,LeftArrow as ze,DownArrow as Z,Polygon as Ee}from"./icons/index.js";import He from"../NavigationSearch/index.js";const Be=X((t,a)=>{const{data:{headerNavigation:l}={},buildProps:o,event:s,profile:c,theme:x="light",isTop:r=!1,searchResult:v,onSearch:h,isSearching:L,keywords:y}=t,u=R(null),[d,m]=D(!1),[p,i]=D(!1),[g,S]=D(!1),[C,P]=D(!1),k=R(null),A=()=>{const w=document?.querySelector("body")?.offsetWidth||0;P(w<=1440)};E(()=>(A(),window.addEventListener("resize",A),()=>{window.removeEventListener("resize",A)}),[]),Ne(a,()=>k.current),E(()=>{k.current&&r&&Me(k.current,{duration:0,offset:k.current?.getBoundingClientRect()?.bottom||0})},[r]),E(()=>{s&&(s.search=()=>m(!0))},[s]),ne(()=>{u?.current&&d&&le.fromTo(u.current,{height:0},{height:"auto",duration:.3})},[d]),E(()=>{document.documentElement.style.overflow=d?"hidden":"auto"},[d]);const W=M(()=>l?.headerBar?.actions?.find(w=>w?.blockType===I.Search)?.searchBar?.[0]||{},[l]);return e(Ce,{buildProps:o,profile:c,isMobile:C,event:s,payloadData:l,children:e("header",{"data-ui-component-id":"HeaderNavigation",className:"relative z-[100]",ref:k,children:n("div",{className:N("hover:text-black hover:bg-white",x==="light"?"text-black":"text-white",{}),onClick:()=>S(!0),children:[e(Te,{data:l,className:"hidden desktop:block",theme:x,onNavItemClick:()=>S(!0)}),e(je,{data:l,className:"block desktop:hidden"}),d&&n("div",{className:"absolute z-[60] top-0 left-0 w-full bg-black/70 flex flex-col",style:{height:`calc(100dvh - ${k?.current?.getBoundingClientRect()?.top}px)`},children:[e("div",{ref:u,className:N("overflow-y-auto",{}),children:e(He,{data:W,keywords:y,isSearching:L,searchResult:v,onSearch:w=>{h?.(w)},onClose:()=>{h?.(),m(!1)}})}),e("div",{className:"flex-1 bg-transparent",onClick:()=>m(!1)})]})]})})})}),Te=X((t,a)=>{const{data:l,onNavItemClick:o,className:s,theme:c}=t,{event:x,profile:r}=O(),[v,h]=D(!1),L=M(()=>ce(l?.categories?.filter(b=>b?.pcShow)),[l]),[y,u]=D(null),[d,m]=D([]),p=R(null),[i,g]=D(!1),S=R(null),C=R(null),P=R(L.map(b=>Array(b?.length||0).fill(null)));E(()=>{L?.length&&m(L?.map((b,z)=>b?.map((B,$)=>({groupIndex:z,index:$,open:!1}))))},[L]);const k=M(()=>{let b=null;for(const z of d){for(const B of z)if(B.open){b=B;break}if(b)break}return b},[d]);E(()=>{document.documentElement.style.overflow=k?.open||i?"hidden":"auto"},[k?.open,i]);const A=(b,z,B)=>{g(!1),y?.components?.[0]?.blockType===F.Links?y?.components?.[0]?.url&&window.open(y?.components?.[0]?.url):(b.stopPropagation(),o?.(),u(L[z][B]),m($=>$.map(V=>V.map(q=>q.groupIndex===z&&q.index===B?{...q,open:!q.open}:{...q,open:!1}))))},W=()=>{m(b=>b.map(z=>z.map(B=>({...B,open:!1}))))},w=M(()=>{if(y)return y?.components?.[0]?.blockType},[y]),ee=se(Re,y),U=ie(Ae,y),he=re($e,{categoriesItem:y,currentNavItemRef:P.current?.[k?.groupIndex||0]?.[k?.index||0]}),ye=M(()=>{switch(w){case F.Sidebar:return e(ee,{});case F.Supports:return e(he,{});case F.Multicol:return e(U,{});default:return null}},[w,y]),te=M(()=>l?.headerBar?.actions?.filter(b=>b?.pcShow),[l]),G=M(()=>te?.find(b=>b?.blockType===I.Profile),[te]),ae=_(()=>{g(b=>!b)},[]);return E(()=>{if(p?.current){const b=p.current;return b.addEventListener("click",ae),()=>{b.removeEventListener("click",ae)}}},[ae]),ne(()=>{k?.open&&le.fromTo(C?.current,{height:0},{height:"auto"})},[k?.open]),n(Y,{className:N("relative h-[96px]",s),children:[n("div",{ref:S,onClick:W,className:"flex h-full flex-col justify-end gap-4",children:[n("div",{className:"flex items-center justify-between",children:[e(fe,{}),e(ve,{ref:p,actions:te,activeStatus:i})]}),e("div",{className:"flex justify-between",children:L?.map((b,z)=>e("div",{className:"flex gap-3",children:b?.map((B,$)=>e("div",{ref:V=>{P.current[z][$]=V},className:"group cursor-pointer",children:n("div",{className:"relative",children:[n("div",{className:"flex items-center gap-1 pb-4",onClick:V=>A(V,z,$),children:[e(f,{html:B.text,className:"text-sm font-bold leading-[1.4]"}),e(Z,{className:N("opacity-0 size-4 group-hover:opacity-100 transition-opacity duration-500",{"rotate-180":k?.groupIndex===z&&k?.index===$,"opacity-100":v&&k?.groupIndex===z&&k?.index===$})})]}),e("div",{className:N("absolute bottom-0 left-0 h-[2px] w-0 transition-all duration-500",{"w-[calc(100%-20px)]":k?.groupIndex===z&&k?.index===$},c==="dark"?"bg-white":"bg-[#1D1D1F]")})]})},B.id))},`groupCategory-${z}`))})]}),n("div",{className:N("border-t border-b-[#E4E5E6] text-black absolute left-0 top-full z-[999] flex w-full flex-col bg-black/70 overflow-hidden",{hidden:!(k?.open&&y)}),onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),style:{height:`calc(100dvh - ${S?.current?.getBoundingClientRect()?.bottom}px)`},children:[e("div",{ref:C,className:N("relative z-50",{"overflow-hidden":w!==F.Supports}),children:ye}),e("div",{className:"flex-1 bg-transparent",onClick:W})]}),i&&n("div",{className:"absolute left-0 z-[999] flex w-full bg-black/70 h-[100dvh] top-full",children:[e("div",{className:"absolute w-[272px] bg-white p-4",style:{right:`calc(100% - ${p?.current?.getBoundingClientRect()?.right}px)`,top:"-36px"},children:r?.email?n(J,{children:[e(f,{html:r?.nick_name||G?.welcome,className:"text-sm font-bold"}),e("div",{className:"h-[1px] mt-2 bg-[#D9D9D9]"}),e("div",{className:"mt-2",children:G?.profiles?.map(b=>e(Q,{className:"py-2",label:b?.title,href:b?.url},b.id))})]}):n(J,{children:[e(Ee,{className:"absolute -top-2 text-white right-[46px] z-30"}),e(f,{html:G?.benefits_title,className:"text-sm font-bold leading-[1.4]"}),e("div",{className:"mt-2 flex flex-col gap-1",children:G?.benefits?.map(b=>n("div",{className:"flex items-center gap-[6px]",children:[e(K,{source:b.benefitIcon?.url,className:"size-4",alt:b.benefit,width:16,height:16}),e(f,{html:b.benefit,className:"text-sm font-bold leading-[1.4]"})]},b.id))}),n("div",{className:"mt-4 flex items-center gap-2",children:[e(H,{variant:"secondary",size:"lg",onClick:()=>x?.join?.(),children:e(f,{html:G?.primaryButton||"Join Now",className:"font-bold"})}),e(H,{variant:"primary",size:"lg",onClick:()=>x?.login?.(),children:e(f,{html:G?.secondaryButton||"Log In",className:"font-bold"})})]})]})}),e("div",{className:"flex-1 bg-transparent",onClick:()=>g(!1)})]})]})}),Re=xe.memo(({sidebarCategoriesMetadata:t,seriesMetadata:a})=>{const{buildProps:l}=O(),[o,s]=D([]),[c,x]=D(-1),r=R(null),v=_(()=>{const u=t?.subcategories;if(!u?.length)return;const d=u.findIndex(i=>!!i?.subSubCategories),m=u.findIndex(i=>!i?.subSubCategories),p=u.map((i,g)=>({index:g,open:d===g||m===g}));s(p)},[t]);E(()=>{v()},[v]);const h=M(()=>{const u=t?.subcategories?.[o?.find(m=>m.open)?.index||0],d=a?.find(m=>m?.label?.toLowerCase()===u?.label?.toLowerCase())||{};if(u?.collections){const m=l?.categories?.[u?.collections]||{};return{label:d?.label,isCollection:!0,banner:d?.banner,primary:d?.primary,series:[{products:m?.products}]}}else if(u?.subSubCategories){const m=u?.subSubCategories?.[c],p=a?.find(i=>i?.label?.toLowerCase()===m?.label?.toLowerCase())||{};if(m?.collections){const i=l?.categories?.[m?.collections]||{};return{label:p?.label,isCollection:!0,banner:p?.banner,primary:p?.primary,series:[{products:i?.products}]}}else return p}else return d},[t,o,c,a]),L=_((u,d)=>{if(d?.subSubCategories?.length>0?x(0):x(-1),d?.subSubCategories?.length>0)s(m=>m.map(p=>p.index===u?{...p,open:!0}:{...p,open:!1}));else{const p=t?.subcategories?.findIndex(i=>!!i?.subSubCategories);s(i=>i.map(g=>({...g,open:g.index===u||g.index===p})))}},[t,v]),y=(u,d)=>{s(m=>m.map(p=>p.index===u?{...p,open:!0}:{...p,open:!1})),x(d)};return n(Y,{childClassName:"lg-desktop:gap-12 flex bg-white gap-8",children:[n("div",{className:"lg-desktop:basis-[356px] flex basis-[284px] flex-col gap-4 py-4",style:{userSelect:"none"},ref:r,children:[e("div",{className:"desktop:h-[416px] flex flex-col overflow-y-auto",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:t?.subcategories?.map((u,d)=>{const m=Array.isArray(u?.subSubCategories)&&u?.subSubCategories?.length>0;return n("div",{children:[n("div",{className:N("flex cursor-pointer items-center justify-between",{"bg-[#F5F5F7]":!m&&o?.find(p=>p.index===d)?.open}),onClick:()=>{L(d,u)},children:[e(f,{html:u.label,className:"p-4 text-sm font-bold leading-[1.4]"}),m&&e(Z,{className:N("size-4",{"rotate-180":o?.find(p=>p.index===d)?.open})})]}),o?.find(p=>p.index===d)?.open&&e("div",{className:"flex flex-col",children:u.subSubCategories?.map((p,i)=>e(f,{html:p.label,onClick:()=>y(d,i),className:N("cursor-pointer hover:bg-[#F5F5F7] px-6 py-4 text-sm font-bold leading-[1.4] text-[#6D6D6F]",{"bg-[#F5F5F7]":c===i})},`subSubItem-${d}-${i}`))})]},`subcategoryItem-${d}`)})}),t&&e("div",{className:"flex",children:n("div",{className:"flex flex-col gap-4",children:[t?.primary&&e(H,{as:"a",href:t?.primary?.url,variant:"primary",size:"lg",className:"text-sm lg-desktop:text-base",children:t?.primary?.label}),t?.secondary&&e(H,{as:"a",href:t?.secondary?.url,variant:"link",size:"lg",className:"justify-start !p-0 text-sm lg-desktop:text-base",children:t?.secondary?.label})]})})]}),n("div",{className:"flex-1 py-4",children:[Reflect.ownKeys(h).length>0&&n("div",{className:"mb-4 flex items-center justify-between",children:[n("div",{className:"flex items-center gap-2",children:[e(f,{html:h?.label,className:"text-xl lg-desktop:text-2xl font-bold leading-[1.4]"}),h?.isCollection&&h?.primary&&e(H,{as:"a",href:h?.primary?.url,variant:"link",size:"lg",className:"justify-start !p-0 text-sm lg-desktop:text-base font-bold leading-[1.2] no-underline",children:h?.primary?.label})]}),e(j,{href:h?.guide?.url,className:"text-sm lg-desktop:text-base leading-[1.2] text-[#6D6D6F]",children:h?.guide?.label})]}),e("div",{className:"flex flex-col gap-4 overflow-y-auto h-[426px]",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:h?.series?.map((u,d)=>n("div",{children:[u.label&&e(f,{html:u.label,className:"text-sm mb-2 font-bold leading-[1.4] text-[#6D6D6F]"}),n("div",{className:"grid grid-cols-3 gap-4",children:[!!h?.banner&&e(j,{asChild:!h?.banner?.href,href:h?.banner?.href,children:n("div",{className:"relative [&_img]:hover:scale-105 [&_img]:hover:transition-all [&_img]:hover:duration-300",children:[e(K,{source:h?.banner?.imageUrl,className:"h-[114px] laptop:h-[120px]",imgClassName:"object-cover h-full"}),n("div",{className:"absolute bottom-0 left-0 right-0 p-4",children:[e(oe,{size:2,html:h?.banner?.title||"Buy in Guide",className:"font-bold text-white"}),e(f,{html:h?.banner?.desc||"20.000mAh",className:"text-sm text-white font-bold"})]})]})}),u.products?.map((m,p)=>e(ue,{product:m,isCollection:h?.isCollection},`seriesProductItem-${p}`))]})]},`seriesItem-${d}`))})]})]})}),Ae=({multicolMetadata:t})=>{const a=R(null);return e("div",{ref:a,children:e(Y,{childClassName:"bg-white",className:"h-full",children:e("div",{className:"flex gap-4 py-4",children:t?.map((l,o)=>e("div",{className:"w-1/4",children:e(me,{item:l})},`multicolItem-${l?.label}-${o}`))})})})},$e=({supportsMetadata:t,currentNavItemRef:a})=>{const l=R(null),[o,s]=D(null),[c,x]=D(0);E(()=>{if(l?.current){const v=l?.current?.getBoundingClientRect();x(v.height)}},[l]);const r=Se(()=>{if(a){const v=a.getBoundingClientRect();s(v)}},500);return E(()=>(r(),window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r)}),[r]),E(()=>{if(a){const v=a.getBoundingClientRect();s(v)}},[a]),e("div",{className:"absolute top-0 h-full bg-white transition-all duration-500 overflow-hidden",style:{right:`calc(100% - ${o?.right}px)`,height:c},children:e("div",{ref:l,className:"p-4",children:t?.map(v=>e("div",{className:"py-2",children:e(j,{href:v.url,className:"text-sm font-bold leading-[1.4] no-underline",children:v.label})},v.id))})})},ue=({product:t,isCollection:a})=>{const{buildProps:l}=O();let o=a?t:l?.products?.find(r=>r.handle===t.handle);const s=o?.variants?.find(r=>r.sku===t.sku)||o?.variants?.[0],c=M(()=>`/products/${o?.handle}?variant=${we(s?.id)}`,[o?.handle,s?.id]),x=M(()=>o?.tags?.filter?.(r=>r?.startsWith?.("CLtag"))?.map?.(r=>r?.replace?.("CLtag:",""))?.slice?.(0,2),[o?.tags]);return s?.availableForSale?n("div",{className:"flex shrink-0 items-center gap-4 bg-[#F5F5F7] px-4 py-3 [&_img]:hover:scale-105",children:[e("div",{className:"shrink-0",children:e(K,{source:`${s?.image?.url||t?.images?.[0]?.url}}`,width:90,height:90,className:"size-[96px]",imgClassName:"object-contain h-full"})}),n("div",{className:"relative",children:[e("div",{className:"flex gap-1",children:Array.isArray(x)&&x?.map(r=>e(f,{as:"p",html:r,className:"text-brand-0 whitespace-nowrap mb-1 inline-block h-[24px] rounded-full border-[1.6px] border-[#00BEFA] px-[6px] text-sm font-bold !leading-[22px]"}))}),e(j,{href:c,className:"no-underline hover:text-current",children:e(f,{className:"lg-desktop:h-[44px] lg-desktop:text-base line-clamp-2 h-[40px] text-sm font-bold leading-[1.4]",html:o?.title||t?.name})}),t?.desc&&e(f,{as:"p",html:t?.desc,className:"lg-desktop:text-sm line-clamp-1 mt-1 text-xs font-bold leading-[1.4] text-[#6D6D6F]"})]})]}):null},me=({item:t,allPicture:a})=>n(J,{children:[t?.columns&&n(J,{children:[e(f,{html:t.label,as:"div",className:"my-2 text-sm font-bold leading-[1.4] text-[#6D6D6F]"}),e("div",{className:"mt-2 flex flex-col",children:t.columns?.map(l=>n("div",{className:"py-2 flex items-center gap-1",children:[e(j,{href:l.url,className:"text-sm font-bold leading-[1.4] no-underline",children:l.label}),l?.badge&&e(f,{as:"p",html:l?.badge||"badge",className:"text-sm font-bold !leading-[24px] text-brand-0 h-[24px] rounded-full border-[1.6px] border-[var(--brand-color-0)] px-[6px]"})]},l.label))})]}),t?.imageUrl&&n("div",{className:N("laptop:h-[280px] desktop:h-[224px] lg-desktop:h-[280px] h-[240px] max-w-[358px] tablet:max-w-[346px] laptop:max-w-[440px] desktop:w-full relative overflow-hidden",{"tablet:max-w-none laptop:max-w-none":a}),children:[e(K,{source:t.imageUrl,width:404,height:280,className:"size-full",imgClassName:"object-cover h-full hover:scale-105 transition-all duration-300"}),n(j,{href:t.url,className:"absolute bottom-4 left-4 z-10 flex flex-col justify-end no-underline",children:[e(f,{html:t.title,className:N("lg-desktop:text-2xl text-xl font-bold leading-[1.2] text-white",{"text-black":t?.theme==="dark"})}),t.subtitle&&e(f,{html:t.subtitle,className:N("text-sm font-bold leading-[1.4] text-white",{"text-black":t?.theme==="dark"})}),t?.primary?.label&&e(H,{as:"a",href:t?.primary?.url,variant:"link",size:"lg",className:N("text-sm font-bold mr-auto !p-0 leading-[1.4] text-white",{"text-black":t?.theme==="dark"}),children:t?.primary?.label||"more"})]})]})]}),je=X(({data:t,className:a},l)=>{const o=M(()=>ce(t?.categories?.filter(w=>w?.mobileShow)),[t]),{currentMenu:s,setCurrentMenu:c,subSubCategory:x}=O(),[r,v]=D(!1),[h,L]=D(0),[y,u]=D(null),d=R(null);E(()=>{if(d?.current&&r){const w=d?.current?.getBoundingClientRect();L(window?.innerHeight-(w?.bottom||0))}},[r]),ne(()=>{le.fromTo(d.current,{height:0},{height:h,duration:.3})},[h]),E(()=>{document.documentElement.style.overflow=r?"hidden":"auto"},[r]);const m=M(()=>y?.components?.[0]?.blockType,[y]),p=re(Oe,{categoriesItem:y}),i=se(Ie,y),g=ie(_e,y),S=M(()=>{switch(m){case F.Sidebar:return e(i,{});case F.Supports:return e(p,{});case F.Multicol:return e(g,{});default:return null}},[m,y,p]),C=_(()=>{v(!1),L(0),c&&c(T.Primary)},[v,L,c]),P=M(()=>t?.headerBar?.actions?.filter(w=>w?.mobileShow&&w?.blockType!==I.Profile),[t]),k=M(()=>t?.headerBar?.actions?.find(w=>w?.mobileShow&&w?.blockType===I.Profile)||{},[t]),A=M(()=>{switch(s){case T.Primary:return e(Ue,{actions:P,menuOpen:r,onMenuOpenClose:()=>{v(!1),L(0)},onMenuOpenClick:()=>v(!0)});case T.Secondary:return e(ge,{title:y?.text,onMenuOpenClose:C,onMenuBackClick:()=>c?.(T.Primary)});case T.Third:return e(ge,{title:x?.label,onMenuOpenClose:C,onMenuBackClick:()=>c?.(T.Secondary)});default:return null}},[r,s,c,y,P,x,C]),W=_((w,ee)=>{const U=Array.isArray(o)?Array.isArray(o[w])?o[w][ee]:{}:{};u(U),U?.components?.[0]?.blockType===F.Links?U?.components?.[0]?.url&&window.open(U?.components?.[0]?.url):c?.(T.Secondary)},[o,c]);return n(Y,{className:N("relative h-[52px]",a),children:[A,r&&e("div",{ref:d,className:"absolute left-0 top-full text-black border-t border-[#E4E5E6] z-[999] w-full overflow-y-auto bg-white",style:{height:h},children:s===T.Primary?e(Fe,{categories:o,onPrimaryMenuClick:W,profileAction:k}):S})]})}),Fe=({categories:t,onPrimaryMenuClick:a,profileAction:l})=>n("div",{className:"flex h-full flex-col justify-between",children:[e("div",{className:"tablet:px-8 laptop:px-16 p-4",children:t?.map((o,s)=>n("div",{className:"",children:[o?.map((c,x)=>e(Q,{label:c.text,onClick:()=>a(s,x),icon:c.components?.[0]?.icon},c.id)),e("div",{className:N("my-2 h-px w-full bg-[#E5E5E7]",{hidden:s===t.length-1})})]},`groupCategory-${s}`))}),e(We,{profileAction:l})]}),Ie=({sidebarCategoriesMetadata:t,seriesMetadata:a})=>{const{currentMenu:l,setCurrentMenu:o,subSubCategory:s,setSubSubCategory:c,setCurrentSeriesMetadata:x,currentSeriesMetadata:r,buildProps:v}=O(),[h,L]=D([]),[y,u]=D([]);E(()=>{t?.subcategories?.length&&L(t?.subcategories?.map((i,g)=>({index:g,open:!1})))},[t]),E(()=>{s?.subSubCategories?.length&&u(s?.subSubCategories?.map((i,g)=>({index:g,open:g===0})))},[s]);const d=_((i,g)=>{o&&o(T.Third),c?.(i);const S=a?.find(C=>g!==void 0?i?.subSubCategories?.[g]?.label?.toLowerCase()===C.label?.toLowerCase():i?.label?.toLowerCase()===C.label?.toLowerCase())||{};if(i?.collections){const C=v?.categories?.[i?.collections]||{};x?.({label:S?.label,isCollection:!0,banner:S?.banner,primary:S?.primary,series:[{products:C?.products}]})}else x?.(S)},[a,t,o,c,x]),m=M(()=>a?.find(i=>!!i?.guide)?.guide,[a,t]);return M(()=>{switch(l){case T.Secondary:return n("div",{className:"tablet:px-8 laptop:px-16 flex h-full flex-col justify-between tablet:justify-start tablet:gap-16 p-4",children:[e("div",{children:t?.subcategories?.map((i,g)=>e("div",{children:e(Q,{label:i?.label,active:h.find(S=>S.index===g)?.open,onClick:()=>{d(i)}})},`${i.label}-${g}`))}),n("div",{className:"tablet:items-start flex flex-col items-center gap-4",children:[t?.primary&&e(H,{as:"a",href:t?.primary?.url,variant:"primary",size:"lg",className:"tablet:w-auto w-full text-base",children:t?.primary?.label}),t?.secondary&&e(H,{as:"a",href:t?.secondary?.url,variant:"link",size:"lg",className:"tablet:w-auto tablet:px-0 w-full py-0 text-base",children:t?.secondary?.label})]})]});case T.Third:return n("div",{className:"tablet:px-8 laptop:px-16 p-4",children:[s?.subSubCategories?s?.subSubCategories?.map((i,g)=>{const S=a?.find(P=>P.label.toLowerCase()===i?.label?.toLowerCase())||{};let C={};if(i?.collections){const P=v?.categories?.[i?.collections]||{};C={label:S?.label,isCollection:!0,banner:S?.banner,primary:S?.primary,series:[{products:P?.products}]}}else C=S;return n("div",{children:[Reflect.ownKeys(i).length>0&&e(pe,{matchSeriesMetadata:C,onSubSubCategoryItemClick:()=>u(P=>P.map((k,A)=>({...k,open:A===g}))),expanded:!!y?.find(P=>P.index===g)?.open}),y?.find(P=>P.index===g)?.open&&n(J,{children:[e(be,{matchSeriesMetadata:C}),C?.primary&&e("div",{className:"text-center my-4",children:e(H,{as:"a",href:C?.primary?.url,className:"text-base no-underline leading-[1.2]",variant:"secondary",size:"base",children:C?.primary?.label})})]})]},`${i.label}-${g}`)}):n(J,{children:[Reflect.ownKeys(r).length>0&&e(pe,{matchSeriesMetadata:r}),e(be,{matchSeriesMetadata:r}),r?.primary&&e("div",{className:"text-center my-4 ",children:e(H,{as:"a",href:r?.primary?.url,variant:"secondary",size:"base",className:"text-base no-underline leading-[1.2]",children:r?.primary?.label})})]}),m&&e(j,{href:m?.url,children:e("div",{className:"mt-4",children:e(f,{html:m?.label,className:"text-sm font-bold leading-[1.2] text-[#6D6D6F]"})})})]});default:return null}},[l,t,o,a,h,y,c,s,x,r])},pe=({matchSeriesMetadata:t,onSubSubCategoryItemClick:a,expanded:l})=>n("div",{className:"tablet:pt-0 py-4 flex items-center justify-between",onClick:a,children:[t?.label&&e(f,{html:t?.label,className:"text-sm font-bold leading-[1.4]"}),a&&e(Z,{className:N("size-5",{"rotate-180":l})})]}),be=({matchSeriesMetadata:t})=>e("div",{className:"flex flex-col gap-2 laptop:gap-3",children:!!t?.series?.length&&t?.series?.map((a,l)=>n("div",{children:[a.label&&e(f,{html:a.label,className:"text-sm mb-2 font-bold leading-[1.4] text-[#3D3D3F]"}),n("div",{className:"laptop:grid-cols-3 laptop:gap-4 tablet:grid tablet:grid-cols-2 tablet:gap-3 flex flex-col gap-2",children:[!!t?.banner&&e(j,{asChild:!t?.banner?.href,href:t?.banner?.href,children:n("div",{className:"relative [&_img]:hover:scale-105 [&_img]:hover:transition-all [&_img]:hover:duration-300",children:[e(K,{source:t?.banner?.imageUrl,className:"h-[114px] laptop:h-[120px]",imgClassName:"object-cover h-full"}),n("div",{className:"absolute bottom-0 left-0 right-0 p-4",children:[e(oe,{size:2,html:t?.banner?.title||"Buy in Guide",className:N("font-bold text-white",{"text-black":t?.banner?.theme==="dark"})}),e(f,{html:t?.banner?.desc||"20.000mAh",className:N("text-sm text-white font-bold",{"text-black":t?.banner?.theme==="dark"})})]})]})}),a.products?.map((o,s)=>e(ue,{product:o,isCollection:t?.isCollection},`seriesProductItem-${l}-${s}`))]})]},`seriesItem-${l}`))}),Oe=({supportsMetadata:t})=>e("div",{className:"tablet:px-8 laptop:px-16 p-4",children:t?.map(a=>e(Q,{href:a.url,label:a.label,onClick:()=>{}},a.id))}),_e=({multicolMetadata:t})=>{const a=M(()=>!t?.some(l=>!!l.columns),[t]);return e("div",{className:N("tablet:py-4 tablet:px-8 laptop:px-16 flex flex-col gap-4 tablet:gap-6 p-4",{"tablet:grid tablet:grid-cols-2 tablet:gap-3 laptop:gap-4":a}),children:t?.map((l,o)=>e("div",{children:e(me,{item:l,allPicture:a})},`multicolItem-${l?.label}-${o}`))})},We=({profileAction:t})=>{const[a,l]=D(!1),{profile:o,event:s}=O();return n("div",{className:N("tablet:px-8 laptop:px-16 bg-[#F5F5F7] px-4 py-6",{"p-4":a}),children:[n("div",{className:"flex items-center justify-between",onClick:()=>l(!a),children:[n("div",{className:"flex items-center gap-[14px]",children:[e("div",{className:"flex size-[40px] shrink-0 items-center justify-center rounded-full bg-white",children:e(Le,{})}),e(f,{html:o?.nick_name||t?.welcome,className:"text-base font-bold leading-[1.4]"})]}),!o?.email&&e(Z,{className:N("size-5 laptop:size-4",{"rotate-180":a})})]}),o?.email&&e("div",{className:"mt-4",children:t?.profiles?.map(c=>e(Q,{label:c?.title,href:c?.url},c.id))}),a&&!o?.email&&n("div",{className:"mt-4",children:[e(f,{html:t?.benefits_title,className:"text-sm font-bold leading-[1.4]"}),e("div",{className:"mt-2 flex flex-col gap-1",children:t?.benefits?.map(c=>n("div",{className:"flex items-center gap-[6px]",children:[e(K,{source:c.benefitIcon?.url,className:"size-4",alt:c.benefit,width:16,height:16}),e(f,{html:c.benefit,className:"text-sm font-bold leading-[1.4]"})]},c.id))})]}),!o?.email&&n("div",{className:"mt-4 flex items-center gap-3",children:[e(H,{className:"tablet:flex-none flex-1",variant:"secondary",size:"base",onClick:()=>s?.join?.(),children:e(f,{html:t?.primaryButton||"Join Now",className:"text-sm font-bold leading-[1.4]"})}),e(H,{className:"tablet:flex-none flex-1",variant:"primary",size:"base",onClick:()=>s?.login?.(),children:e(f,{html:t?.secondaryButton||"Log In",className:"text-sm font-bold leading-[1.4]"})})]})]})},Ue=({menuOpen:t,onMenuOpenClose:a,onMenuOpenClick:l,actions:o})=>n("div",{className:"flex h-full items-center justify-between gap-4",children:[e(fe,{}),n("div",{className:"desktop:gap-6 flex items-center gap-4",children:[e(ve,{actions:o}),t?e(de,{className:"size-5",onClick:()=>a()}):e(De,{className:"size-5",onClick:()=>l()})]})]}),fe=()=>{const{payloadData:t,isMobile:a}=O();return e("div",{className:"[&>svg]:w-full hover:text-brand-0 cursor-pointer",onClick:()=>{window.location.href="/"},dangerouslySetInnerHTML:{__html:a?t?.headerBar?.mobileLogo:t?.headerBar?.desktopLogo}})},ve=X(({actions:t,activeStatus:a=!1},l)=>{const{event:o}=O(),[s,c]=D(null),x=_((r,v)=>{switch(c(v),r?.blockType){case I.Search:o?.search?.();break;case I.Cart:o?.cart?.();break;case I.Profile:o?.profile?.();break;case I.Livestream:o?.livestream?.();break;default:return()=>{}}},[o]);return e("div",{className:"desktop:gap-6 flex items-center gap-4",children:Array.isArray(t)&&t?.map((r,v)=>e("div",{ref:r.blockType===I.Profile?l:null,onClick:()=>x(r,v),children:e(f,{html:r.icon,className:N("cursor-pointer size-5",{"text-brand-0":a&&s===v})})},r.id))})}),ge=({title:t,onMenuOpenClose:a,onMenuBackClick:l})=>n("div",{className:"flex h-full items-center gap-3",children:[e(ze,{className:"size-5",onClick:()=>l()}),e(f,{html:t,className:"flex-1 text-center text-base font-bold leading-[1.4]"}),e(de,{className:"size-5",onClick:()=>a()})]}),Q=({label:t,href:a,onClick:l,active:o,icon:s,className:c})=>e("div",{className:N("flex cursor-pointer items-center justify-between py-4",c),onClick:l,children:n(j,{href:a,asChild:!a,className:"flex w-full items-center justify-between no-underline",children:[n("div",{className:"flex items-center gap-4",children:[e(f,{html:t,className:N("text-sm font-bold leading-[1.4]",{underline:s})}),s&&e(f,{html:s})]}),e(Pe,{className:N("size-5 laptop:size-4",{"rotate-90":o})})]})});var it=ke(Be);export{it as default};
2
2
  //# sourceMappingURL=index.js.map