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