import{j as e,a as n,L as t}from"./chunks/components-common.js";import{c as i}from"./chunks/client.js";import"./chunks/vendor-react.js";const o=({feedId:i})=>{var o,d,s,a,r,l;const[c,f]=n.useState(null),[u,h]=n.useState(!0),[v,m]=n.useState(null),[w,j]=n.useState(null);if(n.useEffect((()=>{i&&(async()=>{var e,n,t,o,d,s;try{h(!0);const d=await fetch(`${window.etfFrontend.apiBase}/feeds/${i}`,{headers:{"X-WP-Nonce":window.etfFrontend.nonce}});if(!d.ok)throw new Error(`Failed to fetch feed: ${d.status}`);const s=await d.json();f(s);const a=(null==(n=null==(e=s.meta)?void 0:e.etf_settings)?void 0:n.tikTokAccountId)||null;j({feedId:i,accountId:a,layout:(null==(o=null==(t=s.meta)?void 0:t.etf_layout)?void 0:o.type)||"grid",apiBase:window.etfFrontend.apiBase,isDev:window.etfFrontend.isDev,apiResponse:s}),a||m("No TikTok account connected to this feed. Please edit the feed and select an account.")}catch(a){m(a.message),j({feedId:i,error:a.message,stack:a.stack,apiBase:(null==(d=window.etfFrontend)?void 0:d.apiBase)||"undefined",nonce:(null==(s=window.etfFrontend)?void 0:s.nonce)?"available":"missing"})}finally{h(!1)}})()}),[i]),u)return e.jsx("div",{className:"etf-loading",children:e.jsx("div",{className:"etf-loading-spinner"})});if(v)return e.jsxs("div",{className:"etf-error",children:[e.jsx("div",{children:v}),w&&window.etfFrontend&&"1"===window.etfFrontend.isDev&&e.jsxs("details",{className:"etf-debug-info",children:[e.jsx("summary",{children:"Debug Information"}),e.jsx("pre",{children:JSON.stringify(w,null,2)})]})]});if(!c)return e.jsx("div",{className:"etf-error",children:"No feed data found"});null==(o=c.title)||o.rendered;const x=(null==(s=null==(d=c.meta)?void 0:d.etf_layout)?void 0:s.type)||"grid",k=(null==(r=null==(a=c.meta)?void 0:a.etf_settings)?void 0:r.tikTokAccountId)||null,g=(null==(l=c.meta)?void 0:l.etf_settings)||{};return e.jsxs("div",{className:"etf-frontend-feed w-full max-w-3xl mx-auto",children:[!k&&e.jsxs("div",{className:"etf-error",children:[e.jsx("div",{children:"This feed doesn't have a TikTok account connected."}),window.etfFrontend&&"1"===window.etfFrontend.isDev&&e.jsxs("div",{className:"etf-debug-info",children:[e.jsx("p",{children:"To fix this issue:"}),e.jsxs("ol",{children:[e.jsx("li",{children:"Log in to your WordPress admin dashboard"}),e.jsx("li",{children:"Go to TikTok Feed ยป Feeds"}),e.jsxs("li",{children:["Edit this feed (ID: ",i,")"]}),e.jsx("li",{children:"Connect a TikTok account in the feed settings"}),e.jsx("li",{children:"Save the feed"})]})]})]}),k&&e.jsx(t,{layout:x,tikTokAccountId:k,feedSettings:g,showFallbackPreview:!0})]})};document.addEventListener("DOMContentLoaded",(()=>{try{if(!window.etfFrontend)return;document.querySelectorAll(".etf-shortcode-container").forEach((n=>{const t=n.getAttribute("data-feed-id");if(t){i.createRoot(n).render(e.jsx(o,{feedId:t}))}}))}catch(n){document.querySelectorAll(".etf-shortcode-container").forEach((e=>{e.innerHTML='