1import{i as ct,a as Q,j as e,k as Xt,l as Ze,r as s,U as Ue,m as ea,n as kt,P as vt,d as Ia,S as Ea,o as Ye,g as ce,p as Ua,q as za,t as $t,X as de,c as fe,v as be,w as La,u as Nt,s as Z,F as Pa,x as Ra,y as it,e as P,z as Fa,D as $a,G as Ha,H as Oa,J as ye,K as Va,N as qe,O as nt,Q as Qe,R as Ht,T as we,B as Ae,V as Ba,W as Ga,Y as Ce,Z as ta,_ as Ka,$ as qa,a0 as _t,a1 as ft,C as Wa,a2 as Za,L as bt,I as Ya,a3 as Qa,a4 as Ja,a5 as Xa,a6 as aa,a7 as es,a8 as ts,a9 as as,aa as jt,b as ss,ab as rs,ac as Ot,ad as ls,ae as ns,af as is,ag as os}from"./index-B5dEHq60.js";import{P as St,a as Ct,b as Dt}from"./popover-BeqUoNwZ.js";import{D as ds}from"./DashboardLayout-D-nb-1ga.js";import{U as xt}from"./upload-DBlPL4cX.js";import{r as At,g as Mt}from"./tiktok-CzSl5bNg.js";import{A as Tt,I as It,E as cs}from"./EmptyState-CTL9RMnI.js";import{P as ze,C as sa}from"./PlatformIcon-C-6WuizG.js";import{D as ra,a as la,b as na,c as ot,P as Vt,M as xs,d as ms,C as us,I as gs,S as et}from"./skeleton-A_Rr1es9.js";import{R as We}from"./refresh-cw-D_kjuMZ1.js";import{E as ps}from"./external-link-p-LAAa6i.js";import{C as ia,a as oa,b as da,S as hs,A as fs,c as bs}from"./scroll-area-CM-kYeMp.js";import{A as ca,a as xa,b as ma,c as ua,d as ga,e as pa,f as ha,g as fa}from"./alert-dialog-Bc0WYmBf.js";import{l as ys,a as js,g as tt,c as Bt,b as ws,d as ks,s as vs,C as Ns}from"./chat-A2o3TYQQ.js";import{M as ba}from"./index-BcNjXLRd.js";import{C as _s}from"./clock-BSJdbc4i.js";import{S as Gt}from"./send-DakV1okm.js";import{H as dt,T as Ss}from"./textarea-Md_aH0bR.js";import{L as Cs}from"./lock-whfmVE_Z.js";import{s as Ds}from"./schemas-D96uyUNQ.js";import{O as ya,C as ja,a as As,T as wa,D as ka,P as Ms,R as Ts,b as Is,c as Et,d as Ut,e as zt,f as Lt,g as Pt}from"./dialog-CBP0E7sd.js";import{B as va}from"./badge-B9r9Irtl.js";import{c as Es,L as Us}from"./renderMarkdownBold-DAKbyMoC.js";import{I as Rt}from"./image-off-DAsmjFfi.js";import{S as Ft}from"./share-2-D521axUV.js";import{P as zs}from"./progress-AJg0HHnu.js";import{C as Kt}from"./hookTypeMap-dKYo7iZR.js";import{S as Ls}from"./search-BIZAXII2.js";import{G as Ps}from"./grid-3x3-B0KThtYX.js";import{C as Rs}from"./Combination-D5ZSvGLO.js";import"./pdf-u_OiRbVB.js";import"./copy-8CQgUwdQ.js";import"./index-ByKwFoW9.js";import"./calendar-DYITj_4U.js";import"./LineChart-CbVvMhxj.js";import"./target-Dq1sT9Sp.js";import"./film-BIJiSzZf.js";import"./trending-down-CRp4wYhM.js";import"./rocket-CQBt_iy7.js";import"./trophy-hEZowlON.js";import"./index-BdQq_4o_.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const qt=ct("FileVideo",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m10 11 5 3-5 3v-6Z",key:"7ntvm4"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Fs=ct("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const yt=ct("Mic",[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const wt=ct("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]),$s=({onUploadClick:t,disabled:r=!1,disabledLabel:n,infoText:i,width:a="full"})=>{const{t:l}=Q("common"),M=i??l("preUpload.infoText"),b=a==="fixed"?"w-[280px]":"w-full";return e.jsxs("div",{className:`group relative ${b} inline-flex items-stretch rounded-full bg-[#15172a] shadow-[0_8px_24px_-6px_rgba(10,12,30,0.45),0_2px_8px_rgba(0,0,0,0.18)] ring-1 ring-white/5 transition-all hover:shadow-[0_12px_30px_-8px_rgba(10,12,30,0.55),0_3px_10px_rgba(0,0,0,0.22)] ${r?"opacity-55":""}`,children:[e.jsxs("button",{type:"button",onClick:t,disabled:r,className:`peer/up flex-1 min-w-0 flex items-center gap-3 pl-2.5 pr-3 py-2 rounded-l-full transition-colors text-left ${r?"cursor-not-allowed":"cursor-pointer hover:bg-white/[0.04] active:bg-white/[0.06]"}`,children:[e.jsx("span",{className:"shrink-0 w-9 h-9 rounded-full bg-white/[0.08] flex items-center justify-center ring-1 ring-white/10",children:e.jsx(xt,{className:"w-4 h-4 text-white",strokeWidth:2.25})}),e.jsx("span",{className:"flex flex-col min-w-0 leading-tight",children:r&&n?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[13px] font-semibold text-white tracking-tight truncate group-hover:hidden",children:l("preUpload.title")}),e.jsx("span",{className:"text-[11px] text-white/55 truncate group-hover:hidden",children:l("preUpload.subtitle")}),e.jsx("span",{className:"hidden group-hover:inline text-[13px] font-semibold text-white/85 truncate",children:n}),e.jsx("span",{className:"hidden group-hover:inline text-[11px] text-white/55 truncate",children:l("preUpload.upgradeToPro")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[13px] font-semibold text-white tracking-tight truncate",children:l("preUpload.title")}),e.jsx("span",{className:"text-[11px] text-white/55 truncate",children:l("preUpload.subtitle")})]})})]}
21),e.jsx("span",{"aria-hidden":!0,className:"self-stretch w-px my-2 bg-white/10"}),e.jsxs(St,{children:[e.jsx(Ct,{asChild:!0,children:e.jsx("button",{type:"button",className:"shrink-0 w-10 flex items-center justify-center rounded-r-full text-white/65 hover:text-white hover:bg-white/[0.04] active:bg-white/[0.06] transition-colors",onClick:w=>w.stopPropagation(),"aria-label":l("preUpload.ariaInfo"),children:e.jsx(Xt,{className:"w-4 h-4"})})}),e.jsx(Dt,{side:"top",className:"max-w-[220px] text-center text-[11px] p-2.5 leading-snug",children:M})]})]})},Hs=3,Na=({isTeamMember:t=!1})=>{const{t:r}=Q("dashboard"),{accounts:n,igAccounts:i,account:a,switchAccount:l,refreshIgAccounts:M}=Ze(),[b,w]=s.useState(!1),[k,y]=s.useState(!1),[S,T]=s.useState(!1),I=[...n.map(d=>({id:d.id,platform:"tiktok",handle:d.handle,display_name:d.display_name,avatar_url:d.avatar_url,follower_count:d.follower_count||0,is_active:d.id===(a==null?void 0:a.id)&&((a==null?void 0:a.platform)??"tiktok")==="tiktok"})),...i.map(d=>({id:d.id,platform:"instagram",handle:d.handle,display_name:d.display_name,avatar_url:d.avatar_url,follower_count:d.follower_count||0,is_active:d.id===(a==null?void 0:a.id)&&((a==null?void 0:a.platform)==="instagram"||(a==null?void 0:a.platform)==null),is_pending:d.verification_status==="pending"}))];if(t&&I.length<2)return null;const R=!t&&n.length+i.length<Hs,v=async()=>{const d=await At(),f=Mt(d),j=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),L=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);if(j||L){window.location.href=f;return}const g=600,U=700,D=(window.screen.width-g)/2,F=(window.screen.height-U)/2,B=`width=${g},height=${U},left=${D},top=${F},toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes`,H=window.open(f,"tiktok_oauth",B);(!H||H.closed||typeof H.closed>"u")&&(window.location.href=f)},u=async(d,f)=>{if(!(d===(a==null?void 0:a.id)&&((a==null?void 0:a.platform)??"tiktok")===f)){w(!0);try{await l(d,f)}catch(j){console.error("Failed to switch account:",j)}finally{w(!1)}}};return I.length===0?null:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-2xl shadow-lg overflow-hidden",children:[e.jsx("div",{className:"divide-y divide-gray-100 dark:divide-neutral-800",children:I.map(d=>{const j=d.platform==="tiktok"||!d.is_pending;return e.jsxs("button",{onClick:()=>j?u(d.id,d.platform):void 0,disabled:!j||b,className:`w-full p-2.5 sm:p-3 flex items-center gap-2.5 sm:gap-3 transition-all text-left ${d.is_active?"bg-gray-50 dark:bg-neutral-800/50":j?"hover:bg-gray-50 dark:hover:bg-neutral-800/50":""} ${b?"opacity-50 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:"w-10 h-10 sm:w-11 sm:h-11 rounded-full overflow-hidden bg-gradient-to-br from-gray-200 to-gray-300 dark:from-neutral-800 dark:to-neutral-700",children:d.avatar_url?e.jsx("img",{src:d.avatar_url,alt:d.display_name||d.handle,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(Ue,{className:"w-5 h-5 text-gray-400 dark:text-gray-500"})})}),e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 ring-2 ring-white dark:ring-neutral-900 shadow rounded-md overflow-hidden",children:e.jsx(ze,{platform:d.platform==="instagram"?"instagram":"tiktok",size:18})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("p",{className:"font-semibold text-gray-900 dark:text-gray-100 text-sm truncate",children:["@",d.handle]}),d.is_pending&&e.jsx(ea,{className:"w-3 h-3 text-amber-500 shrink-0","aria-label":"Verifizierung ausstehend"})]}),e.jsxs("p",{className:"text-gray-500 dark:text-gray-400 text-xs",children:[Os(d.follower_count)," Followers"]})]}),d.is_active&&e.jsx("div",{className:"w-5 h-5 bg-gray-900 dark:bg-purple-600 rounded-full flex items-center justify-center flex-shrink-0",children:e.jsx(kt,{className:"w-3 h-3 text-white"})})]},`${d.platform}-${d.id}`)})}),R&&e.jsxs("button",{onClick:()=>y(!0),className:"w-full p-2.5 sm:p-3 border-t border-gray-100 dark:border-neutral-800 hover:bg-gray-50 dark:hover:bg-neutral-800/50 text-gray-600 dark:text-gray-400 text-xs sm:text-sm font-medium transition-all flex items-center justify-center gap-2",children:[e.jsx(vt,{className:"w-4 h-4"}),e.jsx("span",{children:r("accountSwitcher.addAccount")}
21)]}),e.jsxs(Ia,{to:"/settings?tab=accounts",className:"w-full p-2 border-t border-gray-100 dark:border-neutral-800 hover:bg-gray-50 dark:hover:bg-neutral-800/50 text-gray-400 dark:text-gray-500 text-xs transition-all flex items-center justify-center gap-1.5",children:[e.jsx(Ea,{className:"w-3 h-3"}),e.jsx("span",{children:r("accountSwitcher.manageAccounts")})]})]}),e.jsx(Tt,{open:k,onClose:()=>y(!1),onChooseTikTok:v,onChooseInstagram:()=>T(!0)}),e.jsx(It,{open:S,onClose:()=>T(!1),onConnected:M})]})},Os=t=>t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":t.toString(),Vs=({account:t,isLoading:r,syncing:n,onRefresh:i,isTeamMember:a=!1})=>{const{t:l}=Q("dashboard");if(r)return e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-3xl shadow-lg p-6 animate-pulse",children:[e.jsx("div",{className:"aspect-square bg-gray-200 dark:bg-neutral-700 rounded-2xl mb-4"}),e.jsx("div",{className:"h-5 bg-gray-200 dark:bg-neutral-700 rounded w-3/4 mb-2"}),e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-neutral-700 rounded w-1/2"})]});const M=async()=>{const T=await At(),I=Mt(T),R=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),v=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);if(R||v){window.location.href=I;return}const u=600,d=700,f=(window.screen.width-u)/2,j=(window.screen.height-d)/2,L=`width=${u},height=${d},left=${f},top=${j},toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes`,g=window.open(I,"tiktok_oauth",L);(!g||g.closed||typeof g.closed>"u")&&(window.location.href=I)},[b,w]=s.useState(!1),[k,y]=s.useState(!1),S=()=>w(!0);return t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-[2rem] shadow-2xl overflow-hidden border-4 border-white dark:border-neutral-900",children:[e.jsx("div",{className:"bg-white dark:bg-neutral-900",children:e.jsxs("div",{className:"relative aspect-square bg-gradient-to-br from-gray-100 to-gray-200 overflow-hidden",children:[t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:t.display_name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(Ue,{className:"w-14 h-14 text-gray-300"})}),e.jsx("div",{className:"absolute top-2 left-2 ring-2 ring-white shadow-md rounded-md overflow-hidden",title:t.platform==="instagram"?"Instagram":"TikTok",children:e.jsx(ze,{platform:t.platform==="instagram"?"instagram":"tiktok",size:26})})]})}),e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"text-center mb-2",children:[e.jsxs("h3",{className:"text-base font-bold text-gray-900 dark:text-gray-100 mb-0.5 truncate",children:["@",t.handle]}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-xs truncate",children:t.display_name})]}),e.jsx("div",{className:"bg-gray-50 dark:bg-neutral-800/50 rounded-2xl py-2 px-2 mb-2 shadow-sm",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-400 font-medium",children:l("labels.followers")}),e.jsx("span",{className:"font-bold text-gray-900 dark:text-gray-100",children:at(t.follower_count||0)})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-400 font-medium",children:t.platform==="instagram"?l("labels.reels"):l("labels.videos")}),e.jsx("span",{className:"font-bold text-gray-900 dark:text-gray-100",children:at(t.video_count||0)})]}),t.platform==="instagram"?e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-400 font-medium",children:l("labels.following")}),e.jsx("span",{className:"font-bold text-gray-900 dark:text-gray-100",children:at(t.following_count||0)})]}):e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-400 font-medium",children:l("labels.likes")}),e.jsx("span",{className:"font-bold text-gray-900 dark:text-gray-100",children:at(t.likes_count||0)})]})]})}),e.jsx("div",{className:"space-y-1",children:a?e.jsxs("div",{className:"w-full py-1.5 bg-blue-50 dark:bg-blue-950/40 text-blue-700 rounded-2xl text-xs font-bold flex items-center justify-center gap-2 border border-blue-200 dark:border-blue-900",children:[e.jsx(ce,{className:"w-3.5 h-3.5"}),l("profileCardSidebar.teamAccess")]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsxs("button",{onClick:()=>i(!1),disabled:n,className:"flex-1 py-1.5 bg-gray-100 dark:bg-neutral-800 hover:bg-gray-200 dark:hover:bg-neutral-700 text-gray-900 dark:text-gray-100 rounded-l-2xl text-xs font-bold transition-all flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(We,{className:`w-3.5 h-3.5 ${n?"animate-spin":""}`}),n?l("profileCardSidebar.loading"):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden 2xl:inline",children:l("labels.sync")}),e.jsx("span",{className:"2xl:hidden",children:l("profileCardSidebar.syncShort")})]})]}),e.jsxs(ra,{children:[e.jsx(la,{asChild:!0,disabled:n,children:e.jsx("button",{className:"py-1.5 px-1.5 bg-gray-100 dark:bg-neutral-800 hover:bg-gray-200 dark:hover:bg-neutral-700 text-gray-900 dark:text-gray-100 rounded-r-2xl text-xs transition-all disabled:opacity-50 border-l border-gray-200 dark:border-neutral-800",children:e.jsx(Ye,{className:"w-3.5 h-3.5"})})}),e.jsxs(na,{align:"end",className:"bg-white dark:bg-neutral-900 z-50",children:[e.jsx(ot,{onClick:()=>i(!1),children:l("labels.last40Videos")}),e.jsx(ot,{onClick:()=>i(!0),children:l("profileCardSidebar.allVideosSync")})]})]})]}),t.profile_deep_link&&e.jsxs("a",{href:t.profile_deep_link,target:"_blank",rel:"noopener noreferrer",className:"block w-full py-1.5 bg-gray-900 dark:bg-neutral-100 dar
21k:text-neutral-900 hover:bg-black dark:hover:bg-neutral-200 text-white rounded-2xl text-xs font-bold transition-all text-center shadow-lg flex items-center justify-center gap-2",children:[e.jsx(ps,{className:"w-3.5 h-3.5"}),l("labels.openProfile")]})]})})]})]}),e.jsx("div",{className:"mt-3",children:e.jsx(Na,{isTeamMember:a})})]}):e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-3xl shadow-lg p-6 text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-gray-100 dark:bg-neutral-800 rounded-2xl mx-auto mb-4 flex items-center justify-center",children:e.jsx(Ue,{className:"w-8 h-8 text-gray-400 dark:text-gray-500"})}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:l("profileCardSidebar.noAccount")}),e.jsx("button",{onClick:S,className:"px-4 py-2 bg-gray-900 dark:bg-neutral-100 dark:text-neutral-900 hover:bg-black dark:hover:bg-neutral-200 text-white rounded-xl text-sm font-semibold transition-all",children:l("labels.connectAccount")}),e.jsx(Tt,{open:b,onClose:()=>w(!1),onChooseTikTok:()=>{w(!1),M()},onChooseInstagram:()=>{w(!1),y(!0)}}),e.jsx(It,{open:k,onClose:()=>y(!1)})]})},at=t=>t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":t.toString(),Wt=t=>t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":t.toString(),Zt=({value:t,label:r})=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[15px] font-extrabold text-gray-900 dark:text-gray-100 leading-none tracking-[-0.01em]",children:t}),e.jsx("span",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-1",children:r})]}),Bs=({account:t,isLoading:r,syncing:n,onRefresh:i})=>{const{t:a}=Q("dashboard"),{accounts:l,igAccounts:M}=Ze(),[b,w]=s.useState(!1),[k,y]=s.useState(!1),[S,T]=s.useState(!1),I=async()=>{const v=await At();window.location.href=Mt(v)},R=()=>y(!0);return r?e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-2xl shadow-sm p-3.5 animate-pulse flex items-center gap-3.5",children:[e.jsx("div",{className:"w-14 h-14 bg-gray-200 dark:bg-neutral-800 rounded-2xl"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-neutral-800 rounded w-24 mb-2"}),e.jsx("div",{className:"h-3 bg-gray-200 dark:bg-neutral-800 rounded w-32"})]})]}):t?e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-[22px] shadow-sm p-3.5 flex items-center gap-3.5",children:[e.jsxs("div",{className:"relative flex-shrink-0 w-14 h-14",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl overflow-hidden bg-gradient-to-br from-gray-100 to-gray-200 dark:from-neutral-800 dark:to-neutral-700",children:t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:t.display_name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(Ue,{className:"w-7 h-7 text-gray-300 dark:text-gray-600"})})}),e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 ring-2 ring-white dark:ring-neutral-900 shadow rounded-md overflow-hidden",title:t.platform==="instagram"?"Instagram":"TikTok",children:e.jsx(ze,{platform:t.platform==="instagram"?"instagram":"tiktok",size:20})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h3",{className:"text-[15px] font-bold text-gray-900 dark:text-gray-100 truncate tracking-[-0.01em] leading-tight",children:["@",t.handle]}),e.jsx("p",{className:"text-[13px] text-gray-500 dark:text-gray-400 truncate leading-tight mt-0.5",children:t.display_name}),e.jsxs("div",{className:"flex items-center gap-[18px] mt-2",children:[e.jsx(Zt,{value:Wt(t.follower_count||0),label:a("labels.followers")}),e.jsx(Zt,{value:Wt(t.video_count||0),label:t.platform==="instagram"?a("labels.reels"):a("labels.videos")})]})]}),e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2",children:[e.jsxs(ra,{children:[e.jsx(la,{asChild:!0,disabled:n,children:e.jsx("button",{className:"w-11 h-11 rounded-[13px] bg-white dark:bg-neutral-900 border border-gray-200/80 dark:border-neutral-700 hover:bg-gray-50 dark:hover:bg-neutral-800 text-gray-900 dark:text-gray-100 transition-colors disabled:opacity-50 flex items-center justify-center",title:a(n?"mobileProfileBar.loadingTitle":"labels.sync"),children:e.jsx(We,{className:`w-[17px] h-[17px] ${n?"animate-spin":""}`})})}),e.jsxs(na,{align:"end",className:"bg-white dark:bg-neutral-900 z-50",children:[e.jsx(ot,{onClick:()=>i(!1),children:a("labels.last40Videos")}),e.jsx(ot,{onClick:()=>i(!0),children:a("labels.allVideos")})]})]}),t.profile_deep_link&&e.jsx("a",{href:t.profile_deep_link,target:"_blank",rel:"noopener noreferrer",className:"w-11 h-11 rounded-[13px] bg-[#15171C] hover:bg-[#22252b] text-white transition-colors flex items-center justify-center",title:a("labels.openProfile"),children:e.jsx(Ua,{className:"w-[17px] h-[17px]"})})]})]}),l.length+M.length>
210&&e.jsxs(ia,{open:b,onOpenChange:w,children:[e.jsxs(oa,{className:"w-full bg-white dark:bg-neutral-900 rounded-[18px] shadow-sm px-[18px] py-[14px] flex items-center justify-between",children:[e.jsx("span",{className:"text-[15px] font-bold text-gray-900 dark:text-gray-100 tracking-[-0.01em]",children:a("mobileProfileBar.switchAccount")}),e.jsx(Ye,{className:`w-4 h-4 text-gray-500 dark:text-gray-400 transition-transform duration-200 ${b?"rotate-180":""}`})]}),e.jsx(da,{className:"mt-2",children:e.jsx(Na,{isTeamMember:!1})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-2xl shadow-sm p-4 text-center",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-3",children:a("mobileProfileBar.noAccount")}),e.jsx("button",{onClick:R,className:"px-4 py-2 bg-gray-900 dark:bg-neutral-100 dark:text-neutral-900 hover:bg-black text-white rounded-xl text-sm font-semibold transition-all",children:a("labels.connectAccount")})]}),e.jsx(Tt,{open:k,onClose:()=>y(!1),onChooseTikTok:I,onChooseInstagram:()=>T(!0)}),e.jsx(It,{open:S,onClose:()=>T(!1)})]})},Gs="/assets/new-chat-icon-D4BLPYMc.png",Ks=(t,r)=>{const n=new Date(t),i=new Date,a=new Date(i);return a.setDate(a.getDate()-1),n.toDateString()===i.toDateString()?r("chatHistory.dateGroup.today"):n.toDateString()===a.toDateString()?r("chatHistory.dateGroup.yesterday"):n.toLocaleDateString("de-DE",{day:"numeric",month:"long",year:n.getFullYear()!==i.getFullYear()?"numeric":void 0})},_a=t=>new Date(t).toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"}),qs=(t,r=60)=>t.length<=r?t:t.substring(0,r).trim()+"...",Ws=({dateKey:t,conversations:r,onSelectConversation:n,defaultOpen:i=!0})=>{const{t:a}=Q("scripts"),[l,M]=s.useState(i);return e.jsxs(ia,{open:l,onOpenChange:M,children:[e.jsx(oa,{className:"w-full",children:e.jsxs("div",{className:"flex items-center justify-between px-1 py-2 hover:bg-muted rounded-lg transition-colors",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:t}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.length," ",a("chatHistory.conversationsLabel",{count:r.length})]}),e.jsx(Ye,{className:`w-4 h-4 text-muted-foreground transition-transform duration-200 ${l?"":"-rotate-90"}`})]})]})}),e.jsx(da,{children:e.jsx("div",{className:"space-y-2 mt-2",children:r.map(b=>e.jsx("button",{onClick:()=>n(b.conversation_id),className:"w-full text-left p-4 bg-gray-50 dark:bg-neutral-800/50 hover:bg-gray-100 dark:hover:bg-neutral-800 rounded-xl transition-all group",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-indigo-500 to-purple-500 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(be,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-gray-900 dark:text-gray-100 font-medium truncate",children:qs(b.first_message)}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(_s,{className:"w-3 h-3 text-gray-400 dark:text-gray-500"}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:_a(b.created_at)}),e.jsx("span",{className:"text-xs text-gray-300",children:"â¢"}),e.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:[b.message_count," ",a("chatHistory.messagesLabel",{count:b.message_count})]})]})]}),e.jsx(sa,{className:"w-4 h-4 text-gray-300 rotate-180 group-hover:text-gray-500 transition-colors flex-shrink-0"})]})},b.id))})})]})},Zs=({isOpen:t,onClose:r,userId:n,tiktokAccountId:i,platform:a="tiktok"})=>{const{t:l}=Q("scripts"),[M,b]=s.useState([]),[w,k]=s.useState(!0),[y,S]=s.useState(null),[T,I]=s.useState([]),[R,v]=s.useState(!1);s.useEffect(()=>{t&&n&&u()},[t,n,i]);const u=async()=>{k(!0);try{const g=await ys(n,i,"general",a);b(g)}catch(g){console.error("Error loading conversations:",g)}finally{k(!1)}},d=async g=>{S(g),v(!0);try{const U=await js(n,g,i,"general",a);I(U)}catch(U){console.error("Error loading messages:",U)}finally{v(!1)}},f=()=>{S(null),I([])},j=()=>{S(null),I([]),r()},L=M.reduce((g,U)=>{const D=Ks(U.created_at,l);return g[D]||(g[D]=[]),g[D].push(U),g},{});return t?za.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center p-4",style:{isolation:"isolate"},children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:j,style:{pointerEvents:"auto"}}),e.jsxs("div",{className:"relative bg-white dark:bg-neutral-900 rounded-2xl shadow-2xl w-full max-w-lg max-h-[80vh] flex flex-col overflow-hidden",style:{pointerEvents:"auto"},children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-neutral-800",children:[y?e.jsxs("button",{onClick:f,className:"flex items-center gap-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 transition-colors",children:[e.jsx(sa,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium",children:l("chatHistory.back")})]}):e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-indigo-500 to-purple-500 rounded-xl flex items-center justify-center",children:e.jsx($t,{className:"w-5 h-5 text-white"})}),e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:l("chatHistory.title")})]}),e.jsx("button",{onClick:j,className:"p-2 hover:bg-gray-100 dark:hover:bg-neutral-800 rounded-lg transition-colors",children:e.jsx(de,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:y?e.jsx("div",{className:"p-4",children:R?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(fe,{className:"w-8 h-8 text-indigo-500 animate-spin"})}):T.length===0?e.jsx("div",{className:"text-center py-12 text-gray-500 dark:text-gray-400",children:l("chatHistory.noMessages")}):e.jsx("div",{className:"space-y-3",children:T.map(g=>e.jsx("div",{className:`flex ${g.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`flex flex-col ${g.role==="user"?"max-w-[75%]":"max-w-[85%]"}`,children:[e.jsx("div",{className:`${g.role==="user"?"bg-gradient-to-br from-indigo-500 to-purple-500 text-white":"bg-gray-100 dark:bg-neutral-800 text-gray-900 dark:text-gray-100"} rounded-2xl px-4 py-2`,children:e.jsx("div",{className:`prose prose-sm max-w-none ${g.role==="user"?"prose-invert":""}`,children:e.jsx(ba,{components:{p:({node:U,...D})=>e.jsx("p",{className:"mb-1 last:mb-0 leading-relaxed text-sm",...D}),strong:({node:U,...D})=>e.jsx("strong",{className:g.role==="user"?"font-semibold text-white":"font-semibold text-gray-900 dark:text-gray-100",...D}),ul:({node:U,...D})=>e.jsx("ul",{className:"list-disc ml-3 mb-1 space-y-0.5 text-sm",...D}),ol:({node:U,...D})=>e.jsx("ol",{className:"list-decimal ml-3 mb-1 space-y-0.5 text-sm",...D}),li:({node:U,...D})=>e.jsx("li",{className:"text-sm",...D})},children:g.message.startsWith("[SETUP_REQUIRED:")?g.message.includes("no_account")?l("chatHistory.setupHint.noAccount"):l("chatHistory.setupHint.noVideo"):g.message})})}),e.jsx("div",{className:`text-[10px] text-gray-400 dark:text-gray-500 mt-0.5 px-1 ${g.role==="user"?"text-right":"text-left"}`,children:_a(g.created_at)})]})},g.id))})}):e.jsx("div",{className:"p-4",children:w?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(fe,{className:"w-8 h-8 text-indigo-500 animate-spin"})}):M.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx($t,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:l("chatHistory.empty")})]}):e.jsx("div",{className:"space-y-3",children:Object.keys(L).map((g,U)=>e.jsx(Ws,{dateKey:g,conversations:L[g],onSelectConversation:d,defaultOpen:U===0},g))})})}),!y&&M.length>0&&e.jsx("div",{className:"px-6 py-3 bg-gray-50 dark:bg-neutral-800/50 border-t border-gray-100 dark:border-neutral-800",children:e.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 text-center",children:"Klicke auf eine Konversation um sie anzusehen (nur Vorschau)"})})]})]}),document.body):null},Yt=t=>`dashboard-chat:${t}`,Ys=Ds().trim().min(1,"Nachricht darf nicht leer sein").max(4e3,"Nachricht darf maximal 4000 Zeichen lang sein"),Qs=(t,r)=>{const n=new Date,i=new Date(n);return i.setDate(i.getDate()-1),t.toDateString()===n.toDateString()?r("chatInterface.dateSeparator.today"):t.toDateString()===i.toDateString()?r("chatInterface.dateSeparator.yesterday"):t.toLocaleDateString("de-DE",{month:"short",day:"numeric",year:"numeric"})},Js=t=>
21t.startsWith("[SETUP_REQUIRED:")?t.includes("no_account")?"no_account":"no_analyzed_videos":null,Xs=({reason:t,onCta:r})=>{const{t:n}=Q("scripts"),i=t==="no_account";return e.jsxs("div",{className:"bg-white dark:bg-neutral-900 border border-gray-200 dark:border-neutral-700 rounded-2xl p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-purple-50 dark:bg-purple-950/40 flex items-center justify-center flex-shrink-0",children:i?e.jsx(Fs,{className:"w-4 h-4 text-purple-600"}):e.jsx(Ra,{className:"w-5 h-5 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:n(i?"chatInterface.setupCard.account.title":"chatInterface.setupCard.video.title")}),e.jsx("p",{className:"text-[12.5px] text-gray-500 dark:text-gray-400 leading-snug mt-0.5",children:n(i?"chatInterface.setupCard.account.desc":"chatInterface.setupCard.video.desc")})]})]}),e.jsx("button",{onClick:r,className:"mt-3 w-full px-3 py-2 bg-purple-600 hover:bg-purple-700 text-white text-[13px] font-medium rounded-xl transition-colors",children:n(i?"chatInterface.setupCard.account.cta":"chatInterface.setupCard.video.cta")})]})},Sa=({onClose:t,onExpandedChange:r}={})=>{const{t:n}=Q("scripts"),{user:i,account:a,loading:l}=Ze(),{startChat:M,getPendingChat:b,subscribeToChat:w,consumePendingChat:k}=La(),[y,S]=s.useState([]),[T,I]=s.useState(""),[R,v]=s.useState(!1),[u,d]=s.useState(null),[f,j]=s.useState(null),[L,g]=s.useState(!0),[U,D]=s.useState(!1),[F,B]=s.useState(!1),[H,O]=s.useState(null),[ue,K]=s.useState(!1),[C,J]=s.useState(!1),[q,ee]=s.useState(!1);s.useEffect(()=>{if(!q)return;const c=m=>{m.key==="Escape"&&ee(!1)};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[q]),s.useEffect(()=>{r==null||r(q)},[q,r]);const xe=Nt(),ne=c=>{ee(!1),t&&t(),c==="no_account"?xe("/settings?tab=accounts"):setTimeout(()=>{var m;(m=document.getElementById("video-list"))==null||m.scrollIntoView({behavior:"smooth",block:"start"})},t?300:50)},[p,W]=s.useState(null),[ge,pe]=s.useState(!1),[Me,$]=s.useState(!1),[V,ie]=s.useState("free"),[Te,ke]=s.useState(()=>localStorage.getItem("chat-info-badge-dismissed")==="true"),mt=s.useRef(null),he=s.useRef(null),Fe=s.useRef(null),Ie=s.useRef(!1),ve=s.useRef(!1),je=s.useRef(null);s.useRef(null);const oe=s.useRef(null),Ne=s.useRef(!1),me=s.useRef(null),Le=s.useRef(new Set);s.useEffect(()=>{je.current&&(je.current.style.height="auto",je.current.style.height=Math.min(je.current.scrollHeight,120)+"px")},[T]);const te=async()=>{if(!i)return;const{data:c}=await Z.from("users").select("subscription_tier").eq("id",i.id).single(),m=(c==null?void 0:c.subscription_tier)||"free";ie(m);const _=await it(i.id,"chat_message",m);$(!_.allowed)};s.useEffect(()=>{te()},[i]),s.useEffect(()=>{if(!i){g(!1);return}const c=(a==null?void 0:a.id)||null,m=me.current===null&&y.length===0,_=c!==null&&c!==me.current,N=m||_;N&&c!==null?(_&&me.current!==null&&(S([]),O(null),D(!1),ve.current=!1),me.current=c,X()):N&&c===null&&!l?(O(tt()),S([]),D(!1),g(!1)):N||g(!1)},[i,a==null?void 0:a.id,l]),s.useEffect(()=>{const c=m=>{window.innerWidth>=1024&&I(m.detail.message)};return window.addEventListener("openChatWithMessage",c),()=>window.removeEventListener("openChatWithMessage",c)},[]),s.useEffect(()=>{const c=m=>{I(m.detail.message)};return window.addEventListener("setChatInput",c),()=>window.removeEventListener("setChatInput",c)},[]),s.useEffect(()=>{!L&&y.length>0&&!ve.current&&(ve.current=!0,he.current&&(he.current.scrollTop=he.current.scrollHeight))},[L,y.length]),s.useEffect(()=>{Ie.current&&(Je(),Ie.current=!1)},[y]),s.useEffect(()=>{if(!i||L||!H||y.length===0)return;const c=_=>!!_&&/^\d+$/.test(_),m=y.filter(_=>!c(_.id));m.length!==0&&Bt(i.id,a==null?void 0:a.id,H,m)},[y,H,i==null?void 0:i.id,a==null?void 0:a.id,L]),s.useEffect(()=>{if(!i||!H)return;const c=Z.channel(`chat-sync-${H}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"chat_history",filter:`conversation_id=eq.${H}`},m=>{const _=m.new;if(!_||_.user_id!==i.id)return;const N={id:_.id,role:_.role,message:_.message,created_at:_.created_at,conversation_id:_.conversation_id};S(E=>{if(Le.current.has(_.message)){Le.current.delete(_.message);const Y=o=>!!o&&/^\d+$/.test(o),re=E.findIndex(o=>o.role===_.role&&o.message===_.message&&Y(o.id));if(re===-1)return E;const le=[...E];return le[re]={...le[re],id:_.id,created_at:_.created_at},le}return E.some(Y=>Y.id===_.id)?E:(Ie.current=!0,D(!0),[...E,N])})}).subscribe();return()=>{Z.removeChannel(c)}},[i==null?void 0:i.id,H]);const Je=()=>{he.current&&he.current.scrollTo({top:he.current.scrollHeight,behavior:"smooth"})},X=async()=>
21{if(Ne.current){console.log("[ChatInterface] Already loading history, skipping...");return}Ne.current=!0,ve.current=!1;let c=null;if(i)try{c=sessionStorage.getItem(`chat-new-pending:${i.id}:${(a==null?void 0:a.id)||"none"}`)}catch{}if(c){O(c),S([]),D(!1),g(!1),Ne.current=!1;return}let m=!1;if(i){const N=ws(i.id,a==null?void 0:a.id);N&&N.messages.length>0?(m=!0,N.conversationId&&O(N.conversationId),S(N.messages),D(!0),g(!1)):g(!0)}else g(!0);const _=window.setTimeout(()=>{console.warn("[ChatInterface] loadHistory timeout reached (10s)"),Ne.current=!1,g(!1)},1e4);try{if(!i){console.log("[ChatInterface] No user, skipping history load");return}const N=(a==null?void 0:a.platform)==="instagram"?"instagram":"tiktok",{conversationId:E,messages:ae}=await ks(i.id,a==null?void 0:a.id,50,"general",N);if(E){O(E);const Y=ae.map(le=>({...le,role:le.role,conversation_id:le.conversation_id||void 0})),re=le=>!!le&&/^\d+$/.test(le);S(le=>{const o=new Set(Y.map(h=>h.id)),x=le.filter(h=>re(h.id)&&!o.has(h.id));return x.length===0?Y:[...Y,...x]}),Y.length>0&&D(!0),Bt(i.id,a==null?void 0:a.id,E,ae)}else if(!m){const Y=tt();O(Y),S([]),D(!1)}}catch(N){console.error("[ChatInterface] Error loading history:",N)}finally{window.clearTimeout(_),Ne.current=!1,g(!1)}},$e=(c,m)=>{const _={id:(Date.now()+1).toString(),role:"assistant",message:c,created_at:new Date().toISOString(),conversation_id:m};Le.current.add(c),S(N=>{const E=N[N.length-1];return E&&E.role==="assistant"&&E.message===c?N:[...N,_]}),Ie.current=!0},He=async()=>{if(R)return;if(!T.trim()&&!p){P.error(n("chatInterface.toast.emptyMessage"));return}if(T.trim()){const x=Ys.safeParse(T);if(!x.success){P.error(x.error.issues[0].message);return}}const c=T.trim()||((p==null?void 0:p.type)==="image"?"Analysiere dieses Bild":"Analysiere dieses Dokument"),m=p;try{i!=null&&i.id&&sessionStorage.removeItem(`chat-new-pending:${i.id}:${(a==null?void 0:a.id)||"none"}`)}catch{}I(""),p!=null&&p.preview&&URL.revokeObjectURL(p.preview),W(null),oe.current&&(oe.current.value=""),v(!0),j(null),d(n("chatInterface.thinking.analyzing"));const _=setTimeout(()=>d(n("chatInterface.thinking.loadingData")),2e3),N=setTimeout(()=>d(n("chatInterface.thinking.creatingAnswer")),5e3),E=y,ae=(a==null?void 0:a.platform)==="instagram"?"instagram":"tiktok",Y=ae==="tiktok"?a==null?void 0:a.id:void 0;ae==="instagram"&&(a==null||a.id);const re=m?`ð ${m.name} 22${c}`:c;let le=c;(m==null?void 0:m.type)==="pdf"&&(le=`${c} 23 24--- ANGEHÃNGTES DOKUMENT: ${m.name} --- 25${m.data} 26--- ENDE DOKUMENT ---`);const o=(m==null?void 0:m.type)==="image"?m.data:void 0;try{if(!i)throw new Error("Not authenticated");let x=H;x||(x=tt(),O(x));const{data:h}=await Z.from("users").select("subscription_tier").eq("id",i.id).single(),A=(h==null?void 0:h.subscription_tier)||"free",G=await it(i.id,"chat_message",A);if(!G.allowed){P.error(n("chatInterface.toast.limitReached",{current:G.current,limit:G.limit})),clearTimeout(_),clearTimeout(N),d(null),v(!1);return}const z={id:Date.now().toString(),role:"user",message:re,created_at:new Date().toISOString(),conversation_id:x};Le.current.add(re),S(_e=>[..._e,z]),Ie.current=!0,D(!0);const se=Yt(x);M(se,"dashboard-chat",async()=>({reply:await vs(le,E,x,Y,o,void 0,a==null?void 0:a.id,ae),userMessage:re,imageMarker:!!m,conversationId:x}),{title:"Hookzy Chat",conversationId:x,tiktokAccountId:Y})}catch(x){console.error("Chat error:",x);const h=x.message||n("chatInterface.toast.sendError");j(h),P.error(h),I(c),clearTimeout(_),clearTimeout(N),d(null),v(!1)}};s.useEffect(()=>{if(!H)return;const c=Yt(H),m=b(c);m&&(m.status==="pending"?(v(!0),D(!0)):m.status==="done"&&m.result?($e(m.result.reply,m.result.conversationId),v(!1),d(null),te(),k(c)):m.status==="error"&&(j(m.error||n("chatInterface.toast.sendError")),v(!1),d(null),k(c)));const _=w(c,N=>{if(N)if(N.status==="pending")v(!0);else if(N.status==="done"&&N.result){const E=N.result;$e(E.reply,E.conversationId),v(!1),d(null),te(),k(c)}else N.status==="error"&&(j(N.error||n("chatInterface.toast.sendError")),v(!1),d(null),k(c))});return()=>{_()}},[H]);const Oe=()=>{var c;(c=oe.current)==null||c.click()},Ve=async c=>{var N;const m=(N=c.target.files)==null?void 0:N[0];if(!m)return;const _=Fa(m);if(_){P.error(_),oe.current&&(oe.current.value="");return}pe(!0);try{const E=$a(m);if(E==="pdf"){const ae=await Ha(m);if(!ae.trim()){P.error(n("chatInterface.toast.pdfNoText"));return}W({name:m.name,type:"pdf",data:ae})}else if(E==="image"){const ae=await Oa(m),Y=URL.createObjectURL(m);W({name:m.name,type:"image",data:ae,preview:Y})}}catch(E){console.error("Attachment error:",E),P.error(n("chatInterface.toast.fileLoadError"))}finally{pe(!1),oe.current&&(oe.current.value="")}},Be=()=>{p!=null&&p.preview&&URL.revokeObjectURL(p.preview),W(null),oe.current&&(oe.current.value="")},Ge=()=>{const c=tt();O(c),S([]),D(!1),ke(!1),localStorage.removeItem("chat-info-badge-dismissed");try{i!=null&&i.id&&(localStorage.removeItem(`chat-recent:${i.id}:${(a==null?void 0:a.id)||"none"}`),sessionStorage.setItem(`chat-new-pending:${i.id}:${(a==null?void 0:a.id)||"none"}`,c))}catch{}P.success(n("chatInterface.toast.newChatStarted"))},Xe=async()=>{const c=window.SpeechRecognition||window.webkitSpeechRecognition;if(!c){P.error(n("chatInterface.toast.speechNotSupported"));return}try{const m=new c;Fe.current=m,m.lang="de-DE",m.continuous=!0,m.interimResults=!0,m.onresult=_=>{let N="";for(let E=0;E<_.results.length;E++)N+=_.results[E][0].transcript;I(N)},m.onerror=_=>{console.error("Speech recognition error:",_.error),_.error==="not-allowed"?P.error(n("chatInterface.toast.micDenied")):_.error==="no-speech"?P.error(n("chatInterface.toast.noSpeech")):P.error(n("chatInterface.toast.speechError")),B(!1)},m.onend=()=>{B(!1)},m.start(),B(!0),P.success(n("chatInterface.toast.speechActive"))}catch(m){console.error("Speech recognition start error:",m),P.error(n("chatInterface.toast.speechStartError"))}},ut=()=>{Fe.current&&F&&(Fe.current.stop(),B(!1),P.success(n("chatInterface.toast.speechStopped")))},gt=n("chatInterface.exampleQuestions",{returnObjects:!0}),pt=c=>{I(c),D(!0)},ht=s.useMemo(()=>{const c=new Date;
26return new Date(c.getFullYear(),c.getMonth()+1,1).toLocaleDateString("de-DE",{day:"numeric",month:"long",year:"numeric"})},[]),Pe=()=>e.jsx("div",{className:"px-4 py-4 bg-white dark:bg-neutral-900 border-t border-gray-200 dark:border-neutral-800",children:e.jsxs("div",{className:"bg-gray-50 dark:bg-neutral-800/50 border border-gray-200 dark:border-neutral-800 rounded-2xl p-4 text-center space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-center gap-2 text-gray-700 dark:text-gray-300",children:[e.jsx(Cs,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-semibold",children:n("chatInterface.limitBanner.title")})]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[n("chatInterface.limitBanner.resetPrefix")," ",e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:ht})," ",n("chatInterface.limitBanner.resetSuffix")]}),V==="free"&&e.jsxs("button",{onClick:()=>window.location.href="/pricing",className:"mt-2 inline-flex items-center gap-1.5 px-4 py-2.5 bg-gradient-to-r from-gray-900 to-gray-700 hover:from-gray-800 hover:to-gray-600 text-white text-sm font-medium rounded-xl transition-all shadow-sm",children:[e.jsx(Ns,{className:"w-4 h-4"}),n("chatInterface.limitBanner.upgrade")]})]})});if(L)return e.jsxs("div",{className:`flex flex-col overflow-hidden font-sans relative ${t?"h-[100dvh] bg-white dark:bg-neutral-900":"bg-gray-50 dark:bg-neutral-800/50 rounded-3xl shadow-lg h-[calc(100dvh-14rem)] border border-gray-300 dark:border-neutral-700"}`,children:[e.jsxs("div",{className:"px-6 py-2 bg-white dark:bg-neutral-900 border-b border-gray-100 dark:border-neutral-800 flex items-center justify-between sticky top-0 z-10 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-orange-400 to-orange-500 rounded-2xl flex items-center justify-center shadow-lg flex-shrink-0",children:e.jsx(be,{className:"w-4 h-4 text-white"})}),e.jsx("div",{className:"h-4 w-44 rounded bg-gray-200 dark:bg-neutral-700 animate-pulse"})]}),t&&e.jsx("button",{onClick:t,className:"p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-neutral-800 transition-colors",title:n("chatInterface.closeChat"),children:e.jsx(de,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),e.jsx("div",{className:"flex-1 overflow-hidden px-4 pb-4 pt-4 bg-white dark:bg-neutral-900 space-y-3",children:[{side:"left",w:"w-3/4",h:"h-16"},{side:"right",w:"w-1/2",h:"h-10"},{side:"left",w:"w-2/3",h:"h-20"},{side:"right",w:"w-2/5",h:"h-8"},{side:"left",w:"w-4/5",h:"h-14"}].map((c,m)=>e.jsx("div",{className:`flex ${c.side==="right"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`${c.w} ${c.h} rounded-2xl animate-pulse ${c.side==="right"?"bg-gradient-to-br from-indigo-200 to-purple-200":"bg-gray-200 dark:bg-neutral-700"}`})},m))}),e.jsxs("div",{className:"px-3 py-2 bg-white dark:bg-neutral-900 border-t border-gray-200 dark:border-neutral-800 pb-[env(safe-area-inset-bottom)]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 bg-gray-100 dark:bg-neutral-800 rounded-full opacity-70",children:[e.jsx(Vt,{className:"w-4 h-4 text-gray-300"}),e.jsx("div",{className:"flex-1 h-5 rounded bg-gray-200 dark:bg-neutral-700 animate-pulse"}),e.jsx(yt,{className:"w-4 h-4 text-gray-300"}),e.jsx("div",{className:"p-1.5 rounded-full bg-gray-300",children:e.jsx(Gt,{className:"w-3.5 h-3.5 text-white"})})]}),e.jsx("div",{className:"w-full mt-1.5 h-3 flex items-center justify-center",children:e.jsx("div",{className:"h-2.5 w-24 rounded bg-gray-100 dark:bg-neutral-800 animate-pulse"})})]})]});const Ke=y.reduce((c,m)=>{const N=new Date(m.created_at).toDateString();return c[N]||(c[N]=[]),c[N].push(m),c},{});return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"file",ref:oe,onChange:Ve,accept:"image/*,.pdf,application/pdf",className:"hidden"}),e.jsx("div",{className:`fixed -inset-4 z-40 bg-black/40 backdrop-blur-sm transition-opacity duration-200 ${!t&&q?"opacity-100":"opacity-0 pointer-events-none"}`,onClick:()=>ee(!1),"aria-hidden":"true"}),e.jsx("div",{className:`flex flex-col overflow-hidden font-sans ${t?"relative h-[100dvh] bg-white dark:bg-neutral-900":q?"fixed z-50 left-1/2 -translate-x-1/2 top-[4dvh] bottom-[4dvh] w-[min(92vw,56rem)] bg-gray-50 dark:bg-neutral-800/50 rounded-3xl shadow-2xl border border-gray-300 dark:border-neutral-700":"relative bg-gray-50 dark:bg-neutral-800/50 rounded-3xl shadow-lg h-[calc(100dvh-14rem)] border border-gray-300 dark:border-neutral-700"}`,children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-3 bg-white dark:bg-neutral-900 border-b border-gray-100/80 dark:border-neutral-800 flex items-center justify-between sticky top-0 z-10 shrink-0 gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"w-9 h-9 bg-gradient-to-br from-orange-400 to-orange-600 rounded-xl flex items-center justify-center flex-shrink-0 shadow-[inset_0_1px_0_rgba(255,255,255,0.4)]",children:e.jsx(be,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"min-w-0 leading-tight",children:[e.jsx("div",{className:"text-[10px] tracking-[0.14em] uppercase font-mono text-gray-400 dark:text-gray-500",children:"Hookzy Assistant"}),e.jsx("h3",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100 tracking-tight mt-0.5 leading-[1.25] break-words",children:n("chatInterface.headerTitle")})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[y.length>0&&e.jsx("button",{onClick:()=>
26J(!0),className:"w-8 h-8 rounded-[10px] bg-stone-100 dark:bg-neutral-800 hover:bg-stone-200 dark:hover:bg-neutral-700 text-gray-700 dark:text-gray-300 transition-colors inline-flex items-center justify-center",title:n("chatInterface.newChatTitle"),children:e.jsx("img",{src:Gs,alt:n("chatInterface.newChatAlt"),className:"w-5 h-5 object-contain"})}),!t&&e.jsx("button",{onClick:()=>ee(c=>!c),className:"p-1.5 rounded-full hover:bg-stone-100 dark:hover:bg-neutral-800 text-gray-500 dark:text-gray-400 transition-colors inline-flex items-center justify-center",title:n(q?"chatInterface.collapse":"chatInterface.expand"),children:q?e.jsx(xs,{className:"w-4 h-4"}):e.jsx(ms,{className:"w-4 h-4"})}),t&&e.jsx("button",{onClick:t,className:"p-1.5 rounded-full hover:bg-stone-100 dark:hover:bg-neutral-800 transition-colors",title:n("chatInterface.closeChat"),children:e.jsx(de,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]})]}),!Te&&e.jsx("div",{className:"px-4 pt-3 pb-0 bg-white dark:bg-neutral-900",children:e.jsxs("div",{className:"bg-sky-50/70 dark:bg-sky-950/30 border border-sky-100 dark:border-sky-900/60 rounded-xl px-3 py-2.5 flex items-start gap-2.5 text-[12.5px] leading-snug text-sky-800 dark:text-sky-300",children:[e.jsx(be,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5 text-sky-500"}),e.jsx("span",{className:"flex-1",children:n("chatInterface.infoBanner")}),e.jsx("button",{onClick:()=>{ke(!0),localStorage.setItem("chat-info-badge-dismissed","true")},className:"p-0.5 -m-0.5 hover:bg-sky-100 dark:hover:bg-sky-900/40 rounded transition-colors flex-shrink-0 text-sky-500","aria-label":n("chatInterface.dismissHint"),children:e.jsx(de,{className:"w-3.5 h-3.5"})})]})}),e.jsxs("div",{ref:he,className:"flex-1 overflow-y-auto overflow-x-hidden px-4 pb-4 bg-white dark:bg-neutral-900 relative",children:[y.length===0?e.jsx("div",{className:"flex flex-col items-center justify-center h-full py-12",children:e.jsx("div",{className:"w-full max-w-md
26space-y-2.5",children:gt.map((c,m)=>e.jsx("button",{onClick:()=>pt(c),className:"w-full text-left px-5 py-3.5 bg-gray-900 hover:bg-gray-800 dark:bg-neutral-800 dark:hover:bg-neutral-700 text-white rounded-xl text-sm font-medium transition-colors",children:c},m))})}):Object.keys(Ke).map(c=>e.jsxs("div",{children:[e.jsx("div",{className:"flex justify-center my-4",children:e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-medium",children:Qs(new Date(c),n)})}),e.jsx("div",{className:"space-y-3",children:Ke[c].map(m=>{const _=m.role==="assistant"?Js(m.message):null;return e.jsx("div",{className:`flex ${m.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`flex flex-col ${m.role==="user"?"max-w-[80%]":"max-w-[85%]"}`,children:[_?e.jsx(Xs,{reason:_,onCta:()=>ne(_)}):e.jsx("div",{className:`${m.role==="user"?"bg-gray-900 dark:bg-gray-100 text-white dark:text-gray-900 rounded-tl-2xl rounded-tr-2xl rounded-bl-2xl rounded-br-md":"bg-stone-100 dark:bg-neutral-800 text-gray-900 dark:text-gray-100 rounded-tl-md rounded-tr-2xl rounded-br-2xl rounded-bl-2xl"} px-3.5 py-2.5 break-words overflow-hidden text-[13.5px] leading-[1.5]`,children:m.role==="user"?e.jsx("div",{className:"text-sm",children:e.jsx(us,{content:m.message,variant:"purple"})}):e.jsx("div",{className:"prose prose-sm max-w-none",children:e.jsx(ba,{components:{p:({node:N,...E})=>e.jsx("p",{className:"mb-1 last:mb-0 leading-relaxed text-sm",...E}),strong:({node:N,...E})=>e.jsx("strong",{className:"font-semibold text-gray-900 dark:text-gray-100",...E}),ul:({node:N,...E})=>e.jsx("ul",{className:"list-disc ml-3 mb-1 space-y-0.5 text-sm",...E}),ol:({node:N,...E})=>e.jsx("ol",{className:"list-decimal ml-3 mb-1 space-y-0.5 text-sm",...E}),li:({node:N,...E})=>e.jsx("li",{className:"text-sm",...E}),code:({node:N,inline:E,className:ae,children:Y,...re})=>E?e.jsx("code",{className:"px-1 py-0.5 rounded text-xs bg-gray-300 text-gray-900 dark:text-gray-100",...re,children:Y}):e.jsx("code",{className:"block p-2 rounded-lg mb-1 text-xs bg-gray-300 text-gray-900 dark:text-gray-100",...re,children:Y})},children:m.message})})}),m.role==="assistant"?e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 px-1",children:[e.jsx("div",{className:"w-5 h-5 rounded-md bg-gradient-to-br from-orange-400 to-orange-600 flex items-center justify-center flex-shrink-0 shadow-[inset_0_1px_0_rgba(255,255,255,0.4)]",children:e.jsx(be,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:"text-[10px] font-mono tracking-wider text-gray-400 dark:text-gray-500 tabular-nums",children:new Date(m.created_at).toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"Europe/Berlin"})})]}):e.jsx("div",{className:"text-[10px] font-mono tracking-wider text-gray-400 dark:text-gray-500 mt-1 px-1 text-right tabular-nums",children:new Date(m.created_at).toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"Europe/Berlin"})})]})},m.id)})})]},c)),R&&e.jsxs("div",{className:"flex flex-col mt-3 max-w-[85%]",children:[e.jsxs("div",{className:"bg-stone-100 dark:bg-neutral-800 rounded-tl-md rounded-tr-2xl rounded-br-2xl rounded-bl-2xl px-4 py-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"0ms",animationDuration:"1s"}}),e.jsx("div",{className:"w-1.5 h-1.5 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"300ms",animationDuration:"1s"}}),e.jsx("div",{className:"w-1.5 h-1.5 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"600ms",animationDuration:"1s"}})]}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-normal transition-all duration-300",children:u||n("chatInterface.thinking.default")})]}),e.jsx("div",{className:"flex items-center gap-2 mt-1.5 px-1",children:e.jsx("div",{className:"w-5 h-5 rounded-md bg-gradient-to-br from-orange-400 to-orange-600 flex items-center justify-center flex-shrink-0 shadow-[inset_0_1px_0_rgba(255,255,255,0.4)]",children:e.jsx(be,{className:"w-3 h-3 text-white"})})})]}),f&&!R&&e.jsx("div",{className:"flex flex-col mt-3 max-w-[85%]",children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-950/40 border border-red-200 dark:border-red-900 rounded-2xl px-4 py-3",children:[e.jsx("p",{className:"text-xs text-red-600 mb-2",children:f}),e.jsx("button",{onClick:()=>{j(null),He()},className:"text-xs font-medium text-red-700 bg-red-100 dark:bg-red-900/40 hover:bg-red-200 px-3 py-1.5 rounded-full transition-colors",children:n("chatInterface.retry")})]})}),e.jsx("div",{ref:mt})]}),Me?e.jsx(Pe,{}):e.jsxs("div",{className:"px-3 pt-2 pb-3 bg-white dark:bg-neutral-900 border-t border-gray-200 dark:border-neutral-800 relative overflow-hidden pb-[max(0.75rem,env(safe-area-inset-bottom))]",children:[F&&e.jsx("div",{className:"absolute inset-0 bg-white dark:bg-neutral-900 flex items-center justify-center z-20",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("button",{onClick:ut,className:"p-3 bg-red-500 text-white rounded-full hover:bg-red-600 transition-all shadow-md animate-pulse",children:e.jsx(yt,{className:"w-5 h-5"})}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 font-medium",children:n("chatInterface.listening")})]})}),e.jsxs("div",{className:"transition-all duration-300",style:{opacity:F?0:1,filter:F?"blur(4px)":"blur(0px)"},children:[p&&e.jsx("div",{className:"mb-2",children:p.type==="image"&&p.preview?e.jsxs("div",{className:"relative inline-block",children:[e.jsx("img",{src:p.preview,alt:n("chatInterface.attachedImageAlt"),className:"max-h-20 rounded-lg border border-gray-200 dark:border-neutral-800"}),e.jsx("button",{onClick:Be,className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-red-500 text-white rounded-full flex items-center justify-center hover:bg-red-600 transition-colors",children:e.jsx(de,{className:"w-3 h-3"})})]}):e.jsxs("div",{className:"flex items-center gap-2 bg-purple-50 dark:bg-purple-950/40 border border-purple-200 dark:border-purple-900 rounded-lg px-2.5 py-1.5 w-fit",children:[p.type==="pdf"?e.jsx(Pa,{className:"w-3.5 h-3.5 text-purple-600"}):e.jsx(gs,{className:"w-3.5 h-3.5 text-purple-600"}),e.jsx("span",{className:"text-xs text-purple-700 font-medium max-w-[160px] truncate",children:p.name}),e.jsx("button",{onClick:Be,className:"text-purple-400 hover:text-purple-600 transition-colors",children:e.jsx(de,{className:"w-3.5 h-3.5"})})]})}),e.jsxs("div",{className:"flex items-center gap-1.5 pl-3.5 pr-1.5 py-1.5 bg-stone-50 dark:bg-neutral-800 border border-stone-200/80 dark:border-neutral-700 rounded-full",children:[e.jsx("button",{onClick:Oe,disabled:ge,className:"p-1 rounded-full text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 transition-colors flex-shrink-0 disabled:opacity-50","aria-label":n("chatInterface.attachFile"),children:ge?e.jsx(fe,{className:"w-4 h-4 animate-spin"}):e.jsx(Vt,{className:"w-4 h-4"})}),e.jsx("textarea",{ref:je,value:T,onChange:c=>{I(c.target.value),c.target.style.height="auto",c.target.style.height=Math.min(c.target.scrollHeight,80)+"px"},onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),He())},placeholder:n("chatInterface.placeholder"),rows:1,className:"flex-1 min-w-0 bg-transparent text-[14px] text-gray-900 dark:text-gray-100 placeholder:text-gray-400 dark:placeholder:text-gray-500 outline-none resize-none overflow-y-auto border-none focus:ring-0 focus:outline-none break-words py-1.5",style:{maxHeight:"80px",minHeight:"22px",lineHeight:"1.45"},disabled:R||F}),e.jsx("button",{onClick:Xe,className:"p-1 rounded-full text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 transition-colors flex-shrink-0","aria-label":n("chatInterface.voiceRecord"),children:e.jsx(yt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:He,disabled:!T.trim()&&!p||R,className:"w-8 h-8 rounded-full bg-gray-900 dark:bg-gray-100 hover:bg-gray-800 dark:hover:bg-white disabled:bg-gray-300 disabled:dark:bg-neutral-700 disabled:cursor-not-allowed text-white dark:text-gray-900 transition-colors flex-shrink-0 inline-flex items-center justify-center","aria-label":n("chatInterface.sendAri
26a"),children:R?e.jsx(fe,{className:"w-4 h-4 animate-spin"}):e.jsx(Gt,{className:"w-3.5 h-3.5"})})]}),e.jsxs("button",{onClick:()=>K(!0),className:"w-full mt-3 text-[10.5px] font-mono tracking-[0.14em] uppercase text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 transition-colors flex items-center justify-center gap-1.5",children:[e.jsx(dt,{className:"w-3 h-3"}),e.jsx("span",{children:n("chatInterface.historyLink")})]})]})]}),e.jsx("style",{children:` 27 @keyframes slideInFromBottom { 28 from { 29 opacity: 0; 30 transform: translateY(40px); 31 } 32 to { 33 opacity: 1; 34 transform: translateY(0); 35 } 36 } 37 38 @keyframes scaleIn { 39 from { 40 opacity: 0; 41 transform: scale(0.8); 42 } 43 to { 44 opacity: 1; 45 transform: scale(1); 46 } 47 } 48 49 @keyframes fadeIn { 50 from { 51 opacity: 0; 52 } 53 to { 54 opacity: 1; 55 } 56 } 57 `})]})}),i&&e.jsx(Zs,{isOpen:ue,onClose:()=>K(!1),userId:i.id,tiktokAccountId:a==null?void 0:a.id,platform:(a==null?void 0:a.platform)==="instagram"?"instagram":"tiktok"}),e.jsx(ca,{open:C,onOpenChange:J,children:e.jsxs(xa,{className:"bg-white dark:bg-neutral-900 border-gray-200 dark:border-neutral-800",children:[e.jsxs(ma,{children:[e.jsx(ua,{className:"text-gray-900 dark:text-gray-100",children:n("chatInterface.newChatDialog.title")}),e.jsx(ga,{className:"text-gray-500 dark:text-gray-400",children:n("chatInterface.newChatDialog.description")})]}),e.jsxs(pa,{children:[e.jsx(ha,{className:"bg-white dark:bg-neutral-900 text-gray-900 dark:text-gray-100 border-gray-300 dark:border-neutral-700 hover:bg-gray-50 dark:hover:bg-neutral-800/50",children:n("chatInterface.newChatDialog.cancel")}),e.jsx(fa,{onClick:()=>{Ge(),J(!1)},className:"bg-gray-900 dark:bg-neutral-100 dark:text-neutral-900 text-white hover:bg-gray-800 dark:hover:bg-neutral-200",children:n("chatInterface.newChatDialog.confirm")})]})]})})]})},er=Ts,tr=Is,ar=Ms,Ca=s.forwardRef(({className:t,...r},n)=>e.jsx(ya,{className:ye("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...r,ref:n}));Ca.displayName=ya.displayName;const sr=Va("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Da=s.forwardRef(({side:t="right",className:r,children:n,hideClose:i,...a},l)=>e.jsxs(ar,{children:[e.jsx(Ca,{}),e.jsxs(ja,{ref:l,className:ye(sr({side:t}),r),...a,children:[n,!i&&e.jsxs(As,{className:"absolute right-4 top-4 roun
57ded-sm opacity-70 ring-offset-background transition-opacity data-[state=open]:bg-secondary hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none text-gray-900",children:[e.jsx(de,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Da.displayName=ja.displayName;const Aa=({className:t,...r})=>e.jsx("div",{className:ye("flex flex-col space-y-2 text-center sm:text-left",t),...r});Aa.displayName="SheetHeader";const Ma=s.forwardRef(({className:t,...r},n)=>e.jsx(wa,{ref:n,className:ye("text-lg font-semibold text-foreground",t),...r}));Ma.displayName=wa.displayName;const rr=s.forwardRef(({className:t,...r},n)=>e.jsx(ka,{ref:n,className:ye("text-sm text-muted-foreground",t),...r}));rr.displayName=ka.displayName;const lr=4e3,nr=({userTier:t="free"})=>{const{t:r}=Q("dashboard"),n=r("chatSidebar.samplePrompts",{returnObjects:!0}),[i,a]=s.useState(!1),[l,M]=s.useState(null),[b,w]=s.useState(0),k=t!=="ultra";return s.useEffect(()=>{if(i)return;const y=setInterval(()=>{w(S=>(S+1)%n.length)},lr);return()=>clearInterval(y)},[i]),s.useEffect(()=>{const y=new CustomEvent("mobileChatToggle",{detail:{open:i}});window.dispatchEvent(y)},[i]),s.useEffect(()=>{const y=S=>{M(S.detail.message),a(!0)};return window.addEventListener("openChatWithMessage",y),()=>window.removeEventListener("openChatWithMessage",y)},[]),s.useEffect(()=>{i&&l&&setTimeout(()=>{const y=new CustomEvent("setChatInput",{detail:{message:l}});window.dispatchEvent(y),M(null)},200)},[i,l]),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(er,{open:i,onOpenChange:a,children:[e.jsx(tr,{asChild:!0,children:e.jsxs("button",{type:"button",className:"relative w-full overflow-hidden rounded-[22px] p-[18px] text-left text-white transition-transform active:scale-[0.99]",style:{background:"radial-gradient(120% 100% at 0% 0%, #9F62FF 0%, #7C3AED 50%, #5B1FCF 100%)",boxShadow:"0 10px 28px -10px rgba(124,58,237,0.55), inset 0 1px 0 rgba(255,255,255,0.18)"},"aria-label":r("chatSidebar.openChat"),children:[e.jsx("div",{className:"absolute -right-3 -top-3 opacity-[0.22] pointer-events-none",children:e.jsx(qe,{className:"w-24 h-24 text-white",strokeWidth:1.5})}),e.jsxs("div",{className:"flex items-center gap-3 relative",children:[e.jsx("div",{className:"w-11 h-11 rounded-[14px] bg-white/[0.18] flex items-center justify-center flex-shrink-0",children:e.jsx(qe,{className:"w-[22px] h-[22px] text-white",strokeWidth:2.25})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[16px] font-bold tracking-[-0.01em] leading-tight",children:r("chatSidebar.askExpert")}),e.jsx("div",{className:"text-[12.5px] text-white/85 mt-[3px] leading-[1.35]",children:r("chatSidebar.expertSubtitle")})]})]}),e.jsxs("div",{className:"mt-3.5 flex items-center gap-2.5 rounded-xl bg-white/[0.16] border border-white/[0.22] px-3 py-2.5 min-h-[64px]",children:[e.jsx("span",{className:"flex-1 text-[13px] text-white/85 leading-snug line-clamp-2 animate-in fade-in duration-500",children:n[b]},b),e.jsx("span",{className:"shrink-0 w-7 h-7 rounded-[9px] bg-white flex items-center justify-center",children:e.jsx(nt,{className:"w-[14px] h-[14px] text-violet-600",strokeWidth:2.5})})]})]})}),e.jsxs(Da,{side:"bottom",hideClose:!0,className:"h-[100dvh] p-0 bg-white dark:bg-neutral-900 rounded-t-3xl overflow-hidden",children:[e.jsx(Aa,{className:"sr-only",children:e.jsx(Ma,{children:r("chatSidebar.expertTitle")})}),e.jsx("div",{className:"h-full overflow-hidden",children:i&&e.jsx(Sa,{onClose:()=>a(!1)})})]})]}),e.jsxs("div",{className:"w-full inline-flex items-center gap-3 rounded-full bg-[#15171C] pl-[13px] pr-[18px] py-[13px] text-white",children:[e.jsxs("button",{type:"button",onClick:()=>{k||window.dispatchEvent(new CustomEvent("openUploadDialog"))},disabled:k,className:`flex-1 inline-flex items-center gap-3 text-left ${k?"opacity-55 cursor-not-allowed":"active:scale-[0.99] transition-transform"}`,"aria-label":r("chatSidebar.openPreUpload"),children:[e.jsx("span",{className:"shrink-0 w-10 h-10 rounded-full bg-white/[0.12] flex items-center justify-center",children:e.jsx(xt,{className:"w-[18px] h-[18px] text-white",strokeWidth:2.25})}),e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block text-[15px] font-bold tracking-[-0.01em] leading-tight",children:r(k?"chatSidebar.ultraOnly":"chatSidebar.preUploadTitle")}),!k&&e.jsx("span",{className:"block text-[12px] text-white/70 mt-0.5 leading-tight",children:r("chatSidebar.preUploadSubtitle")})]}),e.jsx(nt,{className:"w-[18px] h-[18px] text-white shrink-0",strokeWidth:2})]}),e.jsxs(St,{children:[e.jsx(Ct,{asChild:!0,children:e.jsx("button",{type:"button",onClick:y=>y.stopPropagation(),className:"shrink-0 w-7 h-7 rounded-full text-white/55 hover:text-white hover:bg-white/[0.06] flex items-center justify-center transition-colors","aria-label":r("chatSidebar.preUploadInfoAria"),children:e.jsx(Xt,{className:"w-4 h-4"})})}),e.jsx(Dt,{side:"top",className:"max-w-[220px] text-center text-[11px] p-2.5 leading-snug",children:r("chatSidebar.preUploadInfo")})]})]}),e.jsx("div",{className:"flex justify-center pt-0.5",children:e.jsxs("button",{onClick:()=>window.dispatchEvent(new CustomEvent("openUploadHistory")),className:"inline-flex items-center gap-1.5 text-[14px] font-semibold text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white px-3 py-2 transition-colors",children:[e.jsx(dt,{className:"w-4 h-4"}),e.jsx("span",{children:r("chatSidebar.viewHistory")}),e.jsx(nt,{className:"w-[14px] h-[14px]",strokeWidth:2})]})})]})},Ta=({isOpen:t,onClose:r,video:n,userId:i})=>{const{t:a}=Q("videos"),l=Nt(),{startUltimateAnalysis:M}=Qe(),[b,w]=s.useState(null),[k,y]=s.useState(null),[S,T]=s.useState(null),[I,R]=s.useState(null),[v,u]=s.useState(!1),[d,f]=s.useState(""),[j,L]=s.useState(null),[g,U]=s.useState("free"),[D,F]=s.useState(!1),[B,H]=s.useState({current:0,limit:0});if(s.useEffect(()=>
57{i&&(async()=>{if(!i)return;const{data:C}=await Z.from("users").select("subscription_tier").eq("id",i).single(),J=(C==null?void 0:C.subscription_tier)||"free";U(J);const q=await it(i,"ultimate_analysis",J);H({current:q.current,limit:q.limit}),F(!q.allowed)})()},[i]),!t)return null;const O=g==="free",ue=async()=>{if(!b){P.error(a("ultimateAnalysisModal.errorKpiRequired")),L(a("ultimateAnalysisModal.errorKpiMissing"));return}u(!0),L(null);const K=await M(n,i,b,S,()=>{window.dispatchEvent(new CustomEvent("ultimate-analysis-complete",{detail:{videoId:n.id}}))});u(!1),K&&r()};return e.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-md flex items-start justify-center z-[9999] px-4 py-24 overflow-y-auto",onClick:()=>{console.log("[UltimateAnalysisModal] Backdrop click"),r()},children:e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-2xl shadow-2xl max-w-4xl w-full p-6 md:p-8 relative",onClick:K=>K.stopPropagation(),children:[O&&e.jsx("div",{className:"absolute inset-0 bg-gray-900/50 backdrop-blur-md rounded-2xl z-50 flex flex-col items-center justify-start pt-8 p-8 cursor-pointer animate-in fade-in duration-300",onClick:()=>l("/pricing"),children:e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-2xl p-8 max-w-md text-center shadow-2xl animate-in zoom-in-95 fade-in duration-300",onClick:K=>K.stopPropagation(),children:[e.jsxs("div",{className:"relative w-16 h-16 mx-auto mb-5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-purple-500 to-pink-500 rounded-full blur-xl opacity-50 animate-pulse"}),e.jsx("div",{className:"relative w-16 h-16 bg-gradient-to-br from-purple-500 to-pink-500 rounded-full flex items-center justify-center shadow-lg",children:e.jsx(Ht,{className:"w-8 h-8 text-white"})})]}),e.jsx("h3",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100 mb-2",children:a("ultimateAnalysisModal.unlockTitle")}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-5 leading-relaxed",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.unlockBody",components:{b:e.jsx("strong",{})}})}),e.jsxs("div",{className:"text-left space-y-2.5 mb-6 bg-gradient-to-br from-purple-50/60 to-pink-50/40 dark:from-purple-950/30 dark:to-pink-950/20 rounded-xl p-4 border border-purple-100 dark:border-purple-900/40",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"shrink-0 w-5 h-5 rounded-full bg-purple-100 dark:bg-purple-900/40 flex items-center justify-center mt-0.5",children:e.jsx("span",{className:"text-purple-600 dark:text-purple-300 text-xs",children:"ð"})}),e.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300 leading-snug",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.unlockFeature1",components:{b:e.jsx("strong",{})}})})]}),e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"shrink-0 w-5 h-5 rounded-full bg-purple-100 dark:bg-purple-900/40 flex items-center justify-center mt-0.5",children:e.jsx("span",{className:"text-purple-600 dark:text-purple-300 text-xs",children:"ð¯"})}),e.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300 leading-snug",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.unlockFeature2",components:{b:e.jsx("strong",{})}})})]}),e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"shrink-0 w-5 h-5 rounded-full bg-purple-100 dark:bg-purple-900/40 flex items-center justify-center mt-0.5",children:e.jsx("span",{className:"text-purple-600 dark:text-purple-300 text-xs",children:"â¡"})}),e.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300 leading-snug",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.unlockFeature3",components:{b:e.jsx("strong",{})}})})]})]}),e.jsxs(Ae,{className:"w-full bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 text-white font-semibold py-6 text-base shadow-lg shadow-purple-500/30 transition-all hover:shadow-xl hover:shadow-purple-500/40",onClick:K=>{K.stopPropagation(),l("/pricing")},children:[e.jsx(Ht,{className:"w-5 h-5 mr-2"}),a("ultimateAnalysisModal.viewPlans")]}),e.jsx("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-3",children:a("ultimateAnalysisModal.priceNote")})]})}),e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-purple-500 to-pink-500 rounded-xl flex items-center justify-center",children:e.jsx(be,{className:"w-6 h-6 text-white"})}),e.jsx("h2",{className:"text-2xl md:text-3xl font-bold text-gray-900 dark:text-gray-100",children:a("ultimateAnalysisModal.title")})]}),e.jsx("button",{onClick:r,className:"p-2 hover:bg-gray-100 dark:hover:bg-neutral-800 rounded-lg transition-colors",disabled:v,children:e.jsx(de,{className:"w-6 h-6 text-gray-500 dark:text-gray-400"})})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("h3",{className:"font-bold text-gray-900 dark:text-gray-100 mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-red-500",children:"*"}),a("ultimateAnalysisModal.kpiSectionTitle")]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-3",children:a("ultimateAnalysisModal.kpiSectionHint")}),e.jsx("div",{className:"border-2 border-dashed border-purple-300 dark:border-purple-900 rounded-xl p-6 text-center bg-purple-50 dark:bg-purple-950/40",children:k?e.jsxs("div",{children:[e.jsx("img",{src:k,className:"max-h-48 mx-auto rounded border-2 border-purple-300 dark:border-purple-900 mb-3",alt:"KPI Preview"}),e.jsxs(Ae,{variant:"outline",size:"sm",onClick:()=>{w(null),y(null)},disabled:v,children:[e.jsx(de,{className:"w-4 h-4 mr-1"}),a("ultimateAnalysisModal.remove")]})]}):e.jsxs("div",{children:[e.jsx("input",{type:"file",accept:"image/png,image/jpg,image/jpeg",onChange:K=>{var J;const C=(J=K.target.files)==null?void 0:J[0];if(C){if(C.size>10*1024*1024){P.error(a("ultimateAnalysisModal.errorFileTooLarge"));return}w(C),y(URL.createObjectURL(C))}},className:"hidden",id:"kpi-upload",disabled:v}),e.jsx("label",{htmlFor:"kpi-upload",className:v?"opacity-50 cursor-not-allowed":"cursor-pointer",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(xt,{className:"w-12 h-12 text-purple-500 mb-3"}),e.jsx("p",{className:"font-bold text-gray-900 dark:text-gray-100",children:a("ultimateAnalysisModal.selectKpi")}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:a("ultimateAnalysisModal.kpiFormats")})]})})]})})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("h3",{className:"font-bold text-gray-900 dark:text-gray-100 mb-2 flex items-center gap-2",children:[a("ultimateAnalysisModal.graphSectionTitle"),e.jsx(va,{variant:"outline",className:"text-xs bg-blue-50 dark:bg-blue-950/40 text-blue-900 border-blue-300 dark:border-blue-900",children:a("ultimateAnalysisModal.optional")})]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-3",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.graphSectionHint",components:{b:e.jsx("strong",{})}})}),e.jsx("div",{className:"border-2 border-dashed border-blue-300 dark:border-blue-900 rounded-xl p-6 text-center bg-blue-50 dark:bg-blue-950/40",children:I?e.jsxs("div",{children:[e.jsx("img",{src:I,className:"max-h-48 mx-auto rounded border-2 border-blue-300 dark:border-blue-900 mb-3",alt:"Graph Preview"}),e.jsxs(Ae,{variant:"outline",size:"sm",onClick:()=>{T(null),R(null)},disabled:v,children:[e.jsx(de,{className:"w-4 h-4 mr-1"}),a("ultimateAnalysisModal.remove")]})]}):e.jsxs("div",{children:[e.jsx("input",{type:"file",accept:"image/png,image/jpg,image/jpeg",onChange:K=>{var J;const C=(J=K.target.files)==null?void 0:J[0];if(C){if(C.size>10*1024*1024){P.error(a("ultimateAnalysisModal.errorFileTooLarge"));return}T(C),R(URL.createObjectURL(C))}},className:"hidden",id:"graph-upload",disabled:v}),e.jsx("label",{htmlFor:"graph-upload",className:v?"opacity-50 cursor-not-allowed":"cursor-pointer",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(Ba,{className:"w-10 h-10 text-blue-500 mb-2"}),e.jsx("p",{className:"font-semibold text-gray-900 dark:text-gray-100",children:a("ultimateAnalysisModal.selectGraph")}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:a("ultimateAnalysisModal.graphHint")})]})})]})}),!S&&e.jsx("div",{className:"mt-2 bg-yellow-50 dark:bg-yellow-950/40 border border-yellow-200 dark:border-yellow-900 rounded p-3",children:e.jsx("p",{className:"text-xs text-yellow-800",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.noGraphHint",components:{b:e.jsx("strong",{})}})})})]}),D&&e.jsx("div",{className:"mb-4 bg-gradient-to-br from-gray-900 to-gray-800 border border-gray-700 rounded-xl p-5",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-4xl mb-3",children:"ð"}),e.jsx("h4",{className:"font-bold text-white mb-2 text-lg",children:a("ultimateAnalysisModal.limitTitle")}),e.jsx("p",{className:"text-sm text-gray-300 mb-4",children:a("ultimateAnalysisModal.usedAnalyses",{current:B.current,limit:B.limit})}),g==="free"&&e.jsxs("div",{className:"bg-white dark:bg-neutral-900/10 rounded-lg p-4 mb-3 text-left",children:[e.jsx("p",{className:"font-semibold text-white mb-2",children:a("ultimateAnalysisModal.getMoreAnalyses")}),e.jsxs("div",{className:"space-y-2 text-sm text-gray-300",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-red-400 font-bold",children:"Pro:"}),e.jsx("span",{children:a("ultimateAnalysisModal.proPerks")})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-red-400 font-bold",children:"Ultra:"}),e.jsx("span",{children:a("ultimateAnalysisModal.ultraPerks")})]})]})]}),g==="pro"&&e.jsxs("div",{className:"bg-white dark:bg-neutral-900/10 rounded-lg p-4 mb-3 text-left",children:[e.jsx("p",{className:"font-semibold text-white mb-2",children:a("ultimateAnalysisModal.upgradeToUltra")}),e.jsx("p",{className:"text-sm text-gray-300",children:a("ultimateAnalysisModal.upgradeToUltraText")})]}),e.jsx("button",{onClick:()=>l("/pricing"),className:"w-full px-6 py-3 bg-gradient-to-r from-red-500 to-rose-600 hover:from-red-600 hover:to-rose-700 text-white rounded-xl font-semibold transition-all shadow-lg",children:a("ultimateAnalysisModal.upgradeNow")})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 mb-4",children:[e.jsx("button",{onClick:r,className:"flex-1 px-6 py-3 bg-gray-100 dark:bg-neutral-800 hover:bg-gray-200 dark:hover:bg-neutral-700 text-gray-700 dark:text-gray-300 rounded-xl font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:v,children:a("ultimateAnalysisModal.cancel")}),e.jsxs("button",{onClick:ue,className:"flex-1 px-6 py-3 bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 text-white rounded-xl font-semibold transition-all shadow-lg shadow-purple-500/30 flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",disabled:v||!b||D,children:[e.jsx(be,{className:"w-5 h-5"}),a(D?"ultimateAnalysisModal.limitReached":v?"ultimateAnalysisModal.analyzing":"ultimateAnalysisModal.startAnalysis")]})]}),v&&e.jsxs("div",{className:"mb-4 bg-blue-50 dark:bg-blue-950/40 border border-blue-200 dark:border-blue-900 rounded-lg p-4",children:[e.jsx("p",{className:"text-sm text-blue-800 font-semibold mb-2",children:d}),e.jsx("div",{className:"w-full bg-blue-200 rounded-full h-2",children:e.jsx("div",{className:"bg-blue-600 h-2 rounded-full animate-pulse",style:{width:"60%"}})})]}),j&&e.jsx("div",{className:"mb-4 bg-red-50 dark:bg-red-950/40 border border-red-200 dark:border-red-900 rounded-lg p-4",children:e.jsxs("p",{className:"text-sm text-red-800 font-semibold",children:["â ",j]})}),e.jsxs("div",{className:"mb-4 grid md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-4 border-2 border-purple-200 dark:border-purple-900",children:[e.jsxs("h3",{className:"font-bold text-gray-900 dark:text-gray-100 mb-3 flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:"ð"}),a("ultimateAnalysisModal.exampleTitle")]}),e.jsx("div",{className:"rounded-lg overflow-hidden border-2 border-white shadow-lg mb-3",children:e.jsx("img",{src:"/images/tiktok-analytics-example.jpg",alt:"TikTok Analytics Beispiel",className:"w-full h-auto"})}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 text-center font-medium",children:a("ultimateAnalysisModal.exampleCaption")})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-950/40 border-2 border-blue-200 dark:border-blue-900 rounded-xl p-4",children:[e.jsx("h3",{className:"font-bold text-blue-900 mb-2 text-sm",children:a("ultimateAnalysisModal.whatIsAnalyzed")}),e.jsx("p",{className:"text-xs text-blue-800 leading-relaxed",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.whatIsAnalyzedText",components:{b:e.jsx("strong",{})}})})]}),e.jsxs("div",{className:"bg-purple-50 dark:bg-purple-950/40 border-2 border-purple-200 dark:border-purple-900 rounded-xl p-4",children:[e.jsx("h3",{className:"font-bold text-purple-900 mb-2 text-sm",children:a("ultimateAnalysisModal.neededDataTitle")}),e.jsxs("ul",{className:"space-y-1.5 text-xs text-purple-800",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-purple-500 font-bold mt-0.5",children:"â¢"}),e.jsx("span",{children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.neededData1",components:{b:e.jsx("strong",{})}})})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-purple-500 font-bold mt-0.5",children:"â¢"}),e.jsx("span",{children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.neededData2",components:{b:e.jsx("strong",{})}})})]})]})]}),e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-950/40 border-2 border-yellow-200 dark:border-yellow-900 rounded-xl p-4",children:[e.jsx("h3",{className:"font-bold text-yellow-900 mb-2 text-sm",children:a("ultimateAnalysisModal.whereToFindTitle")}),e.jsx("p",{className:"text-xs text-yellow-800 leading-relaxed",children:e.jsx(we,{t:a,i18nKey:"ultimateAnalysisModal.whereToFindText",components:{b:e.jsx("strong",{})}})})]})]})]})]})})},ir=({videos:t,viewMode:r,isLoading:n,onVideoClick:i,analyzingVideos:a=new Set,anal
57yzingProgress:l=new Map,canAnalyze:M=!0,newVideoCard:b})=>{const{t:w}=Q("dashboard");return n?e.jsx("div",{className:r==="grid"?"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-3":"space-y-4",children:[1,2,3,4,5,6,7,8].map(k=>e.jsx("div",{className:"animate-pulse",children:r==="grid"?e.jsxs("div",{children:[e.jsx("div",{className:"aspect-[9/16] bg-gray-200 dark:bg-neutral-700 rounded-2xl mb-3"}),e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-neutral-700 rounded w-3/4 mb-2"}),e.jsx("div",{className:"h-3 bg-gray-200 dark:bg-neutral-700 rounded w-1/2"})]}):e.jsxs("div",{className:"flex gap-4 p-4 bg-gray-50 dark:bg-neutral-800/50 rounded-2xl",children:[e.jsx("div",{className:"w-24 h-32 bg-gray-200 dark:bg-neutral-700 rounded-xl flex-shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"h-5 bg-gray-200 dark:bg-neutral-700 rounded w-3/4"}),e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-neutral-700 rounded w-1/2"}),e.jsx("div",{className:"h-4 bg-gray-200 dark:bg-neutral-700 rounded w-2/3"})]})]})},k))}):t.length===0?e.jsxs("div",{className:"text-center py-20",children:[e.jsx(Ga,{className:"w-16 h-16 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-bold text-gray-900 dark:text-gray-100 mb-2",children:w("videoGrid.noVideos")}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:w("videoGrid.noVideosHint")})]}):r==="grid"?e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-2 md:gap-3",children:[b,t.map(k=>e.jsx(or,{video:k,onVideoClick:i,isAnalyzing:a.has(k.id),analyzingProgress:l.get(k.id)||0,canAnalyze:M},k.id))]}):e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[b,t.map(k=>e.jsx(dr,{video:k,onVideoClick:i,isAnalyzing:a.has(k.id),analyzingProgress:l.get(k.id)||0,canAnalyze:M},k.id))]})},or=({video:t,onVideoClick:r,isAnalyzing:n=!1,analyzingProgress:i=0,canAnalyze:a=!0})=>{var D;const{t:l}=Q("dashboard"),{isAnalyzing:M,getAnalysisStatus:b}=Qe(),w=M(t.id)?b(t.id):void 0,k=n||M(t.id),y=(w==null?void 0:w.progress)||i;Ce.useState(!1);const[S,T]=Ce.useState(!1),[I,R]=Ce.useState(null),v=ta((w==null?void 0:w.elapsedSeconds)||0,y,w==null?void 0:w.type);Ce.useEffect(()=>{(async()=>{const{data:{user:B}}=await Z.auth.getUser();B&&R(B.id)})()},[]);const u=F=>{if(!F)return l("videoGrid.noDate");const B=new Date(F),H=B.toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"}),O=B.toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"});return l("videoGrid.dateTime",{date:H,time:O})},d=!!t.is_deep_analyzed,f=!!((D=t.deep_analysis_data)!=null&&D.extended_retention_analysis),j=t.platform==="instagram";j&&(t.share_url||t.shortcode&&`${t.shortcode}`);const L=(()=>{const F=t.posted_at?new Date(t.posted_at).getTime():NaN;return Number.isNaN(F)?!1:Date.now()-F<24*60*60*1e3})(),g=d?Es(t):null,U=g==null?"bg-gray-400":g<4?"bg-red-500":g<7?"bg-amber-400":"bg-emerald-400";return e.jsxs("div",{id:`video-${t.id}`,className:"group cursor-pointer relative",children:[e.jsxs("div",{className:"relative aspect-[9/16] rounded-2xl overflow-hidden bg-neutral-900 shadow-lg dark:shadow-black/40 hover:shadow-2xl transition-shadow duration-300",children:[t.thumbnail_url?e.jsx("img",{src:t.thumbnail_url,alt:t.title,className:"absolute inset-0 w-full h-full object-cover"}):e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1.5 bg-neutral-800",children:[e.jsx(Rt,{className:"w-5 h-5 md:w-6 md:h-6 text-white/40"}),e.jsx("span",{className:"text-[9px] md:text-[10px] text-white/40 font-medium",children:l("videoGrid.noThumbnail")})]}),e.jsx("div",{className:"absolute inset-x-0 bottom-0 h-[55%] bg-gradient-to-t from-black/90 via-black/55 to-transparent pointer-events-none"}),e.jsx("div",{className:"absolute inset-x-0 top-0 h-20 bg-gradient-to-b from-black/40 to-transparent pointer-events-none"}),k&&e.jsx("div",{className:"absolute inset-0 bg-black/75 backdrop-blur-[2px] flex items-center justify-center z-30 px-3",children:e.jsx(Ka,{progress:y,remainingLabel:v,compact:!0})}),e.jsxs("div",{className:"absolute left-2 md:left-3 top-2 md:top-3 flex flex-col items-start gap-1.5 z-10 max-w-[calc(100%-1rem)]",children:[k?e.jsxs("span",{className:"inline-flex items-center gap-1 pl-0.5 pr-2 md:pr-2.5 py-0.5 rounded-full bg-white text-gray-900 text-[10px] md:text-xs font-semibold shadow-sm",children:[e.jsx("span",{className:"flex items-center justify-center w-4 h-4 md:w-5 md:h-5 rounded-full bg-purple-600",children:e.jsx(fe,{className:"w-3 h-3 md:w-3.5 md:h-3.5 text-white animate-spin"})}),l("videoGrid.running")]}):d?e.jsxs("span",{className:"inline-flex items-center gap-1 pl-0.5 pr-2 md:pr-2.5 py-0.5 rounded-full bg-white text-gray-900 text-[10px] md:text-xs font-semibold shadow-sm",children:[e.jsx("span",{className:`flex items-center justify-center w-4 h-4 md:w-5 md:h-5 rounded-full ${f?"bg-purple-600":"bg-emerald-500"}`,children:e.jsx(qa,{className:"w-3 h-3 md:w-3.5 md:h-3.5 text-white",strokeWidth:2.5})}),l(f?"videoGrid.ultimate":"videoGrid.analyzed")]}
57):L?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 md:px-2.5 py-0.5 md:py-1 rounded-full bg-white/95 backdrop-blur text-gray-900 text-[10px] md:text-xs font-semibold shadow-sm",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-rose-500 animate-pulse"}),l("videoGrid.new")]}):null,d&&g!=null&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 md:px-2.5 py-0.5 md:py-1 rounded-full bg-neutral-900/85 backdrop-blur text-white text-[10px] md:text-xs font-bold tabular-nums shadow-sm",children:[e.jsx("span",{className:`w-1.5 h-1.5 md:w-2 md:h-2 rounded-full ${U}`}),g.toFixed(1),e.jsx("span",{className:"text-white/55 font-medium ml-0.5",children:"/10"})]})]}),e.jsxs("div",{className:`absolute inset-x-2 md:inset-x-3 bottom-2 md:bottom-3 flex flex-col gap-1.5 md:gap-2 z-10 ${k?"":"transition-opacity duration-300 group-hover:opacity-0"}`,children:[t.title&&e.jsx("h3",{className:"text-white font-bold text-xs md:text-sm leading-tight line-clamp-2 drop-shadow",children:t.title}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-0.5 md:gap-y-1 text-white text-[11px] md:text-xs font-semibold mt-0.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 md:gap-1.5",children:[e.jsx(ce,{className:"w-3 h-3 md:w-3.5 md:h-3.5 opacity-90"}),e.jsx("span",{className:"drop-shadow",children:De(t.views||0)})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 md:gap-1.5",children:[e.jsx(_t,{className:"w-3 h-3 md:w-3.5 md:h-3.5 opacity-90"}),e.jsx("span",{className:"drop-shadow",children:De(t.likes||0)})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 md:gap-1.5",children:[e.jsx(qe,{className:"w-3 h-3 md:w-3.5 md:h-3.5 opacity-90"}),e.jsx("span",{className:"drop-shadow",children:De(t.comments||0)})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 md:gap-1.5",children:[e.jsx(Ft,{className:"w-3 h-3 md:w-3.5 md:h-3.5 opacity-90"}),e.jsx("span",{className:"drop-shadow",children:De(t.shares||0)})]})]})]}),!k&&e.jsx("div",{className:"absolute inset-0 bg-black/70 backdrop-blur-[1px] opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-center justify-center z-20 p-3",children:j?e.jsxs("div",{className:"flex flex-col gap-2 w-full items-stretch max-w-[180px]",children:[a&&!d&&e.jsx(Re,{onClick:()=>r(t,"analyze"),icon:be,children:l("videoGrid.analyze")}),a&&d&&e.jsx(Re,{onClick:()=>r(t,"extended"),icon:ft,accent:"amber",children:l("videoGrid.results")})]}):a?e.jsx("div",{className:"flex flex-col gap-2 w-full items-stretch max-w-[180px]",children:d?f?e.jsx(Re,{onClick:()=>r(t,"extended"),icon:ft,children:l("videoGrid.viewUltimate")}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{onClick:()=>T(!0),icon:vt,children:l("videoGrid.ultimate")}),e.jsx(Re,{onClick:()=>r(t,"extended"),icon:ft,accent:"amber",children:l("videoGrid.results")})]}):e.jsx(Re,{onClick:()=>r(t,"analyze"),icon:be,children:l("videoGrid.analyze")})}):e.jsxs("div",{className:"text-center text-white",children:[e.jsx(ce,{className:"w-6 h-6 md:w-8 md:h-8 mx-auto mb-2 opacity-70"}),e.jsx("p",{className:"font-medium text-xs md:text-sm",children:l("videoGrid.viewOnly")}),e.jsx("p",{className:"text-[10px] md:text-xs opacity-70 mt-1",children:l("videoGrid.viewerPermission")})]})})]}),e.jsx("p",{className:"text-[10px] md:text-xs text-gray-500 dark:text-gray-400 mt-2 px-1",children:u(t.posted_at||t.created_at)}),S&&I&&e.jsx(Ta,{isOpen:S,onClose:()=>T(!1),video:t,userId:I})]})},Re=({onClick:t,icon:r,children:n,accent:i="purple"})=>e.jsxs("button",{onClick:a=>{a.stopPropagation(),t(a)},className:`inline-flex items-center justify-center gap-1.5 px-3 py-1.5 md:px-3.5 md:py-2 rounded-xl font-semibold text-[11px] md:text-xs text-white shadow-lg shadow-black/30 border border-white/10 hover:brightness-110 active:scale-[0.98] transition ${i==="amber"?"bg-gradient-to-r from-amber-500 to-orange-600":"bg-gradient-to-r from-purple-600 to-purple-800"}`,children:[e.jsx(r,{className:"w-3.5 h-3.5 md:w-4 md:h-4 shrink-0"}),e.jsx("span",{className:"truncate",children:n})]}),dr=({video:t,onVideoClick:r,isAnalyzing:n=!1,analyzingProgress:i=0,canAnalyze:a=!0})=>{var j,L;const{t:l}=Q("dashboard"),{isAnalyzing:M,getAnalysisStatus:b}=Qe(),w=M(t.id)?b(t.id):void 0,k=n||M(t.id),y=(w==null?void 0:w.progress)||i,[S,T]=Ce.useState(!1),[I,R]=Ce.useState(null),v=ta((w==null?void 0:w.elapsedSeconds)||0,y,w==null?void 0:w.type),u=!!((j=t.deep_analysis_data)!=null&&j.extended_retention_analysis),d=t.platform==="instagram";Ce.useEffect(()=>{(async()=>{const{data:{user:U}}=await Z.auth.getUser();
57U&&R(U.id)})()},[]);const f=g=>{if(!g)return l("videoGrid.noDate");const U=new Date(g),D=U.toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"}),F=U.toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"});return l("videoGrid.dateTime",{date:D,time:F})};return e.jsxs("div",{id:`video-${t.id}`,className:"flex items-center gap-2 md:gap-3 p-2 md:p-3 bg-white dark:bg-neutral-900 hover:bg-gray-50 dark:hover:bg-neutral-800/50 rounded-xl md:rounded-2xl transition-all group border border-gray-200 dark:border-neutral-800",children:[e.jsxs("div",{className:"w-16 h-20 md:w-20 md:h-28 bg-gradient-to-br from-gray-200 to-gray-300 dark:from-neutral-800 dark:to-neutral-900 rounded-lg flex-shrink-0 overflow-hidden relative",children:[k&&e.jsx("div",{className:"absolute inset-x-0 top-0 h-2/3 bg-black/65 flex items-center justify-center z-20 rounded-t-lg",children:e.jsxs("div",{className:"w-full max-w-[95%] px-1.5 overflow-hidden",children:[e.jsx(fe,{className:"w-5 h-5 text-white animate-spin mx-auto mb-1"}),e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1 min-w-0",children:[e.jsx("p",{className:"text-white text-[8px] font-medium leading-none whitespace-nowrap",children:l("videoGrid.analysis")}),v&&e.jsx("p",{className:"text-white/70 text-[7px] leading-none whitespace-nowrap",children:v})]}),e.jsxs("div",{className:"flex items-center gap-1 w-full max-w-[58px] mx-auto",children:[e.jsx("div",{className:"flex-1 bg-white dark:bg-neutral-900/20 rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-pink-500 to-red-500 transition-all duration-100",style:{width:`${y}%`}})}),e.jsxs("p",{className:"text-white/80 text-[7px] tabular-nums leading-none whitespace-nowrap shrink-0",children:[Math.round(y),"%"]})]})]})}),t.thumbnail_url?e.jsx("img",{src:t.thumbnail_url,alt:t.title,className:"w-full h-full object-cover"}):e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center bg-muted/50 gap-1",children:[e.jsx(Rt,{className:"w-4 h-4 text-muted-foreground/60"}),e.jsx("span",{className:"text-[7px] text-muted-foreground/60 font-medium",children:l("videoGrid.noThumbnail")})]}),t.is_deep_analyzed&&e.jsx("div",{className:`absolute top-2 right-2 ${u?"px-1.5 h-5 rounded-full":"w-5 h-5 rounded-full"} ${u?"bg-purple-600":"bg-green-500"} text-white text-[10px] font-bold flex items-center justify-center shadow-lg`,title:l(u?"videoGrid.ultimateAnalysis":"videoGrid.analyzed"),children:u?l("videoGrid.ultimate"):"â"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-gray-100 mb-0.5 md:mb-1 text-xs md:text-sm truncate group-hover:text-pink-600 transition-colors",children:t.title||l("videoGrid.untitled")}),e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 text-[10px] md:text-xs text-gray-600 dark:text-gray-400 mb-1 md:mb-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-0.5 md:gap-1 bg-gray-100 dark:bg-neutral-800 px-1.5 py-0.5 md:px-2 md:py-1 rounded-md md:rounded-lg",children:[e.jsx(ce,{className:"w-3 h-3 md:w-3.5 md:h-3.5 text-gray-500 dark:text-gray-400"}),e.jsx("span",{className:"font-semibold",children:De(t.views||0)})]}),e.jsxs("div",{className:"flex items-center gap-0.5 md:gap-1 bg-gray-100 dark:bg-neutral-800 px-1.5 py-0.5 md:px-2 md:py-1 rounded-md md:rounded-lg",children:[e.jsx(_t,{className:"w-3 h-3 md:w-3.5 md:h-3.5 text-pink-500"}),e.jsx("span",{className:"font-semibold",children:De(t.likes||0)})]}),e.jsxs("div",{className:"flex items-center gap-0.5 md:gap-1 bg-gray-100 dark:bg-neutral-800 px-1.5 py-0.5 md:px-2 md:py-1 rounded-md md:rounded-lg",children:[e.jsx(qe,{className:"w-3 h-3 md:w-3.5 md:h-3.5 text-blue-500"}),e.jsx("span",{className:"font-semibold",children:De(t.comments||0)})]}),e.jsxs("div",{className:"flex items-center gap-0.5 md:gap-1 bg-gray-100 dark:bg-neutral-800 px-1.5 py-0.5 md:px-2 md:py-1 rounded-md md:rounded-lg",children:[e.jsx(Ft,{className:"w-3 h-3 md:w-3.5 md:h-3.5 text-green-500"}),e.jsx("span",{className:"font-semibold",children:De(t.shares||0)})]})]}),e.jsx("p",{className:"text-[10px] md:text-xs text-gray-600 dark:text-gray-400 font-medium",children:f(t.posted_at||t.created_at)})]}),e.jsx("div",{className:"flex flex-col gap-1 md:gap-1.5 flex-shrink-0",children:t.is_deep_analyzed?d?e.jsxs("button",{onClick:()=>r(t,"extended"),className:"px-2 py-1 md:px-3 md:py-1.5 text-[10px] md:text-xs rounded-md md:rounded-lg font-medium transition-all flex items-center justify-center gap-1 md:gap-1.5 bg-gradient-to-b from-amber-500 to-orange-700 hover:from-amber-400 hover:to-orange-600 text-white shadow-[0_4px_20px_rgba(245,158,11,0.4)] border border-white/20",children:[e.jsx(ce,{className:"w-3 h-3 md:w-3.5 md:h-3.5"}),e.jsx("span",{className:"hidden md:inline",children:l("videoGrid.analysisResults")}),e.jsx("span",{className:"md:hidden",children:l("videoGrid.results")})]}):(L=t.deep_analysis_data)!=null&&L.extended_retention_analysis?e.jsxs("button",{onClick:()=>r(t,"extended"),className:"px-2 py-1 md:px-3 md:py-1.5 text-[10px] md:text-xs rounded-md md:rounded-lg font-medium transition-all flex items-center justify-center gap-1 md:gap-1.5 bg-gradient-to-b from-violet-500 to-purple-900 hover:from-violet-400 hover:to-purple-800 text-white shadow-[0_4px_20px_rgba(109,40,217,0.4)] border border-white/20",children:[e.jsx(ce,{className:"w-3 h-3 md:w-3.5 md:h-3.5"}),e.jsx("span",{className:"hidden md:inline",children:l("videoGrid.ultimateAnalysis")}),e.jsx("span",{className:"md:hidden",children:l("videoGrid.ultimate")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>T(!0),className:"px-2 py-1 md:px-3 md:py-1.5 text-[10px] md:text-xs rounded-md md:rounded-lg font-medium transition-all flex items-center justify-center gap-1 md:gap-1.5 bg-gradient-to-b from-violet-500 to-purple-900 hover:from-violet-400 hover:to-purple-800 text-white shadow-[0_4px_20px_rgba(109,40,217,0.4)] border border-white/20",children:[e.jsx(vt,{className:"w-3 h-3 md:w-3.5 md:h-3.5"}),e.jsx("span",{className:"hidden md:inline",children:l("videoGrid.ultimateAnalysis")}),e.jsx("span",{className:"md:hidden",children:l("videoGrid.ultimate")})]}),e.jsxs("button",{onClick:()=>r(t,"extended"),className:"px-2 py-1 md:px-3 md:py-1.5 text-[10px] md:text-xs rounded-md md:rounded-lg font-medium transition-all flex items-center justify-center gap-1 md:gap-1.5 bg-gradient-to-b from-amber-500 to-orange-700 hover:from-amber-400 hover:to-orange-600 text-white shadow-[0_4px_20px_rgba(245,158,11,0.4)] border border-white/20",children:[e.jsx(ce,{className:"w-3 h-3 md:w-3.5 md:h-3.5"}),e.jsx("span",{className:"hidden md:inline",children:l("videoGrid.analysisResults")}),e.jsx("span",{className:"md:hidden",children:l("videoGrid.results")})]})]}):e.jsx("button",{onClick:()=>r(t,"analyze"),className:"px-2 py-1 md:px-3 md:py-1.5 rounded-md md:rounded-lg font-medium text-[10px] md:text-xs transition-all bg-white dark:bg-neutral-900 border border-gray-300 dark:border-neutral-700 md:border-2 hover:border-pink-500 text-gray-900 dark:text-gray-100 hover:text-pink-600",children:l("videoGrid.analyze")})}),S&&I&&e.jsx(Ta,{isOpen:S,onClose:()=>T(!1),video:t,userId:I})]})},De=t=>t>=1e6?(t/1e6).toFixed(1)+"M":t>
57=1e3?(t/1e3).toFixed(1)+"K":t.toString(),cr=({viewMode:t,onSync:r,isSyncing:n})=>{const{t:i}=Q("dashboard");return t==="list"?e.jsxs("button",{onClick:r,disabled:n,className:"w-full flex items-center gap-2 md:gap-3 p-2 md:p-3 bg-white dark:bg-neutral-900 hover:bg-gray-50 dark:hover:bg-neutral-800/50 rounded-xl md:rounded-2xl transition-all border border-gray-200 dark:border-neutral-800 group",children:[e.jsx("div",{className:"w-16 h-20 md:w-20 md:h-28 bg-gradient-to-br from-gray-100 to-gray-200 rounded-lg flex-shrink-0 flex items-center justify-center",children:n?e.jsx(fe,{className:"w-5 h-5 text-gray-400 dark:text-gray-500 animate-spin"}):e.jsx(We,{className:"w-5 h-5 text-gray-400 dark:text-gray-500 group-hover:text-gray-600 group-hover:rotate-180 transition-all duration-500"})}),e.jsxs("div",{className:"flex-1 text-left",children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-gray-100 text-xs md:text-sm mb-0.5",children:"Neues Video gefunden"}),e.jsx("p",{className:"text-[10px] md:text-xs text-gray-500 dark:text-gray-400 font-medium",children:i(n?"newVideoCard.syncing":"newVideoCard.syncNow")})]})]}):e.jsxs("button",{onClick:r,disabled:n,className:"group cursor-pointer relative transition-all w-full text-left",children:[e.jsx("div",{className:"relative aspect-[9/16] bg-gradient-to-br from-gray-100 to-gray-200 rounded-xl md:rounded-2xl overflow-hidden mb-2 md:mb-3 transition-all flex items-center justify-center hover:shadow-md",children:e.jsxs("div",{className:"relative z-10 flex flex-col items-center gap-2 md:gap-3 px-3 text-center",children:[n?e.jsx(fe,{className:"w-8 h-8 md:w-10 md:h-10 text-gray-400 dark:text-gray-500 animate-spin"}):e.jsx("div",{className:"w-12 h-12 md:w-14 md:h-14 rounded-full bg-white dark:bg-neutral-900/80 flex items-center justify-center group-hover:bg-white transition-colors shadow-sm",children:e.jsx(We,{className:"w-5 h-5 md:w-6 md:h-6 text-gray-400 dark:text-gray-500 group-hover:text-gray-600 group-hover:rotate-180 transition-all duration-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs md:text-sm font-semibold text-gray-600 dark:text-gray-400",children:"Neues Video gefunden"}),e.jsx("p",{className:"text-[10px] md:text-xs text-gray-400 dark:text-gray-500 font-medium mt-0.5",children:i(n?"newVideoCard.syncing":"newVideoCard.syncNow")})]})]})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-gray-100 text-xs md:text-sm mb-0.5 md:mb-1",children:"Neues Video verfügbar"}),e.jsx("p",{className:"text-[10px] md:text-xs text-gray-500 dark:text-gray-400",children:"Tippe zum Synchronisieren"})]})]})},st=new Map,Qt=5*60*1e3;function xr(t){const[r,n]=s.useState(()=>{if(!t)return!1;const b=st.get(t);return b&&Date.now()-b.checkedAt<Qt?b.hasNewVideos:!1}),[i,a]=s.useState(!1),l=s.useRef(void 0);s.useEffect(()=>{if(!t)return;l.current!==t&&(l.current=t);const b=st.get(t);if(b&&Date.now()-b.checkedAt<Qt){n(b.hasNewVideos);return}let w=!1;return(async()=>{a(!0);try{const{data:y,error:S}=await Z.functions.invoke("check-new-videos",{body:{account_id:t}});if(w)return;if(S){console.error("check-new-videos error:",S);return}const T=(y==null?void 0:y.hasNewVideos)??!1;n(T),st.set(t,{hasNewVideos:T,checkedAt:Date.now()})}catch(y){w||console.error("check-new-videos failed:",y)}finally{w||a(!1)}})(),()=>{w=!0}},[t]);const M=s.useCallback(()=>{n(!1),t&&st.set(t,{hasNewVideos:!1,checkedAt:Date.now()})},[t]);return{hasNewVideos:r,isChecking:i,dismiss:M}}const mr=[{keyword:"heruntergeladen",target:20,labelKey:"stepDownload"},{keyword:"hochgeladen",target:40,labelKey:"stepUpload"},{keyword:"Timeline",target:55,labelKey:"stepFrames"},{keyword:"KI analysiert",target:80,labelKey:"stepAiAnalysis"},{keyword:"Speichere",target:95,labelKey:"stepSave"}],ur=({video:t,onClose:r,onComplete:n,onStartBackgroundAnalysis:i,userTier:a})=>{const{t:l}=Q("videos"),{startDeepAnalysis:M,getAnalysisStatus:b,isAnalyzing:w}=Qe(),k=l("analysisModal.tiktokFeatures",{returnObjects:!0}),y=l("analysisModal.instagramFeatures",{returnObjects:!0}),S=!!(t!=null&&t.instagram_account_id||t!=null&&t.ig_video_id||(t==null?void 0:t.platform)==="instagram"),T=S?y:k,I=b(t.id),R=!!I&&!I.error&&I.progress<100,[v,u]=s.useState(""),[d,f]=s.useState(""),[j,L]=s.useState(!1),[g,U]=s.useState(!1),[D,F]=s.useState("free"),[B,H]=s.useState({current:0,limit:0}),[O,ue]=s.useState(!0),[K,C]=s.useState(0),[J,q]=s.useState(!1),[ee,xe]=s.useState(0),[ne,p]=s.useState(0),[W,ge]=s.useState(-1),pe=s.useRef(null);s.useEffect(()=>{(async()=>{try{ue(!0);const{data:{user:V}}=await Z.auth.getUser();if(!V)return;let ie=a||"free";if(!a){const{data:ke}=await Z.from("users").select("subscription_tier").eq("id",V.id).single();ie=(ke==null?void 0:ke.subscription_tier)||"free"}F(ie);const Te=await it(V.id,"deep_analysis",ie);H({current:Te.current,limit:Te.limit}),U(!Te.allowed)}catch(V){console.error("Failed to check usage limit:",V)}finally{ue(!1)}})()},[a]),s.useEffect(()=>{const $=V=>{V.key==="Escape"&&!j&&r()};return document.addEventListener("keydown",$),()=>document.removeEventListener("keydown",$)},[j,r]),s.useEffect(()=>{let $;return j&&(C(0),$=setInterval(()=>{C(V=>V+1)},1e3)),()=>{$&&clearInterval($)}},[j]),s.useEffect(()=>(ee<ne&&(pe.current=requestAnimationFrame(()=>{const $=ne-ee,V=Math.max(.5,$*.08);xe(ie=>Math.min(ie+V,ne))}
57)),()=>{pe.current&&cancelAnimationFrame(pe.current)}),[ee,ne]),s.useEffect(()=>{let $;return j&&ee<ne-3&&($=setInterval(()=>{xe(V=>{const ie=ne-3;return V<ie?V+.3:V})},100)),()=>{$&&clearInterval($)}},[j,ne]);const Me=!O&&!j&&!d&&!g;return e.jsx("div",{className:"fixed inset-0 bg-black/50 dark:bg-black/70 backdrop-blur-md flex items-start justify-center z-[200] px-4 py-6 sm:py-12 lg:py-20 overflow-y-auto",onClick:()=>r(),children:e.jsx("div",{className:"bg-white dark:bg-neutral-900 rounded-[22px] shadow-[0_1px_0_rgba(0,0,0,0.04),0_30px_60px_-20px_rgba(20,18,30,0.18),0_12px_24px_-12px_rgba(20,18,30,0.12)] w-full max-w-3xl relative overflow-hidden my-auto",onClick:$=>$.stopPropagation(),children:e.jsxs("div",{className:"p-5 sm:p-7",children:[e.jsx("button",{onClick:r,"aria-label":l("analysisModal.closeAria"),className:"absolute top-4 right-4 w-8 h-8 rounded-full text-neutral-500 hover:text-neutral-900 dark:hover:text-neutral-100 hover:bg-neutral-100 dark:hover:bg-neutral-800 flex items-center justify-center transition-colors z-10",children:e.jsx(de,{className:"w-[18px] h-[18px]"})}),e.jsx("div",{className:"mb-3.5 sm:mb-4 pr-10",children:e.jsx("h2",{className:"text-xl sm:text-[26px] font-semibold tracking-[-0.02em] leading-[1.1] text-neutral-950 dark:text-neutral-50",children:l(S?"analysisModal.reelTitle":"analysisModal.videoTitle")})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[0.9fr_1.1fr] gap-4 md:gap-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"relative aspect-square rounded-[12px] overflow-hidden bg-gradient-to-br from-[#2a2230] via-[#0f0d14] to-[#1a1620]",children:[t.thumbnail_url?e.jsx("img",{src:t.thumbnail_url,alt:t.title,className:"w-full h-full object-cover"}):e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 text-white/40",children:[e.jsx(Rt,{className:"w-7 h-7"}),e.jsx("span",{className:"text-xs font-medium",children:l("videoList.noThumbnail")})]}),t.duration&&e.jsx("span",{className:"absolute right-2.5 bottom-2.5 font-mono text-[11px] font-medium text-white bg-black/60 backdrop-blur-md px-1.5 py-0.5 rounded tabular-nums",children:gr(t.duration)})]}),t.title&&e.jsx("div",{className:"hidden md:block mt-3 mb-3 text-[13.5px] font-semibold leading-[1.35] tracking-[-0.005em] text-neutral-950 dark:text-neutral-50 line-clamp-2",children:t.title||l("videoList.videoNoTitle")}),e.jsxs("div",{className:"grid grid-cols-2 gap-1.5 mt-3 md:mt-0",children:[e.jsx(rt,{icon:e.jsx(ce,{className:"w-[13px] h-[13px]"}),iconClass:"bg-blue-50 border-blue-100 text-blue-600 dark:bg-blue-950/40 dark:border-blue-900/60 dark:text-blue-300",label:"Views",value:lt(t.views||0)}),e.jsx(rt,{icon:e.jsx(_t,{className:"w-[13px] h-[13px]"}
57),iconClass:"bg-rose-50 border-rose-100 text-rose-600 dark:bg-rose-950/40 dark:border-rose-900/60 dark:text-rose-300",label:"Likes",value:lt(t.likes||0)}),e.jsx(rt,{icon:e.jsx(qe,{className:"w-[13px] h-[13px]"}),iconClass:"bg-green-50 border-green-100 text-green-600 dark:bg-green-950/40 dark:border-green-900/60 dark:text-green-300",label:"Comments",value:lt(t.comments||0)}),e.jsx(rt,{icon:e.jsx(Ft,{className:"w-[13px] h-[13px]"}),iconClass:"bg-purple-50 border-purple-100 text-purple-600 dark:bg-purple-950/40 dark:border-purple-900/60 dark:text-purple-300",label:"Shares",value:lt(t.shares||0)})]})]}),e.jsxs("div",{className:"min-h-full",children:[O&&e.jsxs("div",{className:"bg-neutral-50 dark:bg-neutral-800/50 border border-neutral-200 dark:border-neutral-800 rounded-[14px] p-5 h-full min-h-[200px] flex flex-col items-center justify-center text-center",children:[e.jsx(fe,{className:"w-7 h-7 text-neutral-400 animate-spin mb-3"}),e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400",children:l("analysisModal.checkingAnalyses")})]}),!O&&!j&&!d&&g&&e.jsxs("div",{className:"bg-gradient-to-br from-neutral-900 to-neutral-800 rounded-[14px] p-5 h-full min-h-[280px] flex flex-col justify-center text-center",children:[e.jsx("div",{className:"text-3xl mb-2",children:"ð"}),e.jsx("h4",{className:"font-semibold text-white text-base mb-1.5",children:l("analysisModal.limitReached")}),e.jsx("p",{className:"text-sm text-neutral-300 mb-4",children:l("analysisModal.usedAnalyses",{current:B.current,limit:B.limit})}),D==="free"&&e.jsxs("div",{className:"bg-white/[0.06] rounded-lg p-3.5 mb-3 text-left",children:[e.jsx("p",{className:"font-semibold text-white text-sm mb-1.5",children:l("analysisModal.getMoreAnalyses")}),e.jsxs("div",{className:"space-y-1.5 text-xs text-neutral-300",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-purple-300 font-semibold",children:"Pro:"}),e.jsx("span",{children:l("analysisModal.proPerks")})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-purple-300 font-semibold",children:"Ultra:"}),e.jsx("span",{children:l("analysisModal.ultraPerks")})]})]})]}),D==="pro"&&e.jsxs("div",{className:"bg-white/[0.06] rounded-lg p-3.5 mb-3 text-left",children:[e.jsx("p",{className:"font-semibold text-white text-sm mb-1",children:l("analysisModal.upgradeToUltra")}),e.jsx("p",{className:"text-xs text-neutral-300",children:l("analysisModal.upgradeToUltraText")})]}),e.jsx("button",{onClick:()=>window.location.href="/pricing",className:"w-full h-11 rounded-[12px] bg-gradient-to-r from-purple-600 to-purple-500 hover:from-purple-700 hover:to-purple-600 text-white font-semibold text-sm transition-all",children:l("analysisModal.upgradeNow")})]}),Me&&e.jsxs("div",{className:"rounded-[12px] border border-purple-100 dark:border-purple-900/60 bg-gradient-to-b from-purple-50/40 to-purple-50 dark:from-purple-950/30 dark:to-purple-950/50 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>q($=>!$),"aria-expanded":J,className:"md:cursor-default w-full flex items-center justify-between px-4 py-3 md:py-3.5 text-left hover:bg-purple-100/40 md:hover:bg-transparent transition-colors",children:[e.jsxs("h3",{className:"flex items-center gap-2 text-[13px] font-semibold tracking-[-0.005em] text-neutral-950 dark:text-neutral-50 m-0",children:[l("analysisModal.whatWeAnalyze"),e.jsx("span",{className:"text-[10px] font-semibold bg-purple-600 text-white px-1.5 py-[2px] rounded-full tracking-wide",children:l("analysisModal.moduleCount",{count:T.length})})]}),e.jsx("span",{className:ye("md:hidden w-6 h-6 rounded-md bg-white/60 dark:bg-neutral-900/40 text-purple-800 dark:text-purple-200 flex items-center justify-center transition-transform duration-200",J&&"rotate-180"),"aria-hidden":"true",children:e.jsx(Ye,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:ye("px-4 pb-3.5","md:block",J?"block animate-in fade-in slide-in-from-top-1 duration-200":"hidden"),children:[e.jsx("ul",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-1 gap-x-3 gap-y-2 list-none p-0 m-0",children:T.map(($,V)=>e.jsxs("li",{className:"flex gap-2 items-start text-neutral-800 dark:text-neutral-200",children:[e.jsx("span",{className:"flex-shrink-0 w-4 h-4 rounded-full bg-white dark:bg-neutral-900 border border-purple-200 dark:border-purple-800 text-purple-600 dar
57k:text-purple-300 flex items-center justify-center mt-[2px]",children:e.jsx(kt,{className:"w-[9px] h-[9px]",strokeWidth:3})}),e.jsxs("span",{className:"flex flex-col min-w-0 leading-tight",children:[e.jsx("b",{className:"text-[12.5px] font-semibold leading-[1.2] tracking-[-0.005em] text-neutral-950 dark:text-neutral-50",children:$.t}),$.s&&e.jsx("span",{className:"text-[11px] leading-[1.2] text-neutral-500 dark:text-neutral-400 mt-[1px]",children:$.s})]})]},V))}),e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-dashed border-purple-200 dark:border-purple-900 flex gap-1.5 items-start text-[11.5px] leading-[1.4] text-purple-800 dark:text-purple-300",children:[e.jsx(be,{className:"w-3 h-3 mt-[2px] flex-shrink-0"}),e.jsx("span",{children:l("analysisModal.geminiHint")})]})]})]}),j&&e.jsxs("div",{className:"bg-gradient-to-br from-purple-50 to-purple-100 dark:from-purple-950/40 dark:to-purple-900/30 rounded-[14px] p-6 border border-purple-200 dark:border-purple-900 h-full min-h-[280px] flex flex-col justify-center",children:[e.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(fe,{className:"w-6 h-6 text-purple-600 animate-spin"}),e.jsx("div",{className:"absolute inset-0 w-6 h-6 bg-purple-300/40 rounded-full animate-ping"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-neutral-950 dark:text-neutral-50 font-semibold mb-1",children:l("analysisModal.analysisRunning")}),e.jsx("p",{className:"text-sm text-neutral-700 dark:text-neutral-300",children:v})]})]}),e.jsxs("div",{className:"mb-4 text-center",children:[e.jsxs("span",{className:"text-2xl font-mono font-bold text-neutral-800 dark:text-neutral-200 tabular-nums",children:[Math.floor(K/60),":",(K%60).toString().padStart(2,"0")]}),e.jsx("p",{className:"text-xs text-neutral-500 mt-1",children:v.includes("heruntergeladen")?l("analysisModal.downloadHint"):l("analysisModal.runtime")})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-full bg-white/70 dark:bg-neutral-900/50 backdrop-blur-sm rounded-full h-3 overflow-hidden shadow-inner border border-purple-200 dark:border-purple-900",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-purple-600 via-purple-500 to-purple-600 bg-[length:200%_100%] animate-gradient transition-all duration-300 ease-out",style:{width:`${ee}%`}})}),e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsx("span",{className:"text-xs font-medium text-neutral-600 dar
57k:text-neutral-400",children:l("analysisModal.progress")}),e.jsxs("span",{className:"text-sm font-bold text-purple-600 tabular-nums",children:[Math.round(ee),"%"]})]}),e.jsx("div",{className:"flex justify-between mt-3 px-1",children:mr.map(($,V)=>e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("div",{className:ye("w-2.5 h-2.5 rounded-full transition-all duration-300",ee>=$.target?"bg-purple-600 scale-110":W===V?"bg-purple-400 animate-pulse":"bg-neutral-300 dark:bg-neutral-700")}),e.jsx("span",{className:ye("text-[10px] transition-colors",ee>=$.target?"text-purple-600 font-medium":"text-neutral-400"),children:l("analysisModal."+$.labelKey)})]},V))})]})]}),d&&e.jsxs("div",{className:"bg-destructive/10 border border-destructive/20 rounded-[14px] p-4 min-h-[200px] flex items-start gap-3",children:[e.jsx(ea,{className:"w-5 h-5 text-destructive flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-destructive mb-1",children:l("analysisModal.analysisFailed")}),e.jsx("p",{className:"text-sm text-destructive/80",children:d})]})]}),ee>=100&&!d&&e.jsxs("div",{className:"bg-green-500/10 border border-green-500/20 rounded-[14px] p-4 h-full flex items-center gap-3",children:[e.jsx(Wa,{className:"w-5 h-5 text-green-500"}),e.jsx("p",{className:"text-green-500 font-medium",children:l("analysisModal.analysisCompleted")})]})]})]}),e.jsxs("div",{className:"mt-4 sm:mt-5 grid grid-cols-1 md:grid-cols-[1fr_1.5fr] gap-2",children:[!j&&!R&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"order-2 md:order-1 h-11 md:h-12 rounded-[12px] bg-neutral-100 dark:bg-neutral-800 hover:bg-neutral-200 dark:hover:bg-neutral-700 text-neutral-950 dark:text-neutral-50 font-semibold text-sm md:text-[14.5px] tracking-[-0.005em] transition-colors",children:l("analysisModal.cancel")}),e.jsx("button",{onClick:async()=>{await M(t,n)&&r()},disabled:t.is_deep_analyzed||g||O,className:"order-1 md:order-2 h-11 md:h-12 rounded-[12px] bg-neutral-950 dark:bg-neutral-50 dark:text-neutral-950 hover:bg-black dark:hover:bg-white text-white font-semibold text-sm md:text-[14.5px] tracking-[-0.005em] shadow-[0_1px_0_rgba(255,255,255,0.05)_inset,0_6px_16px_rgba(20,18,30,0.22)] transition-all disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:t.is_deep_analyzed?l("analysisModal.alreadyAnalyzed"):g?l("analysisModal.limitReached"):O?l("analysisModal.checking"):e.jsxs(e.Fragment,{children:[l("analysisModal.startAnalysis"),e.jsx(nt,{className:"w-4 h-4"})]})})]}),(j||R)&&e.jsx("button",{onClick:r,className:"md:col-span-2 h-11 md:h-12 rounded-[12px] bg-neutral-100 dark:bg-neutral-800 hover:bg-neutral-200 dark:hover:bg-neutral-700 text-neutral-950 dark:text-neutral-50 font-semibold text-sm md:text-[14.5px] transition-colors",children:l("analysisModal.closeAnalysisRuns")})]}),e.jsxs("div",{className:"mt-2.5 flex items-center justify-center gap-1.5 text-[11.5px] text-neutral-500 dark:text-neutral-400",children:[e.jsx(Za,{className:"w-3 h-3"}),e.jsx("span",{children:l("analysisModal.fineprint",{type:l(S?"analysisModal.typeReel":"analysisModal.typeVideo")})})]})]})})})},rt=({icon:t,iconClass:r,label:n,value:i})=>e.jsxs("div",{className:"bg-neutral-50 dark:bg-neutral-800/40 border border-neutral-200 dark:border-neutral-800 rounded-[9px] px-2.5 py-2 flex items-center gap-2",children:[e.jsx("span",{className:ye("w-7 h-7 rounded-[7px] border flex items-center justify-center flex-shrink-0",r),children:t}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10.5px] text-neutral-500 dark:text-neutral-400 leading-none mb-1",children:n}),e.jsx("div",{className:"font-mono text-[13.5px] font-semibold leading-none tracking-[-0.01em] text-neutral-950 dark:text-neutral-50 truncate",children:i})]})]}),lt=t=>t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":t.toString(),gr=t=>{const r=typeof t=="string"?parseInt(t,10):t;if(!r||isNaN(r))return"";const n=Math.floor(r/60),i=r%60;return`${n}:${i.toString().padStart(2,"0")}`},Jt=({size:t="md",className:r})=>{const n={sm:"w-4 h-4",md:"w-6 h-6",lg:"w-10 h-10",xl:"w-16 h-16"};return e.jsx("div",{className:ye("relative inline-flex",n[t],r),children:e.jsxs("svg",{className:"animate-spin",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2.5"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})},pr=200*1024*1024,hr=["video/mp4","video/quicktime","video/x-msvideo","video/webm"],fr=({open:t,onClose:r,onUploadComplete:n,initialPlatform:i})=>{const{t:a}=Q("videos"),{account:l}=Ze(),M=i||((l==null?void 0:l.platform)==="instagram"?"instagram":"tiktok"),[b,w]=s.useState(null),[k,y]=s.useState(""),[S,T]=s.useState(""),[I,R]=s.useState(M),[v,u]=s.useState(!1),[d,f]=s.useState(0),[j,L]=s.useState(""),[g,U]=s.useState(!1),[D,F]=s.useState(!1),B=s.useRef(null),H=s.useRef(!1),O=s.useRef(null);Ce.useEffect(()=>{t&&i&&R(i)},[t,i]);const ue=p=>hr.includes(p.type)?p.size>pr?a("videoUploadDialog.errorFileTooLarge",{size:(p.size/(1024*1024)).toFixed(1)}):null:a("videoUploadDialog.errorInvalidFormat"),K=p=>{const W=ue(p);if(W){P.error(W);return}if(w(p),!k){const ge=p.name.replace(/\.[^/.]+$/,"");y(ge.length>
5780?ge.slice(0,80):ge)}},C=p=>{p.preventDefault(),p.stopPropagation(),p.type==="dragenter"||p.type==="dragover"?U(!0):p.type==="dragleave"&&U(!1)},J=p=>{p.preventDefault(),p.stopPropagation(),U(!1),p.dataTransfer.files&&p.dataTransfer.files[0]&&K(p.dataTransfer.files[0])},q=p=>{p.target.files&&p.target.files[0]&&K(p.target.files[0])};s.useEffect(()=>(v&&d===0?O.current=setTimeout(()=>{F(!0)},3e4):(F(!1),O.current&&(clearTimeout(O.current),O.current=null)),()=>{O.current&&clearTimeout(O.current)}),[v,d]);const ee=async()=>{var p;if(!b){P.error(a("videoUploadDialog.errorSelectVideo"));return}try{u(!0),f(0),H.current=!1;const{data:{user:W}}=await Z.auth.getUser();if(!W)throw new Error(a("videoUploadDialog.errorNotLoggedIn"));const pe=((p=(await Z.from("team_members").select("account_owner_id").eq("member_user_id",W.id).eq("status","accepted").maybeSingle()).data)==null?void 0:p.account_owner_id)??W.id,Me=await Ja(b,pe,{title:k,caption:S,platform:I},($,V)=>{H.current||(L($),f(V))});if(H.current)return;P.success(a("videoUploadDialog.uploadSuccess")),n==null||n(Me.uploadedVideo),xe(),r()}catch(W){if(H.current)return;console.error("Upload error:",W);const ge=W instanceof Error?W.message:a("videoUploadDialog.unknownError");P.error(a("videoUploadDialog.uploadErrorPrefix",{msg:ge}))}finally{H.current||u(!1)}},xe=()=>{w(null),y(""),T(""),f(0),L(""),F(!1)},ne=()=>{v?(H.current=!0,u(!1),xe(),P.info(a("videoUploadDialog.uploadCancelled"))):xe(),r()};return e.jsx(Et,{open:t,onOpenChange:ne,children:e.jsxs(Ut,{className:"max-w-2xl w-[calc(100vw-2rem)] max-h-[90vh] overflow-y-auto overflow-x-hidden bg-white dark:bg-neutral-900 dark:bg-white text-gray-900 dark:text-gray-100 dark:text-gray-900 z-[100] mt-20",children:[e.jsxs(zt,{children:[e.jsxs(Lt,{className:"flex items-center gap-2 text-gray-900 dark:text-gray-100",children:[e.jsx(xt,{className:"w-5 h-5 text-gray-900 dark:text-gray-100"}),a("videoUploadDialog.title")]}),e.jsx(Pt,{className:"text-gray-600 dark:text-gray-400",children:a("videoUploadDialog.description")})]}),e.jsxs("div",{className:"space-y-6 py-4 min-w-0",children:[!b&&e.jsxs("div",{className:` 58 border-2 border-dashed rounded-lg p-12 text-center cursor-pointer 59 transition-colors 60 ${g?"border-gray-400 bg-gray-50 dark:bg-neutral-800/50":"border-gray-300 dark:border-neutral-700 hover:border-gray-400"} 61 `,onDragEnter:C,onDragLeave:C,onDragOver:C,onDrop:J,onClick:()=>{var p;return(p=B.current)==null?void 0:p.click()},children:[e.jsx(qt,{className:"w-12 h-12 mx-auto mb-4 text-gray-500 dark:text-gray-400"}),e.jsx("p",{className:"text-lg font-medium mb-2 text-gray-900 dark:text-gray-100",children:a("videoUploadDialog.dropzoneTitle")}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:a("videoUploadDialog.dropzoneFormats")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:a("videoUploadDialog.dropzoneTip")}),e.jsx("input",{ref:B,type:"file",accept:"video/mp4,video/quicktime,video/x-msvideo,video/webm",onChange:q,className:"hidden"})]}),b&&e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-gray-50 dark:bg-neutral-800/50 rounded-lg min-w-0",children:[e.jsx(qt,{className:"w-8 h-8 shrink-0 text-gray-700 dark:text-gray-300"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate text-gray-900 dark:text-gray-100",title:b.name,children:b.name}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:[(b.size/(1024*1024)).toFixed(2)," MB"]})]}),!v&&e.jsx(Ae,{variant:"ghost",size:"icon",className:"shrink-0",onClick:()=>w(null),children:e.jsx(de,{className:"w-4 h-4"})})]}),b&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(bt,{className:"text-gray-900 dark:text-gray-100",children:a("videoUploadDialog.platformLabel")}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:["tiktok","instagram"].map(p=>e.jsxs("button",{type:"button",onClick:()=>R(p),disabled:v,className:`flex items-center justify-center gap-2 rounded-lg border px-4 py-3 text-sm font-semibold transition-all ${I===p?"border-purple-600 bg-purple-50 dark:bg-purple-950/30 text-purple-700 dark:text-purple-200":"border-gray-200 dark:border-neutral-700 text-gray-700 dark:text-gray-300 hover:border-gray-400"}`,children:[e.jsx(ze,{platform:p,size:20}),e.jsx("span",{children:p==="tiktok"?"TikTok":a("videoUploadDialog.platformInstagram")})]},p))}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:a("videoUploadDialog.platformHint")})]}),b&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(bt,{htmlFor:"title",className:"text-gray-900 dark:text-gray-100",children:a("videoUploadDialog.titleLabel")}),e.jsx(Ya,{id:"title",value:k,onChange:p=>y(p.target.value),placeholder:a("videoUploadDialog.titlePlaceholder"),disabled:v,className:"bg-white dark:bg-neutral-900 text-gray-900 dark:text-gray-100 border-gray-300 dark:border-neutral-700"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(bt,{htmlFor:"description",className:"text-gray-900 dark:text-gray-100",children:a("videoUploadDialog.captionLabel")}),e.jsx(Ss,{id:"description",value:S,onChange:p=>T(p.target.value),placeholder:a("videoUploadDialog.captionPlaceholder"),rows:3,disabled:v,className:"bg-white dark:bg-neutral-900 text-gray-900 dark:text-gray-100 border-gray-300 dark:border-neutral-700"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:a("videoUploadDialog.captionHint")})]})]}),v&&e.jsxs("div",{className:"space-y-3 p-4 bg-purple-50 dark:bg-purple-950/40 rounded-lg border border-purple-200 dark:border-purple-900",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{size:"sm",className:"text-purple-600"}),e.jsxs("div",{className:"flex-1 flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:j}),e.jsxs("span",{className:"text-purple-600 font-semibold",children:[d,"%"]})]})]}),e.jsx(zs,{value:d,className:"h-2 [&>div]:bg-purple-600"}),D&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-amber-600",children:[e.jsx(Qa,{className:"w-4 h-4 shrink-0"}),e.jsx("span",{children:a("videoUploadDialog.stuckWarning")})]}),b&&b.size>50*1024*1024&&!D&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:a("videoUploadDialog.largeFileHint")})]}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx(Ae,{variant:"outline",onClick:ne,children:a(v?"videoUploadDialog.cancel":"videoUploadDialog.close")}),e.jsx(Ae,{onClick:ee,disabled:!b||v,className:"bg-purple-600 hover:bg-purple-700 text-white",children:v?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Jt,{size:"sm",className:"text-white"}),a("videoUploadDialog.uploading")]}):a("videoUploadDialog.uploadButton")})]})]})]})})},br=({open:t,onClose:r,onChoose:n})=>{const{t:i}=Q("videos");return e.jsx(Et,{open:t,onOpenChange:a=>!a&&r(),children:e.jsxs(Ut,{className:"max-w-md",children:[e.jsxs(zt,{children:[e.jsx(Lt,{children:i("preUploadPlatformChoice.title")}),e.jsx(Pt,{children:i("preUploadPlatformChoice.description")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mt-2",children:[e.jsxs("button",{type:"button",onClick:()=>
61n("tiktok"),className:"flex flex-col items-center gap-2 p-5 rounded-2xl border border-gray-200 dark:border-neutral-800 hover:border-gray-900 dark:hover:border-neutral-100 hover:bg-gray-50 dark:hover:bg-neutral-800/40 transition-all",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-black flex items-center justify-center",children:e.jsx(ze,{platform:"tiktok",size:28})}),e.jsx("span",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"TikTok"}),e.jsx("span",{className:"text-[11px] text-gray-500 dark:text-gray-400 text-center leading-tight",children:i("preUploadPlatformChoice.tiktokHint")})]}),e.jsxs("button",{type:"button",onClick:()=>n("instagram"),className:"flex flex-col items-center gap-2 p-5 rounded-2xl border border-gray-200 dark:border-neutral-800 hover:border-pink-600 hover:bg-pink-50 dark:hover:bg-pink-950/30 transition-all",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-tr from-purple-500 via-pink-500 to-yellow-500 flex items-center justify-center",children:e.jsx(ze,{platform:"instagram",size:28})}),e.jsx("span",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"Instagram"}),e.jsx("span",{className:"text-[11px] text-gray-500 dark:text-gray-400 text-center leading-tight",children:i("preUploadPlatformChoice.instagramHint")})]})]})]})})},yr=({open:t,onClose:r,onViewAnalysis:n})=>{const{t:i}=Q("videos"),[a,l]=s.useState([]),[M,b]=s.useState(!0),[w,k]=s.useState({});s.useEffect(()=>{t&&T()},[t]);const y=u=>{if(!u.startsWith("http"))return u;const d=u.match(/\/video-frames\/(.+)$/);return d?d[1]:u},S=async u=>{const d={};await Promise.all(u.filter(f=>f.thumbnail_url).map(async f=>{const j=y(f.thumbnail_url),{data:L}=await Z.storage.from("video-frames").createSignedUrl(j,3600);L!=null&&L.signedUrl&&(d[f.id]=L.signedUrl)})),k(d)},T=async()=>{try{b(!0);const{data:u,error:d}=await Z.from("uploaded_videos").select("*").order("created_at",{ascending:!1});if(d)throw d;l(u||[]),u!=null&&u.length&&S(u)}catch(u){console.error("Error fetching uploaded videos:",u),P.error(i("uploadedVideosHistory.toastLoadError"))}finally{b(!1)}},I=async(u,d)=>{if(confirm(i("uploadedVideosHistory.confirmDelete")))try{await ts(u,d),P.success(i("uploadedVideosHistory.toastDeleted")),T()}catch(f){console.error("Error deleting video:",f),P.error(i("uploadedVideosHistory.toastDeleteError"))}},R=u=>{const d=Math.floor(u/60),f=u%60;return`${d}:${f.toString().padStart(2,"0")}`},v=u=>{const d={not_started:{label:i("uploadedVideosHistory.statusNotStarted"),variant:"outline"},processing:{label:i("uploadedVideosHistory.statusProcessing"),variant:"secondary"},completed:{label:i("uploadedVideosHistory.statusCompleted"),variant:"default"},error:{label:i("uploadedVideosHistory.statusError"),variant:"destructive"}},f=d[u]||d.not_started;return e.jsx(va,{variant:f.variant,children:f.label})};return s.useEffect(()=>()=>{document.body.style.pointerEvents=""},[]),s.useEffect(()=>{t||(document.body.style.pointerEvents="")},[t]),e.jsxs(Et,{modal:!1,open:t,onOpenChange:u=>{u||r()},children:[t&&e.jsx("div",{className:"fixed inset-0 z-[100] bg-black/80 animate-in fade-in-0",onClick:()=>r()}),e.jsxs(Ut,{className:"w-[calc(100vw-2rem)] sm:w-[calc(100vw-4rem)] max-w-3xl max-h-[90vh] p-4 sm:p-6 bg-white dark:bg-neutral-900 dark:bg-white text-gray-900 dark:text-gray-100 dark:text-gray-900 z-[9999] mt-20 overflow-hidden",style:{isolation:"isolate"},children:[e.jsxs(zt,{children:[e.jsxs(Lt,{className:"flex items-center gap-2 text-gray-900 dark:text-gray-100",children:[e.jsx(dt,{className:"w-5 h-5 text-gray-900 dark:text-gray-100"}),i("uploadedVideosHistory.dialogTitle")]}),e.jsx(Pt,{className:"text-gray-600 dark:text-gray-400",children:i("uploadedVideosHistory.dialogDescription")})]}),e.jsx(hs,{className:"h-[calc(90vh-8rem)] -mr-2 sm:-mr-3",children:e.jsx("div",{className:"pr-2 sm:pr-4",children:M?e.jsx("div",{className:"space-y-4",children:[1,2,3].map(u=>e.jsx(Kt,{className:"p-4 bg-white dark:bg-neutral-900 border-gray-200 dark:border-neutral-800",children:e.jsxs("div",{className:"flex gap-4",children:[e.jsx(et,{className:"w-32 h-24 rounded bg-gray-200 dark:bg-neutral-700"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(et,{className:"h-5 w-2/3 bg-gray-200 dark:bg-neutral-700"}),e.jsx(et,{className:"h-4 w-1/2 bg-gray-200 dark:bg-neutral-700"}),e.jsx(et,{className:"h-4 w-1/3 bg-gray-200 dark:bg-neutral-700"})]})]})},u))}):a.length===0?e.jsx(cs,{icon:dt,title:i("uploadedVideosHistory.emptyTitle"),description:i("uploadedVideosHistory.emptyDescription")}):e.jsx("div",{className:"space-y-3",children:a.map(u=>e.jsxs(Kt,{className:"p-3 sm:p-4 bg-white dark:bg-neutral-900 hover:bg-gray-50 dark:hover:bg-neutral-800/50 transition-colors border-gray-200 dark:border-neutral-800",children:[e.jsxs("div",{className:"flex gap-3 sm:gap-4 min-w-0",children:[e.jsx("div",{className:"w-20 h-16 sm:w-32 sm:h-24 bg-gray-100 dark:bg-neutral-800 rounded overflow-hidden flex-shrink-0",children:w[u.id]?e.jsx("img",{src:w[u.id],alt:u.title||"Video",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(ce,{className:"w-8 h-8 text-gray-500 dark:text-gray-400"})})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("h3",{className:"font-semibold truncate text-gray-900 dark:text-gray-100 text-sm sm:text-base",children:u.title}),(()=>{const d=u.platform==="instagram"?"instagram":"tiktok";return e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded-md text-[10px] font-semibold uppercase tracking-wide shrink-0 ${d==="instagram"?"bg-pink-50 dark:bg-pink-950/40 text-pink-700 dark:text-pink-300":"bg-gray-100 dark:bg-neutral-800 text-gray-700 dark:text-gray-300"}`,title:d==="instagram"?"Instagram-Reel":"TikTok-Video",children:[e.jsx(ze,{platform:d,size:10}),d==="instagram"?"IG":"TT"]})})()]}),u.description&&e.jsx("p",{className:"text-xs sm:text-sm text-gray-600 dark:text-gray-400 line-clamp-1 sm:line-clamp-2 mt-1",children:u.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-gray-600 dark:text-gray-400 mt-1",children:[e.jsxs("span",{children:["â±ï¸ ",R(u.duration)]}),e.jsxs("span",{children:["ð ",Xa(new Date(u.created_at),{addSuffix:!0,locale:as})]})]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2 pt-2 border-t border-gray-100 dark:border-neutral-800",children:[e.jsx("span",{children:v(u.analysis_status)}),u.is_deep_analyzed&&e.jsxs(Ae,{size:"sm",variant:"outline",className:"h-7 text-xs px-2 sm:h-8 sm:text-sm sm:px-3",onClick:()=>n==null?void 0:n(aa(u)),children:[e.jsx(ce,{className:"w-3.5 h-3.5 mr-1"}),i("uploadedVideosHistory.viewResults")]}),e.jsxs(Ae,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2 sm:h-8 sm:text-sm sm:px-3 text-red-500 hover:text-red-600",onClick:()=>I(u.id,u.storage_path),children:[e.jsx(es,{className:"w-3.5 h-3.5 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:i("uploadedVideosHistory.delete")})]})]})]},u.id))})})})]})]})},jr=()=>{var u,d;const{t}=Q("team"),[r,n]=s.useState([]),[i,a]=s.useState(!0),[l,M]=s.useState(null),[b,w]=s.useState(null);s.useEffect(()=>{k()},[]);const k=async()=>{try{const{data:{user:f}}=await Z.auth.getUser();if(!f)return;const[j,L]=await Promise.all([Z.from("team_members").select(` 62 *, 63 owner:users!team_members_account_owner_id_fkey(email, full_name)
64 `).eq("member_user_id",f.id).eq("status","pending"),Z.from("team_members").select(` 65 id, 66 owner:users!team_members_account_owner_id_fkey(email, full_name) 67 `).eq("member_user_id",f.id).eq("status","accepted").maybeSingle()]),{data:g}=j,U=L.data;w(U?{owner:U.owner}:null);const D=await Promise.all((g||[]).map(async F=>{const{data:B}=await Z.from("tiktok_accounts_safe").select("handle, display_name").eq("user_id",F.account_owner_id).maybeSingle();return{...F,account:B}}));n(D)}catch(f){console.error("Error loading invitations:",f)}finally{a(!1)}},y=async f=>{M(f);try{const{data:j,error:L}=await Z.from("team_members").update({status:"accepted",accepted_at:new Date().toISOString(),invite_token_hash:null,invite_expires_at:null}).eq("id",f).select("account_owner_id, role").single();if(L)throw L;P.success(t("invitations.accepted")),window.location.reload()}catch(j){console.error("Error accepting invitation:",j),P.error(t("invitations.acceptError"))}finally{M(null)}},S=async f=>{M(f);try{const{error:j}=await Z.from("team_members").delete().eq("id",f);if(j)throw j;P.success(t("invitations.declined")),await k()}catch(j){console.error("Error declining invitation:",j),P.error(t("invitations.declineError"))}finally{M(null)}},T=f=>{switch(f){case"admin":return e.jsx(jt,{className:"w-4 h-4 text-purple-600"});case"editor":return e.jsx(wt,{className:"w-4 h-4 text-blue-600"});case"viewer":return e.jsx(ce,{className:"w-4 h-4 text-gray-600 dark:text-gray-400"});default:return null}},I=f=>{const j={admin:"bg-purple-100 dark:bg-purple-900/40 text-purple-800 border-purple-200 dark:border-purple-900",editor:"bg-blue-100 dark:bg-blue-900/40 text-blue-800 border-blue-200 dark:border-blue-900",viewer:"bg-gray-100 dark:bg-neutral-800 text-gray-800 dark:text-gray-200 border-gray-200 dark:border-neutral-800"};return j[f]||j.viewer};if(i||r.length===0)return null;const R=((u=b==null?void 0:b.owner)==null?void 0:u.full_name)||((d=b==null?void 0:b.owner)==null?void 0:d.email),v=!!R;return e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-950/40 border-2 border-blue-200 dark:border-blue-900 rounded-xl p-6 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/40 rounded-lg",children:e.jsx(Ue,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-gray-100",children:t("invitations.title")}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t("invitations.count",{count:r.length})})]})]}),v&&e.jsxs("div",{className:"mb-4 bg-amber-50 dark:bg-amber-950/40 border border-amber-200 dark:border-amber-900/40 rounded-lg px-4 py-3 text-sm text-amber-800 dark:text-amber-200",children:[e.jsx("strong",{children:t("invitations.inOtherTeam",{name:R})})," ",t("invitations.inOtherTeamHint")]}),e.jsx("div",{className:"space-y-3",children:r.map(f=>{var j,L,g,U;return e.jsx("div",{className:"bg-white dark:bg-neutral-900 rounded-lg p-4 border-2 border-gray-200 dark:border-neutral-800",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:((j=f.owner)==null?void 0:j.full_name)||((L=f.owner)==null?void 0:L.email)}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium border ${I(f.role)}`,children:[T(f.role),f.role]})]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:((g=f.account)==null?void 0:g.display_name)||((U=f.account)==null?void 0:U.handle)||t("invitations.accountFallback")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>y(f.id),disabled:l===f.id||v,className:"p-2 bg-green-100 dark:bg-green-900/40 hover:bg-green-200 text-green-700 rounded-lg transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:v?t("invitations.leaveFirstTitle",{name:R}):t("invitations.acceptTitle"),children:l===f.id?e.jsx(fe,{className:"w-4 h-4 animate-spin"}):e.jsx(kt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>S(f.id),disabled:l===f.id,className:"p-2 bg-red-100 dark:bg-red-900/40 hover:bg-red-200 text-red-700 rounded-lg transition-colors disabled:opacity-50",title:t("invitations.declineTitle"),children:e.jsx(de,{className:"w-4 h-4"})})]})]})},f.id)})})]})},wr={viewer:["view","analyze"],editor:["view","analyze","edit","favorite","compare"],admin:["view","analyze","edit","favorite","compare","delete","invite"]},kr=(t,r,n)=>{var i;return n?r&&((i=wr[r])==null?void 0:i.includes(t))||!1:!0},dl=()=>{const{t}=Q("dashboard"),{account:r,videos:n,userTier:i,refreshAccount:a,refreshVideos:l,setAccount:M,setVideos:b,isTeamMember:w,teamRole:k,accountOwner:y}=Ze(),{startDeepAnalysis:S,isAnalyzing:T,getAnalysisStatus:I}=Qe(),[R,v]=ss(),u=Nt(),d=R.get("video"),f=kr("analyze",k,w),[j,L]=s.useState(!1),g=(r==null?void 0:r.platform)!=="instagram",{hasNewVideos:U,dismiss:D}=xr(!w&&g?r==null?void 0:r.id:void 0),[F,B]=s.useState(""),[H,O]=s.useState(!1),[ue,K]=s.useState(!1),[C,J]=s.useState({}),[q,ee]=s.useState("posted_newest"),[xe,ne]=s.useState("grid"),[p,W]=s.useState(null),[ge,pe]=s.useState(!1),[Me,$]=s.useState(!1),[V,ie]=s.useState(!1),[Te,ke]=s.useState(!1),[mt,he]=s.useState(!1),[Fe,Ie]=s.useState("tiktok"),[ve,je]=s.useState(!1),[oe,Ne]=s.useState(null);s.useState(!1);const[me,Le]=s.useState("all"),[te,Je]=s.useState(0),[X,$e]=s.useState(1/0),[He,Oe]=s.useState(!1),[Ve,Be]=s.useState(""),[Ge,Xe]=s.useState(""),[ut,gt]=s.useState(!1),[pt]=s.useState(new Set),[ht]=s.useState(new Map),[Pe,Ke]=s.useState(40);s.useEffect(()=>{if(!r){const o=setTimeout(()=>{console.log("[Dashboard] Account still null after 2s, retrying refreshAccount..."),a()},2e3);return()=>clearTimeout(o)}},[r,a]),s.useEffect(()=>{(async()=>{var x,h;try{const{data:{user:A}}=await Z.auth.getUser();if(!A||!((h=(x=A.app_metadata)==null?void 0:x.providers)==null?void 0:h.includes("google")))return;(await ns()).conflict&&O(!0)}catch(A){console.error("Account linking check failed:",A)}})()},[]);const c=async()=>{K(!0);const o=await is();o.success?(P.success(t("page.toast.claimSuccess"),{description:t("page.toast.claimSuccessDesc")}),O(!1)):P.error(t("page.toast.claimError"),{description:o.error||t("page.toast.claimErrorDesc")}),K(!1)},m=async()=>{O(!1),await os(),u("/login")};s.useEffect(()=>{const o=()=>{i==="free"?P.error(t("page.toast.uploadProOnly"),{description:t("page.toast.uploadProOnlyDesc")}):he(!0)},x=()=>je(!0);return window.addEventListener("openUploadDialog",o),window.addEventListener("openUploadHistory",x),()=>{window.removeEventListener("openUploadDialog",o),window.removeEventListener("openUploadHistory",x)}},[i]),s.useEffect(()=>{const o=()=>{console.log("Analysis complete, refreshing videos..."),l()};return window.addEventListener("ultimate-analysis-complete",o),window.addEventListener("analysis-complete",o),()=>{window.removeEventListener("ultimate-analysis-complete",o),window.removeEventListener("analysis-complete",o)}},[l]),s.useEffect(()=>{let o=0;const x=()=>
67{if(document.visibilityState!=="visible")return;const A=Date.now();A-o<3e3||(o=A,l())},h=()=>x();return document.addEventListener("visibilitychange",x),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",x),window.removeEventListener("focus",h)}},[l]),s.useEffect(()=>{if(ve||!oe)return;const o=window.setTimeout(()=>{document.body.style.pointerEvents="",W(oe),ie(!0),Ne(null)},150);return()=>window.clearTimeout(o)},[ve,oe]),s.useEffect(()=>{d&&n.length>0&&setTimeout(()=>{const o=document.getElementById(`video-${d}`);o&&(o.scrollIntoView({behavior:"smooth",block:"center"}),o.classList.add("ring-4","ring-purple-500","ring-offset-2"),setTimeout(()=>{o.classList.remove("ring-4","ring-purple-500","ring-offset-2")},2e3)),v({})},500)},[d,n,v]);const _=s.useRef("");s.useEffect(()=>{const o=JSON.stringify({searchQuery:F,filters:C,sortBy:q,filterAnalyzed:me,minViews:te,maxViews:X});_.current&&_.current!==o&&Ke(40),_.current=o},[F,C,q,me,te,X]);const N=s.useMemo(()=>{let o=[...n];if(F){const x=F.toLowerCase().trim();return o=o.map(h=>({...h,relevanceScore:rs(x,h)})),o=o.filter(h=>h.relevanceScore>=30),o.sort((h,A)=>(A.relevanceScore||0)-(h.relevanceScore||0)),o}switch(me==="analyzed"?o=o.filter(x=>x.is_deep_analyzed):me==="not_analyzed"?o=o.filter(x=>!x.is_deep_analyzed):me==="normal_only"?o=o.filter(x=>{var h;return x.is_deep_analyzed&&!((h=x.deep_analysis_data)!=null&&h.extended_retention_analysis)}):me==="ultimate"&&(o=o.filter(x=>{var h;return!!((h=x.deep_analysis_data)!=null&&h.extended_retention_analysis)})),C.minViews>0&&(o=o.filter(x=>x.views>=C.minViews)),C.maxViews<1e6&&(o=o.filter(x=>x.views<=C.maxViews)),(C.minScore>0||C.maxScore<10)&&(o=o.filter(x=>{var A,G;const h=((G=(A=x.deep_analysis_data)==null?void 0:A.viral_score_breakdown)==null?void 0:G.final_viral_score)||0;return h>=C.minScore&&h<=C.maxScore})),C.startDate&&(o=o.filter(x=>{const h=x.posted_at?new Date(x.posted_at):new Date(x.created_at),A=new Date(C.startDate);return A.setHours(0,0,0,0),h>=A})),C.endDate&&(o=o.filter(x=>{const h=x.posted_at?new Date(x.posted_at):new Date(x.created_at),A=new Date(C.endDate);return A.setHours(23,59,59,999),h<=A})),(C.startTime||C.endTime)&&(o=o.filter(x=>{if(!x.posted_at)return!0;const h=new Date(x.posted_at),A=h.getHours()*60+h.getMinutes();if(C.startTime){const[G,z]=C.startTime.split(":").map(Number),se=G*60+z;if(A<se)return!1}if(C.endTime){const[G,z]=C.endTime.split(":").map(Number),se=G*60+z;if(A>se)return!1}return!0})),C.daysOfWeek&&C.daysOfWeek.length>0&&(o=o.filter(x=>{if(!x.posted_at)return!0;const A=(new Date(x.posted_at).getDay()+6)%7;return C.daysOfWeek.includes(A)})),q){case"posted_newest":o.sort((x,h)=>{const A=x.posted_at?new Date(x.posted_at):new Date(x.created_at);return(h.posted_at?new Date(h.posted_at):new Date(h.created_at)).getTime()-A.getTime()});break;case"posted_oldest":o.sort((x,h)=>{const A=x.posted_at?new Date(x.posted_at):new Date(x.created_at),G=h.posted_at?new Date(h.posted_at):new Date(h.created_at);return A.getTime()-G.getTime()});break;case"imported_newest":o.sort((x,h)=>new Date(h.created_at).getTime()-new Date(x.created_at).getTime());break;case"last_analyzed":o.sort((x,h)=>{const A=x.analysis_completed_at?new Date(x.analysis_completed_at).getTime():0;return(h.analysis_completed_at?new Date(h.analysis_completed_at).getTime():0)-A});break;case"most_views":o.sort((x,h)=>h.views-x.views);break;case"most_likes":o.sort((x,h)=>h.likes-x.likes);break;case"least_views":o.sort((x,h)=>x.views-h.views);break;case"highest_score":o.sort((x,h)=>{var A,G,z,se;return(((G=(A=h.deep_analysis_data)==null?void 0:A.viral_score_breakdown)==null?void 0:G.final_viral_score)||0)-(((se=(z=x.deep_analysis_data)==null?void 0:z.viral_score_breakdown)==null?void 0:se.final_viral_score)||0)});break;case"lowest_score":o.sort((x,h)=>{var A,G,z,se;return(((G=(A=x.deep_analysis_data)==null?void 0:A.viral_score_breakdown)==null?void 0:G.final_viral_score)||0)-(((se=(z=h.deep_analysis_data)==null?void 0:z.viral_score_breakdown)==null?void 0:se.final_viral_score)||0)});break;case"best_retention":o.sort((x,h)=>{var A,G,z,se,_e,Se;return(((z=(G=(A=h.deep_analysis_data)==null?void 0:A.extended_retention_analysis)==null?void 0:G.retention_metrics)==null?void 0:z.retention_rate)||0)-(((Se=(_e=(se=x.deep_analysis_data)==null?void 0:se.extended_retention_analysis)==null?void 0:_e.retention_metrics)==null?void 0:Se.retention_rate)||0)});break}return o},[n,F,C,q,me,te,X]);s.useEffect(()=>{const o=()=>{gt(window.scrollY>200)};return window.addEventListener("scroll",o),()=>window.removeEventListener("scroll",o)},[]);const E=()=>{window.scrollTo({top:0,behavior:"smooth"})},ae=async o=>{const x=typeof o=="boolean"?o:!1;if(!r||j)return;const h=r.platform==="instagram";L(!0),P.info(t(h?"page.toast.syncingInstagram":x?"page.toast.syncingFull":"page.toast.syncingTiktok"));try{const A=h?"instagram-sync":"tiktok-sync",G=h?{accountId:r.id,full_sync:x}:{action:"sync",account_id:r.id,full_sync:x},{data:z,error:se}=await Z.functions.invoke(A,{body:G});if(se){let _e=null;const Se=se;try{if(Se!=null&&Se.context&&typeof Se.context.json=="function"){const Ee=await Se.context.json();console.error("[sync] server error body:",Ee),_e=(Ee==null?void 0:Ee.error)||JSON.stringify(Ee).slice(0,500)}}catch(Ee){console.warn("Could not parse error.context.json():",Ee)}throw new Error(_e||se.message||t("page.toast.syncFailed"))}if(z!=null&&z.error){if(!h&&z.reconnect_required){P.error(t("page.toast.tiktokAuthExpired"),{duration:5e3});return}throw new Error(z.error)}console.log("â
Sync completed:",z),await Promise.all([a(),l()]),D(),h&&((z==null?void 0:z.reels_saved)??0)===0?(console.warn("[instagram-sync] 0 reels saved â full server response:",z),console.warn(" stopped_because:",z==null?void 0:z.stopped_because),console.warn(" total_items_received:",z==null?void 0:z.total_items_received),console.warn(" pages_fetched:",z==null?void 0:z.pages_fetched),console.warn(" first_page_top_level_keys:",z
67==null?void 0:z.first_page_top_level_keys),console.warn(" upsert_error:",z==null?void 0:z.upsert_error),P.warning(t("page.toast.syncZeroReels"))):P.success(t("page.toast.syncSuccess"))}catch(A){console.error("Error syncing:",A),P.error(t("page.toast.syncError",{message:A.message||t("page.toast.unknownError")}))}finally{L(!1)}},Y=async(o,x)=>{W(o),x==="analyze"?pe(!0):ie(!0)},re=async()=>{pe(!1),ie(!1),W(null),Ne(null),await l()},le=async o=>{pe(!1),await S(o,()=>{l()})};return e.jsxs(ds,{children:[e.jsxs("div",{className:"space-y-4 lg:space-y-0 lg:grid lg:grid-cols-12 lg:gap-8 xl:gap-12 items-start",children:[e.jsx("div",{className:"lg:hidden",children:e.jsx(Bs,{account:r,isLoading:!1,syncing:j,onRefresh:ae})}),e.jsx("div",{className:"lg:hidden",children:e.jsx(nr,{userTier:i})}),e.jsx("div",{className:"lg:col-span-2 hidden lg:block max-w-[260px]",children:e.jsxs("div",{className:"sticky top-32",children:[w&&y&&e.jsxs("button",{onClick:()=>u("/team"),className:"w-full text-left mb-4 p-3 bg-purple-50 dark:bg-purple-950/40 border-2 border-purple-200 dark:border-purple-900 hover:border-purple-300 dark:hover:border-purple-800 hover:bg-purple-100/60 dark:hover:bg-purple-950/60 rounded-xl transition-colors group",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"w-4 h-4 text-purple-600 dark:text-purple-400"}),e.jsx("span",{className:"text-sm font-semibold text-purple-900 dark:text-purple-200",children:t("page.teamMember")})]}),e.jsx(Ot,{className:"w-4 h-4 text-purple-500 dark:text-purple-400 group-hover:translate-x-0.5 transition-transform"})]}),e.jsxs("p",{className:"text-xs text-purple-700 dark:text-purple-300",children:[t("page.accountOf")," ",e.jsx("span",{className:"font-semibold",children:y.full_name||y.email})]}),e.jsxs("div",{className:"mt-2 inline-flex items-center gap-1 px-2 py-0.5 bg-purple-100 dark:bg-purple-900/40 rounded-md text-xs text-purple-800 dark:text-purple-200",children:[k==="admin"&&e.jsx(jt,{className:"w-3 h-3"}),k==="editor"&&e.jsx(wt,{className:"w-3 h-3"}),k==="viewer"&&e.jsx(ce,{className:"w-3 h-3"}),e.jsx("span",{className:"font-medium capitalize",children:k})]})]}),e.jsx(Vs,{account:r,isLoading:!1,syncing:j,onRefresh:ae,isTeamMember:w})]})}),e.jsxs("div",{className:"lg:col-span-7",children:[e.jsxs("div",{className:"mb-8 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl md:text-4xl font-bold text-gray-900 dark:text-gray-100 mb-2",children:t("page.title")}),e.jsx("p",{className:"text-sm md:text-base text-gray-600 dark:text-gray-400",children:t("page.videosShown",{shown:Math.min(Pe,N.length),total:N.length})})]}),e.jsxs("div",{className:"hidden lg:flex lg:flex-col lg:items-center gap-2 flex-shrink-0",children:[e.jsx($s,{width:"fixed",disabled:i==="free",disabledLabel:t
67("page.uploadDisabledLabel"),onUploadClick:()=>{i==="free"?P.error(t("page.toast.uploadProOnly"),{description:t("page.toast.uploadProOnlyDesc")}):he(!0)}}),e.jsx("button",{onClick:()=>je(!0),className:"text-sm text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors text-center w-full",children:t("page.viewHistory")})]})]}),e.jsx(jr,{}),w&&y&&e.jsx("div",{className:"mb-6 lg:hidden bg-gradient-to-r from-blue-50 to-indigo-50 border-2 border-blue-200 dark:border-blue-900 rounded-2xl p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ue,{className:"w-6 h-6 text-blue-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-bold text-gray-900 dark:text-gray-100",children:t("page.teamMember")}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium ${k==="admin"?"bg-purple-100 dark:bg-purple-900/40 text-purple-800":k==="editor"?"bg-green-100 dark:bg-green-900/40 text-green-800":"bg-blue-100 dark:bg-blue-900/40 text-blue-800"}`,children:[k==="admin"?e.jsx(jt,{className:"w-3 h-3"}):k==="editor"?e.jsx(wt,{className:"w-3 h-3"}):e.jsx(ce,{className:"w-3 h-3"}),k]})]}),e.jsxs("p",{className:"text-sm text-gray-700 dark:text-gray-300 mb-2",children:[t("page.teamBannerSeeing",{platform:(r==null?void 0:r.platform)==="instagram"?"Instagram":"TikTok"})," ",e.jsx("span",{className:"font-semibold",children:y.full_name||y.email})]}),r&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsxs("span",{className:"font-medium",children:[r.platform==="instagram"?"Instagram":"TikTok",":"]}),e.jsxs("span",{className:"truncate",children:["@",r.handle]}),r.display_name&&e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 truncate",children:["⢠",r.display_name]})]})]})]})}),e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ls,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-700 dark:text-gray-300 z-10 pointer-events-none"}),e.jsx("input",{type:"text",placeholder:t("page.searchPlaceholder"),value:F,onChange:o=>B(o.target.value),className:"w-full pl-12 pr-10 py-4 glass-input rounded-2xl text-gray-900 dark:text-gray-100 placeholder-gray-500"}),F&&e.jsx("button",{onClick:()=>B(""),className:"absolute right-3 top-1/2 -translate-y-1/2 p-1 rounded-full hover:bg-gray-200 dark:hover:bg-neutral-700 transition-colors z-10","aria-label":t("page.clearSearch"),children:e.jsx(de,{className:"w-4 h-4 text-gray-500 dark:text-gray-400"})})]})}),e.jsxs("div",{className:"flex items-center justify-between mb-6 md:mb-8 gap-3 md:gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-3 flex-wrap w-full lg:w-auto",children:[e.jsxs("select",{value:q,onChange:o=>ee(o.target.value),className:"flex-1 lg:flex-none px-3 md:px-4 py-2 md:py-2.5 glass-input rounded-lg md:rounded-xl text-xs md:text-sm text-gray-700 dark:text-gray-300",children:[e.jsx("option",{value:"posted_newest",children:t("page.sort.postedNewest")}),e.jsx("option",{value:"last_analyzed",children:t("page.sort.lastAnalyzed")}),e.jsx("option",{value:"most_views",children:t("page.sort.mostViews")}),e.jsx("option",{value:"most_likes",children:t("page.sort.mostLikes")}),e.jsx("option",{value:"highest_score",children:t("page.sort.highestScore")})]}),e.jsxs("select",{value:me,onChange:o=>Le(o.target.value),className:"flex-1 lg:flex-none px-3 md:px-4 py-2 md:py-2.5 glass-input rounded-lg md:rounded-xl text-xs md:text-sm text-gray-700 dark:text-gray-300",children:[e.jsx("option",{value:"all",children:t("page.filterAnalyzed.all")}),e.jsx("option",{value:"analyzed",children:t("page.filterAnalyzed.analyzed")}),(r==null?void 0:r.platform)!=="instagram"&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"normal_only",children:t("page.filterAnalyzed.normalOnly")}),e.jsx("option",{value:"ultimate",children:t("page.filterAnalyzed.ultimate")})]}),e.jsx("option",{value:"not_analyzed",children:t("page.filterAnalyzed.notAnalyzed")})]}),e.jsxs(St,{open:He,onOpenChange:Oe,children:[e.jsx(Ct,{asChild:!0,children:e.jsxs("button",{className:"flex-1 lg:flex-none flex items-center gap-2 px-3 md:px-4 py-2 md:py-2.5 glass-input rounded-lg md:rounded-xl text-xs md:text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-neutral-800/50 transition-colors",children:[e.jsx(ce,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:te===0&&X===1/0?t("page.views.all"):te>0&&X<1/0?`${te>=1e3?`${te/1e3}K`:te} â ${X>=1e6?`${X/1e6}M`:X>
67=1e3?`${X/1e3}K`:X}`:X<1/0?t("page.views.under",{value:X>=1e6?`${X/1e6}M`:X>=1e3?`${X/1e3}K`:X}):`${te>=1e6?`${te/1e6}M`:te>=1e3?`${te/1e3}K`:te}+`}),e.jsx(Ye,{className:"w-3 h-3 opacity-50"})]})}),e.jsx(Dt,{className:"w-64 p-3",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:t("page.views.quickSelect")}),e.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:[{label:t("page.views.presets.all"),min:0,max:1/0},{label:t("page.views.presets.under1k"),min:0,max:1e3},{label:t("page.views.presets.under10k"),min:0,max:1e4},{label:t("page.views.presets.range1k10k"),min:1e3,max:1e4},{label:t("page.views.presets.range10k100k"),min:1e4,max:1e5},{label:t("page.views.presets.plus100k"),min:1e5,max:1/0},{label:t("page.views.presets.plus1m"),min:1e6,max:1/0}].map(o=>e.jsx("button",{onClick:()=>{Je(o.min),$e(o.max),Be(o.min>0?String(o.min):""),Xe(o.max<1/0?String(o.max):""),Oe(!1)},className:`px-2.5 py-1.5 text-xs rounded-lg border transition-colors ${te===o.min&&X===o.max?"bg-primary/10 border-primary text-primary font-medium":"border-gray-200 dark:border-neutral-800 text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-neutral-800/50"}`,children:o.label},o.label))}),e.jsxs("div",{className:"border-t pt-3",children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2",children:t("page.views.customRange")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",inputMode:"numeric",pattern:"[0-9]*",placeholder:t("page.views.from"),value:Ve,onChange:o=>Be(o.target.value),className:"w-full px-2.5 py-1.5 text-base md:text-xs border border-gray-200 dark:border-neutral-800 rounded-lg focus:outline-none focus:ring-1 focus:ring-primary"}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:"â"}),e.jsx("input",{type:"number",inputMode:"numeric",pattern:"[0-9]*",placeholder:t("page.views.to"),value:Ge,onChange:o=>Xe(o.target.value),className:"w-full px-2.5 py-1.5 text-base md:text-xs border border-gray-200 dark:border-neutral-800 rounded-lg focus:outline-none focus:ring-1 focus:ring-primary"})]}),e.jsx("button",{onClick:()=>{const o=Ve?Number(Ve):0,x=Ge?Number(Ge):1/0;Je(o),$e(x),Oe(!1)},className:"w-full mt-2 px-3 py-1.5 text-xs font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90 transition-opacity",children:t("page.views.apply")})]})]})})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 md:gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 md:gap-2 bg-gray-100 dark:bg-neutral-800 rounded-lg md:rounded-xl p-1",children:[e.jsx("button",{onClick:()=>ne("grid"),className:`p-2 md:p-2.5 rounded-md md:rounded-lg transition-all ${xe==="grid"?"bg-white dark:bg-neutral-900 text-gray-900 dark:text-gray-100 shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100"}`,children:e.jsx(Ps,{className:"w-4 h-4 md:w-5 md:h-5"})}),e.jsx("button",{onClick:()=>ne("list"),className:`p-2 md:p-2.5 rounded-md md:rounded-lg transition-all ${xe==="list"?"bg-white dark:bg-neutral-900 text-gray-900 dark:text-gray-100 shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100"}`,children:e.jsx(Us,{className:"w-4 h-4 md:w-5 md:h-5"})})]}),(r==null?void 0:r.platform)==="tiktok"&&e.jsx("button",{onClick:()=>ae(!1),disabled:j,title:t("page.sync24h"),"aria-label":t("page.sync24h"),className:"p-1.5 md:p-2 rounded-md md:rounded-lg text-gray-500 dark:text-gray-500 hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100 dark:hover:bg-neutral-800 transition-all disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:e.jsx(We,{className:`w-3.5 h-3.5 md:w-4 md:h-4 ${j?"animate-spin":""}`})})]})]}),e.jsx("div",{id:"video-list",children:e.jsx(ir,{videos:N.slice(0,Pe),viewMode:xe,isLoading:j,onVideoClick:Y,analyzingVideos:pt,analyzingProgress:ht,canAnalyze:f,newVideoCard:U?e.
67jsx(cr,{viewMode:xe,onSync:()=>ae(),isSyncing:j}):void 0})}),N.length>Pe&&e.jsx("div",{className:"flex justify-center mt-8",children:e.jsx("button",{onClick:()=>Ke(o=>o+40),className:"px-6 py-3 bg-black dark:bg-neutral-100 dark:text-neutral-900 hover:bg-gray-800 dark:hover:bg-neutral-200 text-white font-medium rounded-xl transition-all",children:t("page.loadMore",{count:N.length-Pe})})})]}),e.jsx("div",{className:"lg:col-span-3 hidden lg:block",style:{marginTop:"-1rem"},children:e.jsxs("div",{className:`sticky top-20 space-y-3 ${Me?"z-[60]":""}`,children:[e.jsx(Sa,{onExpandedChange:$}),e.jsxs("button",{onClick:()=>u("/settings?tab=brain"),className:"w-full bg-white dark:bg-neutral-900 rounded-xl p-3 flex items-center gap-3 hover:bg-gray-50 dark:hover:bg-neutral-800/50 transition-all border border-gray-200 dark:border-neutral-800 text-left shadow-sm",children:[e.jsx(ls,{className:"w-5 h-5 text-gray-600 dark:text-gray-400 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:t("page.brain.title")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("page.brain.subtitle")})]}),e.jsx(Ot,{className:"w-4 h-4 text-gray-400 dark:text-gray-500 shrink-0"})]})]})})]}),ge&&p&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm animate-in fade-in duration-200",children:e.jsx("div",{className:"w-full max-w-4xl max-h-[90vh] overflow-auto animate-in zoom-in-95 duration-300",children:e.jsx(ur,{video:p,onClose:re,onComplete:re,onStartBackgroundAnalysis:le,userTier:i})})}),V&&p&&e.jsx(fs,{analysis:p,onClose:re,onDelete:()=>{re(),l()},allUserVideos:n,channelEngagementAvg:(r==null?void 0:r.avg_analysis_engagement)??null,platform:(p==null?void 0:p.platform)==="instagram"||(r==null?void 0:r.platform)==="instagram"&&!(p!=null&&p.platform)?"instagram":"tiktok"}),e.jsx(br,{open:mt,onClose:()=>he(!1),onChoose:o=>{Ie(o),he(!1),ke(!0)}}),e.jsx(fr,{open:Te,onClose:()=>ke(!1),initialPlatform:Fe,onUploadComplete:o=>{l(),W(aa(o)),ie(!0)}}),ve&&e.jsx(yr,{open:ve,onClose:()=>je(!1),onViewAnalysis:o=>{Ne(o),je(!1)}}),ut&&!V&&e.jsx("button",{onClick:E,className:"fixed bottom-24 right-6 lg:right-[23%] p-3 rounded-full bg-black/30 backdrop-blur-sm hover:bg-black/40 transition-all duration-300 animate-fade-in z-50 shadow-lg","aria-label":"Scroll to top",children:e.jsx(Rs,{className:"w-5 h-5 text-white"})}),e.jsx(ca,{open:H,onOpenChange:O,children:e.jsxs(xa,{children:[e.jsxs(ma,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(bs,{className:"h-5 w-5 text-amber-500"}),e.jsx(ua,{children:t("page.claimDialog.title")})]}),e.jsxs(ga,{className:"text-left space-y-2",children:[e.jsx("span",{className:"block",children:t("page.claimDialog.body1")}),e.jsx("span",{className:"block",children:t("page.claimDialog.body2")})]})]}),e.jsxs(pa,{children:[e.jsx(ha,{onClick:m,disabled:ue,children:t("page.claimDialog.cancel")}),e.jsxs(fa,{onClick:c,disabled:ue,children:[ue&&e.jsx(fe,{className:"mr-2 h-4 w-4 animate-spin"}),t("page.claimDialog.confirm")]})]})]})})]})};export{dl as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.