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