"use strict";var e=require("react"),t=require("@gem-sdk/core");exports.useBreadcrumb=()=>{let[a,i]=e.useState(),[r,n]=e.useState(),[d,o]=e.useState(),s=t.usePageType();e.useEffect(()=>{let e=parent.document.querySelector(".iframe");e||(e=document.querySelector("#storefront")),e&&(i(e.getAttribute("data-page-name")??void 0),n(e.getAttribute("data-assigned-product-title")??void 0),o(e.getAttribute("data-assigned-collection-title")??void 0))},[]),e.useEffect(()=>{let e=e=>{i(e.detail?.pageName??void 0)},t=e=>{n(e.detail?.assignedProductTitle??void 0)},a=e=>{o(e.detail?.assignedCollectionTitle??void 0)};return window.addEventListener("change-page-name",e),window.addEventListener("change-product-assigned",t),window.addEventListener("change-collection-assigned",a),()=>{window.removeEventListener("change-page-name",e),window.removeEventListener("change-product-assigned",t),window.removeEventListener("change-collection-assigned",a)}},[]);let c=e.useMemo(()=>[{pageType:"GP_PRODUCT",listBreadcrumb:["Home",r??"Product Title"]},{pageType:"GP_COLLECTION",listBreadcrumb:["Home",d??"Collection Title"]},{pageType:"GP_ARTICLE",listBreadcrumb:["Home","Blog","Article Title"]},{pageType:"GP_STATIC",listBreadcrumb:["Home",a??"Landing Page Title"]},{pageType:"GP_INDEX",listBreadcrumb:["Home"]},{pageType:"THEME_SECTION",listBreadcrumb:["Home","Page Title"]}],[d,r,a]),l="undefined"!=typeof window?window.location.search:"",u=e.useMemo(()=>new URLSearchParams(l).get("pageType"),[l]),g=e.useMemo(()=>u||s,[u,s]),m=e.useMemo(()=>c.find(e=>e.pageType===g)?.listBreadcrumb||[],[c,g]);return{currentBreadcrumb:m}};
