"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),T=require("react"),D=require("classcat"),F=require("use-sync-external-store/shim"),J=e=>e&&e.__esModule?e:{default:e};function B(e){if(e&&e.__esModule)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const c=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(n,o,c.get?c:{enumerable:!0,get:()=>e[o]})}}return n.default=e,Object.freeze(n)}const r=B(T),C=J(D),G=".utterances{position:relative;box-sizing:border-box;width:100%;max-width:760px;margin-left:auto;margin-right:auto}.utterances-frame{color-scheme:light;position:absolute;left:0;right:0;width:1px;min-width:100%;max-width:100%;height:100%;border:0}";function k(e,n){window.dispatchEvent(new StorageEvent("storage",{key:e,newValue:n}))}const M=(e,n,o)=>{e.setItem(n,o),k(n,o)},H=(e,n)=>{e.removeItem(n),k(n)},_=(e,n)=>e.getItem(n),K=e=>(window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)),Q=()=>"",m=e=>e==="session"?window.sessionStorage:window.localStorage;function V(e){const n="utterances-session",o=()=>_(m(e),n),c=F.useSyncExternalStore(K,o,Q),i=r.useCallback(l=>{try{const a=typeof l=="function"?l(c||""):l;a==null?H(m(e),n):M(m(e),n,a)}catch(a){console.warn(a)}},[n,c,e]);return r.useEffect(()=>{_(m(e),n)===null&&M(m(e),n,"")},[n,e]),[c||"",i]}const W="preferred-color-scheme",I="https://utteranc.es",X=`${I}/utterances.html`,Y=({repo:e,theme:n="github-light",label:o,issueNumber:c,issueTerm:i,tokenStorage:l="local",loading:a="lazy",onLoad:g,onError:O,placeholder:u=!1,containerClassName:R,containerStyle:U,iframeClassName:q,iframeStyle:P})=>{const[f,w]=r.useState({}),[b,$]=r.useState(!1),[y,x]=V(l);r.useEffect(()=>{const t=document.createElement("style");return t.appendChild(document.createTextNode(G)),document.head.appendChild(t),()=>{document.head.removeChild(t)}},[]),r.useEffect(()=>{const t={};t.repo=e,n===W?t.theme=window.matchMedia("(prefers-color-scheme: dark)").matches?"github-dark":"github-light":t.theme=n,o&&(t.label=o),c&&(t["issue-number"]=String(c)),i&&(Array.isArray(i)?t["issue-term"]=i.join(" "):t["issue-term"]=i);const s=new URL(location.href),S=s.searchParams.get("utterances");S&&(x(S),s.searchParams.delete("utterances"),history.replaceState(void 0,document.title,s.href));const v=document.querySelector("link[rel='canonical']");t.url=v?v.href:s.origin+s.pathname+s.search,t.origin=s.origin,t.pathname=s.pathname.length<2?"index":s.pathname.slice(1).replace(/\.\w+$/,""),t.title=document.title;const E=document.querySelector("meta[name='description']");t.description=E?E.content:"";const j=encodeURIComponent(t.description).length;j>1e3&&(t.description=t.description.slice(0,Math.floor(t.description.length*1e3/j)));const L=document.querySelector("meta[property='og:title'],meta[name='og:title']");return t["og:title"]=L?L.content:"",t.session=S||y||"",w(t),()=>{w({})}},[e,n,o,c,i,l,y,x]);const h=r.useRef(null),p=r.useCallback(t=>{if(t.origin!==I)return;const s=t.data;s&&s.type==="resize"&&s.height&&h.current&&(h.current.style.height=`${s.height}px`)},[]);r.useEffect(()=>(window.addEventListener("message",p),()=>window.removeEventListener("message",p)),[p]);const z=r.useMemo(()=>JSON.stringify(f)!=="{}",[f]),A=r.useCallback(t=>{$(!0),g&&g(t)},[g]),N=r.useMemo(()=>typeof u=="boolean"?u?d.jsx("p",{children:"Loading comments..."}):null:u,[u]);return d.jsx("div",{className:C.default(["utterances",R]),ref:h,style:U,children:z&&d.jsxs(d.Fragment,{children:[d.jsx("iframe",{className:C.default(["utterances-frame",q]),title:"Comments",scrolling:"no",src:`${X}?${new URLSearchParams(f)}`,loading:u?"eager":a,style:{display:!b&&u?"none":"block",...P},onLoad:A,onError:O}),!b&&N]})})},Z=Y;exports.Utterances=Z;