@lovelybunch/api 1.0.75-alpha.4 → 1.0.75-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes/api/v1/ai/index.js +0 -2
- package/dist/routes/api/v1/ai/route.js +105 -241
- package/dist/routes/api/v1/events/status/route.d.ts +1 -1
- package/dist/routes/api/v1/jobs/[id]/run/route.d.ts +2 -2
- package/dist/routes/api/v1/jobs/[id]/runs/[runId]/route.d.ts +2 -2
- package/dist/routes/api/v1/jobs/status/route.d.ts +1 -1
- package/dist/routes/api/v1/proposals/[id]/route.d.ts +8 -8
- package/package.json +6 -4
- package/static/assets/{ActivityPage-BI-4IFaP.js → ActivityPage-6xf2Jxp0.js} +1 -1
- package/static/assets/{AgentDetailPage-eVEOya9x.js → AgentDetailPage-1hbFBTeB.js} +1 -1
- package/static/assets/{AgentEditPage-Ds5XXaak.js → AgentEditPage-qMmg057j.js} +1 -1
- package/static/assets/{AgentsPage-CE59G63x.js → AgentsPage-DyyJrXqo.js} +2 -2
- package/static/assets/{AgentsSettingsPage-uVKYxuov.js → AgentsSettingsPage-Bf61k6i0.js} +2 -2
- package/static/assets/{ApiKeysSettingsPage-CTPK48rU.js → ApiKeysSettingsPage-DlWMBuQb.js} +2 -2
- package/static/assets/{ArchitectureEditPage-Cn4zVbPK.js → ArchitectureEditPage-C6MWFHCp.js} +1 -1
- package/static/assets/{ArchitecturePage-CCocwST0.js → ArchitecturePage-CxQtPG4d.js} +1 -1
- package/static/assets/{AuthSettingsPage-C-nDwiO4.js → AuthSettingsPage-w0blkw8Q.js} +2 -2
- package/static/assets/{CallbackPage-ZcrfbMj2.js → CallbackPage-ByjWTMuG.js} +1 -1
- package/static/assets/{CodePage-DuHcwCCu.js → CodePage-aWl0jKwx.js} +2 -2
- package/static/assets/{CollapsibleSection-DreaKHR1.js → CollapsibleSection-B1AU3exJ.js} +1 -1
- package/static/assets/{DashboardPage-Da0zfmye.js → DashboardPage-CAToLPqr.js} +2 -2
- package/static/assets/{GitPage-DE0oU3cj.js → GitPage-DGjEzIUs.js} +1 -1
- package/static/assets/{GitSettingsPage-DndQUnzg.js → GitSettingsPage-X1GEO1Ti.js} +2 -2
- package/static/assets/{IdentityPage-DD-9upeG.js → IdentityPage-L0foq6qN.js} +3 -3
- package/static/assets/{ImplementationStepsEditor-C3vh3Hc0.js → ImplementationStepsEditor-Dn88eiVP.js} +1 -1
- package/static/assets/IntegrationsSettingsPage-WX1lSaWr.js +1 -0
- package/static/assets/JobDetailPage-CvNs3cEP.js +1 -0
- package/static/assets/KnowledgeDetailPage-DXjmZdQl.js +1 -0
- package/static/assets/KnowledgeEditPage-C70yoVFM.js +1 -0
- package/static/assets/{KnowledgePage-cOsVzN4A.js → KnowledgePage-EUJ9c9By.js} +2 -2
- package/static/assets/{LoginPage-CvVZ8le4.js → LoginPage-Df_q-ACP.js} +1 -1
- package/static/assets/{McpSettingsPage-_q1tdgv0.js → McpSettingsPage-4b5M8tpH.js} +1 -1
- package/static/assets/{NewAgentPage-DIzdUSPb.js → NewAgentPage-BqvZZJmC.js} +1 -1
- package/static/assets/NewKnowledgePage-CqKz6_K-.js +9 -0
- package/static/assets/{NewProposalPage-h91-EksD.js → NewProposalPage-DR9UZich.js} +2 -2
- package/static/assets/{ProjectEditPage-CcwGPvlc.js → ProjectEditPage-5YxG7Xxd.js} +1 -1
- package/static/assets/ProjectPage-BBhGv2fS.js +1 -0
- package/static/assets/{PromptsSettingsPage-BTOf3Xzc.js → PromptsSettingsPage-DLrpZcDA.js} +1 -1
- package/static/assets/ProposalDetailPage-C4tagoNE.js +1 -0
- package/static/assets/ProposalEditPage-Bz-oEsLL.js +1 -0
- package/static/assets/{ProposalsPage-ekrWnqoo.js → ProposalsPage-BKRjNF4y.js} +1 -1
- package/static/assets/{ResourcesPage-90Wdfshd.js → ResourcesPage-BZrToY-V.js} +4 -4
- package/static/assets/{RoleEditPage-DY75XHIO.js → RoleEditPage-C2vWadxy.js} +1 -1
- package/static/assets/{RolePage-CXas69QY.js → RolePage-CE9y3rMd.js} +1 -1
- package/static/assets/{RulesSettingsPage-p6AjPCI0.js → RulesSettingsPage-BidnZaAT.js} +2 -2
- package/static/assets/SchedulePage-DU7ng6Gq.js +4 -0
- package/static/assets/SourceInput-CCa7okhU.js +1 -0
- package/static/assets/{TagInput-Dfue2spU.js → TagInput-Chn207ze.js} +1 -1
- package/static/assets/TerminalPage-CEYgdKT2.js +1 -0
- package/static/assets/{TerminalSessionPage-FueIeaIL.js → TerminalSessionPage-C8YA0AmM.js} +4 -4
- package/static/assets/{UserPreferencesPage-C9yXdIdZ.js → UserPreferencesPage-lPgr1ngr.js} +1 -1
- package/static/assets/{UserSettingsPage-ba7UUKyG.js → UserSettingsPage-ctHFqz6e.js} +1 -1
- package/static/assets/{UtilitiesPage-5Zot5Svs.js → UtilitiesPage-BVxyh0Ce.js} +1 -1
- package/static/assets/{alert-BhJUdRgG.js → alert-D5jzRTa5.js} +1 -1
- package/static/assets/{arrow-down-BYk0k85B.js → arrow-down-4I_8gyhd.js} +1 -1
- package/static/assets/{arrow-left-TQT21N4S.js → arrow-left-DZzHrGWA.js} +1 -1
- package/static/assets/{arrow-up-BkSi1XTr.js → arrow-up-B4VxSS3_.js} +1 -1
- package/static/assets/{badge-DS8SPg0q.js → badge-DvLOhob-.js} +1 -1
- package/static/assets/{browser-modal-CgvW-bbQ.js → browser-modal-DzaD2oDW.js} +2 -2
- package/static/assets/{calendar-AzmVUvxT.js → calendar-BNe2rz1T.js} +1 -1
- package/static/assets/{card-C4vq6AMz.js → card-BguljVtN.js} +1 -1
- package/static/assets/{chevron-left-CeRwwCqx.js → chevron-left-DZQ_tMvU.js} +1 -1
- package/static/assets/{chevrons-up-BdEukQhU.js → chevrons-up-BCenbxtV.js} +1 -1
- package/static/assets/{circle-alert-C1JRie1k.js → circle-alert-CZtpB74t.js} +1 -1
- package/static/assets/{circle-check-big-CQBGgL4s.js → circle-check-big-CTApxALS.js} +1 -1
- package/static/assets/{circle-check-DxiLNIIS.js → circle-check-hWIEYAMH.js} +1 -1
- package/static/assets/{circle-play-qq_sLPT0.js → circle-play-BF3gDlvZ.js} +1 -1
- package/static/assets/{circle-x-kpttvnBF.js → circle-x-BtYTEkcT.js} +1 -1
- package/static/assets/{clipboard-CBBHo2mi.js → clipboard-B8Tnfm3W.js} +1 -1
- package/static/assets/{clock-Ck6whvmg.js → clock-_sj3uVNp.js} +1 -1
- package/static/assets/{download-Cx4OcU33.js → download-CPGv4d5Q.js} +1 -1
- package/static/assets/external-link-CtxWkvSs.js +6 -0
- package/static/assets/{eye-2CnfcAd3.js → eye-_nXnan_b.js} +1 -1
- package/static/assets/{folder-git-2-CvwpDtwI.js → folder-git-2-C_Zkp5wq.js} +1 -1
- package/static/assets/index-BlLRLvWP.js +462 -0
- package/static/assets/index-DVTgTsDa.css +2 -0
- package/static/assets/{info-BO6_vv66.js → info-fJ-d5-p-.js} +1 -1
- package/static/assets/{label-B-1O5hdX.js → label-PINvlQb-.js} +1 -1
- package/static/assets/{markdown-editor-H-rT6Hat.js → markdown-editor-B7Zxgu1u.js} +1 -1
- package/static/assets/{pause-CW39bpDf.js → pause-C9zNWRax.js} +1 -1
- package/static/assets/{play-Bqd-yHZN.js → play-BpXD0Ub0.js} +1 -1
- package/static/assets/{plus-BWhZkuI2.js → plus-DBJTL6qk.js} +1 -1
- package/static/assets/{radio-group-CHbb2Tdt.js → radio-group-DBaY5DVP.js} +1 -1
- package/static/assets/{refresh-cw-CaOTs34G.js → refresh-cw-SQsUc3_C.js} +1 -1
- package/static/assets/{search-D2duvyuf.js → search-CBNlhD-8.js} +1 -1
- package/static/assets/{switch-BRsOxt7T.js → switch-C3ys7mIF.js} +1 -1
- package/static/assets/{tabs--rTULKlo.js → tabs-BpxOu6UL.js} +1 -1
- package/static/assets/{tag-BQ5pJD32.js → tag-Cu4oj34X.js} +1 -1
- package/static/assets/{terminal-preview-ewZC6O1I.js → terminal-preview-B5-BekLC.js} +1 -1
- package/static/assets/{use-terminal-Cya6EYny.js → use-terminal-CDMgbskg.js} +1 -1
- package/static/assets/{zap-DQNov92q.js → zap-LrtVPxxV.js} +1 -1
- package/static/index.html +2 -2
- package/static/assets/IntegrationsSettingsPage-B4J4wDXt.js +0 -1
- package/static/assets/JobDetailPage-tHRLIpQI.js +0 -1
- package/static/assets/KnowledgeDetailPage-Dh315TpW.js +0 -1
- package/static/assets/KnowledgeEditPage-B5bNMMvh.js +0 -1
- package/static/assets/NewKnowledgePage-weR174CB.js +0 -9
- package/static/assets/ProjectPage-D9APD9HG.js +0 -1
- package/static/assets/ProposalDetailPage-DbUTHokj.js +0 -1
- package/static/assets/ProposalEditPage-97pQXtDD.js +0 -1
- package/static/assets/SchedulePage-C-Yevtfw.js +0 -4
- package/static/assets/SourceInput-CLzuDG61.js +0 -1
- package/static/assets/TerminalPage-BbA46X-G.js +0 -1
- package/static/assets/index-C8_b70Ej.css +0 -2
- package/static/assets/index-Df8kpDhM.js +0 -468
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as oe,r as t,j as e,D as pe,b as ge,d as ve,f as je,
|
|
1
|
+
import{c as oe,r as t,j as e,D as pe,b as ge,d as ve,f as je,H as le,S as is,B as R,al as os,n as Ee,a as $e,A as ae,w as ye,h as W,i as B,k as $,l as U,m as G,ag as Oe,x as me,an as ca,ao as da,ap as ua,aq as be,ar as Fe,as as _e,at as ma,au as Bs,av as ha,aw as xa,e as fa,I as We,am as Xe,X as cs,C as $s,F as we,ax as Ze,ay as pa,az as ga,aA as va,a9 as ja,aa as ya,v as ba,ab as wa,ae as Je,g as ds,V as us,aB as Na}from"./index-BlLRLvWP.js";import{C as Ye,b as ms,a as Qe,c as _a,d as Sa}from"./card-BguljVtN.js";import{L as C}from"./label-PINvlQb-.js";import{B as Me}from"./badge-DvLOhob-.js";import{c as Ca}from"./clipboard-B9ndUJKl.js";import{R as Us}from"./registry-ANRa5WBi.js";import{D as es}from"./download-CPGv4d5Q.js";import{C as zs}from"./chevron-left-DZQ_tMvU.js";import{C as ka}from"./calendar-BNe2rz1T.js";import{T as Pa}from"./tag-Cu4oj34X.js";import{P as hs}from"./plus-DBJTL6qk.js";import{S as Ea}from"./search-CBNlhD-8.js";/**
|
|
2
2
|
* @license lucide-react v0.542.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -48,12 +48,12 @@ import{c as oe,r as t,j as e,D as pe,b as ge,d as ve,f as je,J as le,S as is,B a
|
|
|
48
48
|
*
|
|
49
49
|
* This source code is licensed under the ISC license.
|
|
50
50
|
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const
|
|
51
|
+
*/const Va=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],ys=oe("maximize-2",Va);/**
|
|
52
52
|
* @license lucide-react v0.542.0 - ISC
|
|
53
53
|
*
|
|
54
54
|
* This source code is licensed under the ISC license.
|
|
55
55
|
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
-
*/const
|
|
56
|
+
*/const Oa=[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]],fe=oe("music",Oa);/**
|
|
57
57
|
* @license lucide-react v0.542.0 - ISC
|
|
58
58
|
*
|
|
59
59
|
* This source code is licensed under the ISC license.
|
|
@@ -68,4 +68,4 @@ import{c as oe,r as t,j as e,D as pe,b as ge,d as ve,f as je,J as le,S as is,B a
|
|
|
68
68
|
*
|
|
69
69
|
* This source code is licensed under the ISC license.
|
|
70
70
|
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
-
*/const Ua=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Be=oe("video",Ua);async function qs(l){const c=l.startsWith("http")?l:`${Us}${l}`,n=await fetch(c,{headers:{Accept:"application/json","User-Agent":"coconut-frontend"}});if(!n.ok)throw new Error(`Failed to fetch registry resource: ${n.status}`);return n.json()}async function za(){return qs("/registry/resources/root.json")}async function ws(l){return qs(l)}function Ke(l){if(l)return l.startsWith("http")?l:`${Us}${l}`}function qa({open:l,onOpenChange:c,onSelectExample:n,onCustomizeInAssistant:p}){const[m,u]=t.useState([]),[j,h]=t.useState(!1),[N,P]=t.useState(null),[S,d]=t.useState(null),[x,y]=t.useState(null),[E,w]=t.useState(!1),[b,_]=t.useState(null);t.useEffect(()=>{l&&(h(!0),P(null),d(null),y(null),_(null),za().then(v=>{u(v.elements??[]),v.elements&&v.elements.length>0&&z(v.elements[0])}).catch(v=>{console.error("Failed to load registry resources",v),u([]),P("Failed to load examples from registry")}).finally(()=>h(!1)))},[l]);const z=async v=>{d(v.id),_(null),y(null),w(!0);try{const k=await ws(v.endpoint);y(k)}catch(k){console.error("Failed to load resource detail",k),_("Unable to load details for this example")}finally{w(!1)}},M=()=>{x?.prompt&&(n(x.prompt),c(!1))},T=()=>{x?.prompt&&p&&(p(x.prompt),c(!1))},A=async v=>{if(S===v.id&&x?.prompt){n(x.prompt),c(!1);return}try{const k=await ws(v.endpoint);k.prompt&&(n(k.prompt),c(!1))}catch(k){console.error("Failed to load resource detail",k)}};return e.jsx(pe,{open:l,onOpenChange:c,children:e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Example Prompts"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden relative",children:[e.jsx("div",{className:"h-[40%] min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:E?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading..."]}):b?e.jsx("p",{className:"text-sm text-muted-foreground",children:b}):x?e.jsx("img",{src:Ke(x.imageUrl),alt:x.title,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select an example"})}),e.jsxs("div",{className:"flex-1 min-h-0 border-t flex flex-col",children:[j?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):N?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N}):m.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(is,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-2",children:m.map(v=>e.jsxs("button",{onClick:()=>z(v),onDoubleClick:()=>A(v),className:`w-full text-left p-2 rounded-lg border-2 transition-all flex gap-3 ${S===v.id?"border-primary bg-primary/5":"border-transparent bg-muted/50 hover:bg-muted"}`,children:[v.thumbnailUrl&&e.jsx("img",{src:Ke(v.thumbnailUrl),alt:"",className:"w-12 h-12 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:v.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:v.description})]})]},v.id))})}),e.jsx("div",{className:"p-3 border-t flex-shrink-0",children:e.jsxs(R,{onClick:M,disabled:!x?.prompt||E,className:"w-full",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]}),x&&p&&e.jsx("div",{className:"absolute bottom-16 right-3 z-10",children:e.jsxs(R,{size:"sm",variant:"secondary",onClick:T,children:[e.jsx(Ee,{className:"mr-1.5 h-3.5 w-3.5"}),"Customize"]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsxs("div",{className:"w-[35%] border-r flex flex-col",children:[j?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):N?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N}):m.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(is,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-3",children:m.map(v=>e.jsxs("button",{onClick:()=>z(v),onDoubleClick:()=>A(v),className:`w-full text-left p-3 rounded-lg border-2 transition-all flex gap-3 ${S===v.id?"border-primary bg-primary/5 shadow-sm":"border-transparent bg-muted/50 hover:bg-muted hover:border-muted-foreground/20"}`,children:[v.thumbnailUrl&&e.jsx("img",{src:Ke(v.thumbnailUrl),alt:"",className:"w-16 h-16 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:v.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-1",children:v.description}),v.tags&&v.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[v.tags.slice(0,3).map(k=>e.jsx(Me,{variant:"secondary",className:"text-[10px]",children:k},k)),v.tags.length>3&&e.jsxs(Me,{variant:"outline",className:"text-[10px]",children:["+",v.tags.length-3]})]})]})]},v.id))})}),e.jsx("div",{className:"p-4 border-t flex-shrink-0",children:e.jsxs(R,{onClick:M,disabled:!x?.prompt||E,className:"w-full",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:E?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading details..."]}):b?e.jsx("p",{className:"text-sm text-muted-foreground",children:b}):x?e.jsx("img",{src:Ke(x.imageUrl),alt:x.title,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select an example to preview"})}),x&&e.jsxs("div",{className:"border-t p-4 bg-background flex-shrink-0 max-h-[30%] overflow-y-auto",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2 font-medium",children:"Full Prompt:"}),e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap",children:x.prompt})]}),x&&p&&e.jsx("div",{className:"absolute bottom-4 right-4 z-10",children:e.jsxs(R,{size:"sm",variant:"secondary",onClick:T,children:[e.jsx(Ee,{className:"mr-1.5 h-3.5 w-3.5"}),"Customize in Assistant"]})})]})]})]})})}const Ns="image-generator-settings";function _s(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Oe={"nano-banana-pro":{id:"nano-banana-pro",label:"Nano Banana Pro",replicateId:"google/nano-banana-pro",features:{resolution:!0,outputQuality:!1,quality:!1,goFast:!1,safetyTolerance:!1,matchInputImage:!1,background:!1},resolutionOptions:[{value:"1K",label:"1K"},{value:"2K",label:"2K"},{value:"4K",label:"4K"}],defaults:{resolution:"2K"}},"flux-2-dev":{id:"flux-2-dev",label:"FLUX.2 Dev",replicateId:"black-forest-labs/flux-2-dev",features:{resolution:!1,outputQuality:!0,quality:!1,goFast:!0,safetyTolerance:!1,matchInputImage:!0,background:!1},defaults:{outputQuality:80,goFast:!0}},"flux-2-pro":{id:"flux-2-pro",label:"FLUX.2 Pro",replicateId:"black-forest-labs/flux-2-pro",features:{resolution:!0,outputQuality:!0,quality:!1,goFast:!1,safetyTolerance:!0,matchInputImage:!1,background:!1},resolutionOptions:[{value:"0.5 MP",label:"0.5 MP"},{value:"1 MP",label:"1 MP"},{value:"2 MP",label:"2 MP"},{value:"4 MP",label:"4 MP"}],defaults:{resolution:"2 MP",outputQuality:80,safetyTolerance:2}},"gpt-image-1.5":{id:"gpt-image-1.5",label:"GPT Image 1.5",replicateId:"openai/gpt-image-1.5",features:{resolution:!1,outputQuality:!1,quality:!0,goFast:!1,safetyTolerance:!1,matchInputImage:!1,background:!0},aspectRatioOptions:[{value:"1:1",label:"1:1"},{value:"3:2",label:"3:2"},{value:"2:3",label:"2:3"}],defaults:{aspectRatio:"1:1",quality:"high",background:"auto"}}},Ss=Object.values(Oe).map(l=>({value:l.id,label:l.label})),Cs=[{value:"1:1",label:"1:1"},{value:"2:3",label:"2:3"},{value:"3:2",label:"3:2"},{value:"3:4",label:"3:4"},{value:"4:3",label:"4:3"},{value:"4:5",label:"4:5"},{value:"5:4",label:"5:4"},{value:"9:16",label:"9:16"},{value:"16:9",label:"16:9"},{value:"21:9",label:"21:9"}],Ha={value:"match_input_image",label:"Match Input"},ks=[{value:"png",label:"PNG"},{value:"jpg",label:"JPG"},{value:"webp",label:"WebP"}],Ps=[{value:"60",label:"60"},{value:"70",label:"70"},{value:"80",label:"80"},{value:"90",label:"90"},{value:"100",label:"100"}],Es=[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}],Ms=[{value:"auto",label:"Auto"},{value:"transparent",label:"Transparent"},{value:"opaque",label:"Opaque"}],Fs=[{value:"1",label:"1 (Strict)"},{value:"2",label:"2"},{value:"3",label:"3"},{value:"4",label:"4"},{value:"5",label:"5"},{value:"6",label:"6 (Relaxed)"}];function Ja({open:l,onOpenChange:c,onSave:n,onCustomizeInAssistant:p}){const m=a=>a.aspectRatioOptions?a.aspectRatioOptions:a.features.matchInputImage?[Ha,...Cs]:Cs,u=(a,s)=>typeof s!="string"?!1:new Set(m(a).map(f=>f.value)).has(s),h=(()=>{if(typeof window>"u")return null;try{const a=localStorage.getItem(Ns);return a?JSON.parse(a):null}catch{return null}})(),N=h?.model||"nano-banana-pro",P=Oe[N],S=u(P,h?.aspectRatio)?h?.aspectRatio:P.defaults.aspectRatio||"16:9",[d,x]=t.useState(""),[y,E]=t.useState(N),[w,b]=t.useState(S),[_,z]=t.useState(h?.resolution||"2K"),[M,T]=t.useState(h?.outputFormat||"png"),[A,v]=t.useState(h?.outputQuality||"80"),[k,q]=t.useState(h?.quality||"high"),[L,D]=t.useState(h?.goFast??!0),[I,g]=t.useState(h?.safetyTolerance||"2"),[K,Y]=t.useState(h?.background||"auto"),[H,ee]=t.useState(null),[O,V]=t.useState(!1),[Q,o]=t.useState(!1),[te,i]=t.useState([]),[F,se]=t.useState([]),[X,re]=t.useState(!0),[ue,he]=t.useState(!1),[Ie,Re]=t.useState(0),xe=t.useRef(null),{toast:ie}=$e();t.useEffect(()=>{const a={model:y,aspectRatio:w,resolution:_,outputFormat:M,outputQuality:A,quality:k,goFast:L,safetyTolerance:I,background:K};localStorage.setItem(Ns,JSON.stringify(a))},[y,w,_,M,A,k,L,I,K]),t.useEffect(()=>(O?(Re(0),xe.current=setInterval(()=>{Re(a=>a+1)},1e3)):xe.current&&(clearInterval(xe.current),xe.current=null),()=>{xe.current&&clearInterval(xe.current)}),[O]);const J=Oe[y],Ce=m(J),Te=J.resolutionOptions||[];t.useEffect(()=>{const a=Oe[y];a.defaults.resolution&&a.features.resolution&&z(a.defaults.resolution),a.defaults.outputQuality!==void 0&&v(String(a.defaults.outputQuality)),a.defaults.quality!==void 0&&a.features.quality&&q(String(a.defaults.quality)),a.defaults.goFast!==void 0&&D(a.defaults.goFast),a.defaults.safetyTolerance!==void 0&&g(String(a.defaults.safetyTolerance)),a.defaults.background!==void 0&&a.features.background&&Y(String(a.defaults.background)),b(s=>{const r=m(a).map(f=>f.value);return r.includes(s)?s:a.defaults.aspectRatio||r[0]||"16:9"})},[y]),t.useEffect(()=>{l&&ze()},[l]);const ze=async()=>{try{const s=await(await fetch(`${ae}/api/v1/resources`)).json();if(s.success){const r=(s.data||[]).filter(f=>{const Z=f.type==="image/jpeg"||f.name.toLowerCase().endsWith(".jpg")||f.name.toLowerCase().endsWith(".jpeg"),ne=f.type==="image/png"||f.name.toLowerCase().endsWith(".png");return(Z||ne)&&f.thumbnailPath});i(r)}}catch(a){console.error("Failed to fetch image resources:",a)}},ke=async()=>{if(!d.trim()){ie({title:"Prompt required",description:"Please enter a prompt to generate an image",variant:"destructive"});return}V(!0),ee(null);try{const a=X||F.length===0?[]:[...F],s=new AbortController,r=setTimeout(()=>s.abort(),3e5),f=await fetch(`${ae}/api/v1/resources/generate`,{method:"POST",headers:{"Content-Type":"application/json"},signal:s.signal,body:JSON.stringify({prompt:d,model:y,dimensions:w,resolution:J.features.resolution?_:void 0,output_format:M,output_quality:J.features.outputQuality?parseInt(A):void 0,quality:J.features.quality?k:void 0,go_fast:J.features.goFast?L:void 0,safety_tolerance:J.features.safetyTolerance?parseInt(I):void 0,background:J.features.background?K:void 0,image_input:a})});if(clearTimeout(r),f.status===504||f.status===502||f.status===408)throw new Error("Request timed out. The image model may be warming up - please try again.");const Z=f.headers.get("content-type");if(!Z||!Z.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const ne=await f.json();if(!f.ok||!ne.success){const de=ne.error?.message||"Failed to generate image",ce=ne.error?.code==="MISSING_API_TOKEN";throw new Error(ce?"Replicate API token not configured. Please add it in Settings → Integrations.":de)}ee(ne.data.imageUrl),ie({title:"Image generated",description:"Your image has been generated successfully"})}catch(a){console.error("Generation error:",a);const s=a instanceof Error&&a.name==="AbortError",r=s?"Request timed out after 5 minutes. The model may be overloaded - please try again.":a instanceof Error?a.message:"Failed to generate image.",f=s||r.toLowerCase().includes("timeout")||r.toLowerCase().includes("timed out");ie({title:f?"Generation timed out":"Generation failed",description:r,variant:"destructive"})}finally{V(!1)}};t.useEffect(()=>{const a=s=>{l&&(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&(s.preventDefault(),d.trim()&&!O&&!Q&&ke())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[l,d,O,Q]);const De=async()=>{if(H){o(!0);try{await n(H,{prompt:d,model:y}),x(""),E("nano-banana-pro"),b("16:9"),z("2K"),T("png"),v("80"),q("high"),D(!0),g("2"),Y("auto"),ee(null),re(!0),se([]),c(!1)}catch(a){ie({title:"Save failed",description:a instanceof Error?a.message:"Failed to save image. Please try again.",variant:"destructive"})}finally{o(!1)}}},Ge=()=>{!O&&!Q&&c(!1)},Ae=()=>{re(!0),se([])},Le=a=>{X&&re(!1),F.includes(a)?(se(F.filter(s=>s!==a)),F.length===1&&re(!0)):F.length<3?se([...F,a]):ie({title:"Maximum selection",description:"You can only select up to 3 images",variant:"destructive"})},qe=a=>{x(a)},He=a=>{p&&(he(!1),c(!1),p(`"${a}" Please customize this (and respond back just the updated markdown):`))};return e.jsxs(pe,{open:l,onOpenChange:Ge,children:[e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Generate Image"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:O?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):H?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:H,alt:"Generated",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(Ne,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"}),e.jsxs(R,{size:"sm",onClick:()=>he(!0),className:"mt-2",children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"View Examples"]})]})}),e.jsx("div",{className:"border-t bg-background p-2 flex-shrink-0",children:e.jsxs("div",{className:"flex gap-1.5 overflow-x-auto pb-1",children:[e.jsx("button",{onClick:Ae,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${X?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),te.map(a=>{const s=F.includes(a.id);return e.jsx("button",{onClick:()=>Le(a.id),className:`flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${s?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${ae}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[45vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(ye,{id:"prompt-mobile",placeholder:"Describe the image...",value:d,onChange:a=>x(a.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"model-mobile",className:"text-xs",children:"Model"}),e.jsxs(W,{value:y,onValueChange:a=>E(a),children:[e.jsx(B,{id:"model-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ss.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"outputFormat-mobile",className:"text-xs",children:"Format"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{id:"outputFormat-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:ks.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.background&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"background-mobile",className:"text-xs",children:"Background"}),e.jsxs(W,{value:K,onValueChange:Y,children:[e.jsx(B,{id:"background-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ms.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.goFast&&e.jsx("div",{className:"space-y-1 flex flex-col justify-end",children:e.jsxs("div",{className:"flex items-center space-x-2 h-8",children:[e.jsx(Ve,{id:"goFast-mobile",checked:L,onCheckedChange:a=>D(a===!0)}),e.jsx(C,{htmlFor:"goFast-mobile",className:"text-xs cursor-pointer",children:"Go Fast"})]})}),J.features.safetyTolerance&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"safetyTolerance-mobile",className:"text-xs",children:"Safety"}),e.jsxs(W,{value:I,onValueChange:g,children:[e.jsx(B,{id:"safetyTolerance-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Fs.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[J.features.resolution&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"resolution-mobile",className:"text-xs",children:"Resolution"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{id:"resolution-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Te.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"aspectRatio-mobile",className:"text-xs",children:"Ratio"}),e.jsxs(W,{value:w,onValueChange:b,children:[e.jsx(B,{id:"aspectRatio-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ce.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.outputQuality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"outputQuality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{id:"outputQuality-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ps.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.quality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"quality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(W,{value:k,onValueChange:q,children:[e.jsx(B,{id:"quality-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Es.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:ke,disabled:!d.trim()||O||Q,className:"flex-1 h-9",size:"sm",children:O?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(_s,{}),e.jsxs("span",{children:[Ie,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:De,disabled:!H||O||Q,variant:"outline",className:"flex-1 h-9",size:"sm",children:Q?e.jsx(le,{className:"h-4 w-4 animate-spin"}):"Save"})]})]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsx("div",{className:"w-[22%] border-r p-6 overflow-y-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"prompt",children:"Prompt"}),e.jsx(ye,{id:"prompt",placeholder:"Describe the image you want to generate...",value:d,onChange:a=>x(a.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"model",children:"Model"}),e.jsxs(W,{value:y,onValueChange:a=>E(a),children:[e.jsx(B,{id:"model",children:e.jsx($,{})}),e.jsx(U,{children:Ss.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(W,{value:w,onValueChange:b,children:[e.jsx(B,{id:"aspectRatio",children:e.jsx($,{})}),e.jsx(U,{children:Ce.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.resolution&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{id:"resolution",children:e.jsx($,{})}),e.jsx(U,{children:Te.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"outputFormat",children:"Output Format"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{id:"outputFormat",children:e.jsx($,{})}),e.jsx(U,{children:ks.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.background&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"background",children:"Background"}),e.jsxs(W,{value:K,onValueChange:Y,children:[e.jsx(B,{id:"background",children:e.jsx($,{})}),e.jsx(U,{children:Ms.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.outputQuality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"outputQuality",children:"Output Quality"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{id:"outputQuality",children:e.jsx($,{})}),e.jsx(U,{children:Ps.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.quality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"quality",children:"Quality"}),e.jsxs(W,{value:k,onValueChange:q,children:[e.jsx(B,{id:"quality",children:e.jsx($,{})}),e.jsx(U,{children:Es.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.goFast&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"goFast",checked:L,onCheckedChange:a=>D(a===!0)}),e.jsx(C,{htmlFor:"goFast",className:"cursor-pointer",children:"Go Fast"})]}),J.features.safetyTolerance&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"safetyTolerance",children:"Safety Tolerance"}),e.jsxs(W,{value:I,onValueChange:g,children:[e.jsx(B,{id:"safetyTolerance",children:e.jsx($,{})}),e.jsx(U,{children:Fs.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:ke,disabled:!d.trim()||O||Q,className:"w-full",children:O?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(_s,{}),e.jsxs("span",{children:["Generating... ",Ie,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:De,disabled:!H||O||Q,variant:"outline",className:"w-full",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:O?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating image..."})]}):H?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:H,alt:"Generated",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(Ne,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated image will appear here"}),e.jsxs(R,{onClick:()=>he(!0),className:"mt-2",children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"View Examples"]})]})}),e.jsx("div",{className:"border-t bg-background p-4 flex-shrink-0",children:e.jsxs("div",{className:"flex gap-2 overflow-x-auto",children:[e.jsx("button",{onClick:Ae,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${X?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),te.map(a=>{const s=F.includes(a.id);return e.jsx("button",{onClick:()=>Le(a.id),className:`flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${s?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${ae}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})})]})]})]}),e.jsx(qa,{open:ue,onOpenChange:he,onSelectExample:qe,onCustomizeInAssistant:p?He:void 0})]})}var Hs=["PageUp","PageDown"],Js=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Ys={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Se="Slider",[as,Ya,Qa]=ua(Se),[Qs,Et]=da(Se,[Qa]),[Xa,Ue]=Qs(Se),Xs=t.forwardRef((l,c)=>{const{name:n,min:p=0,max:m=100,step:u=1,orientation:j="horizontal",disabled:h=!1,minStepsBetweenThumbs:N=0,defaultValue:P=[p],value:S,onValueChange:d=()=>{},onValueCommit:x=()=>{},inverted:y=!1,form:E,...w}=l,b=t.useRef(new Set),_=t.useRef(0),M=j==="horizontal"?Za:et,[T=[],A]=ca({prop:S,defaultProp:P,onChange:I=>{[...b.current][_.current]?.focus(),d(I)}}),v=t.useRef(T);function k(I){const g=lt(T,I);D(I,g)}function q(I){D(I,_.current)}function L(){const I=v.current[_.current];T[_.current]!==I&&x(T)}function D(I,g,{commit:K}={commit:!1}){const Y=ct(u),H=dt(Math.round((I-p)/u)*u+p,Y),ee=Bs(H,[p,m]);A((O=[])=>{const V=tt(O,ee,g);if(ot(V,N*u)){_.current=V.indexOf(ee);const Q=String(V)!==String(O);return Q&&K&&x(V),Q?V:O}else return O})}return e.jsx(Xa,{scope:l.__scopeSlider,name:n,disabled:h,min:p,max:m,valueIndexToChangeRef:_,thumbs:b.current,values:T,orientation:j,form:E,children:e.jsx(as.Provider,{scope:l.__scopeSlider,children:e.jsx(as.Slot,{scope:l.__scopeSlider,children:e.jsx(M,{"aria-disabled":h,"data-disabled":h?"":void 0,...w,ref:c,onPointerDown:be(w.onPointerDown,()=>{h||(v.current=T)}),min:p,max:m,inverted:y,onSlideStart:h?void 0:k,onSlideMove:h?void 0:q,onSlideEnd:h?void 0:L,onHomeKeyDown:()=>!h&&D(p,0,{commit:!0}),onEndKeyDown:()=>!h&&D(m,T.length-1,{commit:!0}),onStepKeyDown:({event:I,direction:g})=>{if(!h){const H=Hs.includes(I.key)||I.shiftKey&&Js.includes(I.key)?10:1,ee=_.current,O=T[ee],V=u*H*g;D(O+V,ee,{commit:!0})}}})})})})});Xs.displayName=Se;var[Zs,ea]=Qs(Se,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Za=t.forwardRef((l,c)=>{const{min:n,max:p,dir:m,inverted:u,onSlideStart:j,onSlideMove:h,onSlideEnd:N,onStepKeyDown:P,...S}=l,[d,x]=t.useState(null),y=_e(c,M=>x(M)),E=t.useRef(void 0),w=ma(m),b=w==="ltr",_=b&&!u||!b&&u;function z(M){const T=E.current||d.getBoundingClientRect(),A=[0,T.width],k=ls(A,_?[n,p]:[p,n]);return E.current=T,k(M-T.left)}return e.jsx(Zs,{scope:l.__scopeSlider,startEdge:_?"left":"right",endEdge:_?"right":"left",direction:_?1:-1,size:"width",children:e.jsx(sa,{dir:w,"data-orientation":"horizontal",...S,ref:y,style:{...S.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:M=>{const T=z(M.clientX);j?.(T)},onSlideMove:M=>{const T=z(M.clientX);h?.(T)},onSlideEnd:()=>{E.current=void 0,N?.()},onStepKeyDown:M=>{const A=Ys[_?"from-left":"from-right"].includes(M.key);P?.({event:M,direction:A?-1:1})}})})}),et=t.forwardRef((l,c)=>{const{min:n,max:p,inverted:m,onSlideStart:u,onSlideMove:j,onSlideEnd:h,onStepKeyDown:N,...P}=l,S=t.useRef(null),d=_e(c,S),x=t.useRef(void 0),y=!m;function E(w){const b=x.current||S.current.getBoundingClientRect(),_=[0,b.height],M=ls(_,y?[p,n]:[n,p]);return x.current=b,M(w-b.top)}return e.jsx(Zs,{scope:l.__scopeSlider,startEdge:y?"bottom":"top",endEdge:y?"top":"bottom",size:"height",direction:y?1:-1,children:e.jsx(sa,{"data-orientation":"vertical",...P,ref:d,style:{...P.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:w=>{const b=E(w.clientY);u?.(b)},onSlideMove:w=>{const b=E(w.clientY);j?.(b)},onSlideEnd:()=>{x.current=void 0,h?.()},onStepKeyDown:w=>{const _=Ys[y?"from-bottom":"from-top"].includes(w.key);N?.({event:w,direction:_?-1:1})}})})}),sa=t.forwardRef((l,c)=>{const{__scopeSlider:n,onSlideStart:p,onSlideMove:m,onSlideEnd:u,onHomeKeyDown:j,onEndKeyDown:h,onStepKeyDown:N,...P}=l,S=Ue(Se,n);return e.jsx(Fe.span,{...P,ref:c,onKeyDown:be(l.onKeyDown,d=>{d.key==="Home"?(j(d),d.preventDefault()):d.key==="End"?(h(d),d.preventDefault()):Hs.concat(Js).includes(d.key)&&(N(d),d.preventDefault())}),onPointerDown:be(l.onPointerDown,d=>{const x=d.target;x.setPointerCapture(d.pointerId),d.preventDefault(),S.thumbs.has(x)?x.focus():p(d)}),onPointerMove:be(l.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&m(d)}),onPointerUp:be(l.onPointerUp,d=>{const x=d.target;x.hasPointerCapture(d.pointerId)&&(x.releasePointerCapture(d.pointerId),u(d))})})}),aa="SliderTrack",ta=t.forwardRef((l,c)=>{const{__scopeSlider:n,...p}=l,m=Ue(aa,n);return e.jsx(Fe.span,{"data-disabled":m.disabled?"":void 0,"data-orientation":m.orientation,...p,ref:c})});ta.displayName=aa;var ts="SliderRange",na=t.forwardRef((l,c)=>{const{__scopeSlider:n,...p}=l,m=Ue(ts,n),u=ea(ts,n),j=t.useRef(null),h=_e(c,j),N=m.values.length,P=m.values.map(x=>ia(x,m.min,m.max)),S=N>1?Math.min(...P):0,d=100-Math.max(...P);return e.jsx(Fe.span,{"data-orientation":m.orientation,"data-disabled":m.disabled?"":void 0,...p,ref:h,style:{...l.style,[u.startEdge]:S+"%",[u.endEdge]:d+"%"}})});na.displayName=ts;var ns="SliderThumb",la=t.forwardRef((l,c)=>{const n=Ya(l.__scopeSlider),[p,m]=t.useState(null),u=_e(c,h=>m(h)),j=t.useMemo(()=>p?n().findIndex(h=>h.ref.current===p):-1,[n,p]);return e.jsx(st,{...l,ref:u,index:j})}),st=t.forwardRef((l,c)=>{const{__scopeSlider:n,index:p,name:m,...u}=l,j=Ue(ns,n),h=ea(ns,n),[N,P]=t.useState(null),S=_e(c,z=>P(z)),d=N?j.form||!!N.closest("form"):!0,x=ha(N),y=j.values[p],E=y===void 0?0:ia(y,j.min,j.max),w=nt(p,j.values.length),b=x?.[h.size],_=b?rt(b,E,h.direction):0;return t.useEffect(()=>{if(N)return j.thumbs.add(N),()=>{j.thumbs.delete(N)}},[N,j.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[h.startEdge]:`calc(${E}% + ${_}px)`},children:[e.jsx(as.ItemSlot,{scope:l.__scopeSlider,children:e.jsx(Fe.span,{role:"slider","aria-label":l["aria-label"]||w,"aria-valuemin":j.min,"aria-valuenow":y,"aria-valuemax":j.max,"aria-orientation":j.orientation,"data-orientation":j.orientation,"data-disabled":j.disabled?"":void 0,tabIndex:j.disabled?void 0:0,...u,ref:S,style:y===void 0?{display:"none"}:l.style,onFocus:be(l.onFocus,()=>{j.valueIndexToChangeRef.current=p})})}),d&&e.jsx(ra,{name:m??(j.name?j.name+(j.values.length>1?"[]":""):void 0),form:j.form,value:y},p)]})});la.displayName=ns;var at="RadioBubbleInput",ra=t.forwardRef(({__scopeSlider:l,value:c,...n},p)=>{const m=t.useRef(null),u=_e(m,p),j=xa(c);return t.useEffect(()=>{const h=m.current;if(!h)return;const N=window.HTMLInputElement.prototype,S=Object.getOwnPropertyDescriptor(N,"value").set;if(j!==c&&S){const d=new Event("input",{bubbles:!0});S.call(h,c),h.dispatchEvent(d)}},[j,c]),e.jsx(Fe.input,{style:{display:"none"},...n,ref:u,defaultValue:c})});ra.displayName=at;function tt(l=[],c,n){const p=[...l];return p[n]=c,p.sort((m,u)=>m-u)}function ia(l,c,n){const u=100/(n-c)*(l-c);return Bs(u,[0,100])}function nt(l,c){return c>2?`Value ${l+1} of ${c}`:c===2?["Minimum","Maximum"][l]:void 0}function lt(l,c){if(l.length===1)return 0;const n=l.map(m=>Math.abs(m-c)),p=Math.min(...n);return n.indexOf(p)}function rt(l,c,n){const p=l/2,u=ls([0,50],[0,p]);return(p-u(c)*n)*n}function it(l){return l.slice(0,-1).map((c,n)=>l[n+1]-c)}function ot(l,c){if(c>0){const n=it(l);return Math.min(...n)>=c}return!0}function ls(l,c){return n=>{if(l[0]===l[1]||c[0]===c[1])return c[0];const p=(c[1]-c[0])/(l[1]-l[0]);return c[0]+p*(n-l[0])}}function ct(l){return(String(l).split(".")[1]||"").length}function dt(l,c){const n=Math.pow(10,c);return Math.round(l*n)/n}var oa=Xs,ut=ta,mt=na,ht=la;const Pe=t.forwardRef(({className:l,...c},n)=>e.jsxs(oa,{ref:n,className:fa("relative flex w-full touch-none select-none items-center",l),...c,children:[e.jsx(ut,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(mt,{className:"absolute h-full bg-primary"})}),e.jsx(ht,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));Pe.displayName=oa.displayName;const Is="audio-generator-settings";function Rs(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Ts=["English_Trustworth_Man","English_Aussie_Bloke","English_CalmWoman","English_UpsetGirl","English_Gentle-voiced_man","English_Whispering_girl","English_Diligent_Man","English_Graceful_Lady","English_ReservedYoungMan","English_PlayfulGirl","English_ManWithDeepVoice","English_MaturePartner","English_FriendlyPerson","English_MatureBoss","English_Debator","English_LovelyGirl","English_Steadymentor","English_Deep-VoicedGentleman","English_Wiselady","English_CaptivatingStoryteller","English_DecentYoungMan","English_SentimentalLady","English_ImposingManner","English_SadTeen","English_PassionateWarrior","English_WiseScholar","English_Soft-spokenGirl","English_SereneWoman","English_ConfidentWoman","English_PatientMan","English_Comedian","English_BossyLeader","English_Strong-WilledBoy","English_StressedLady","English_AssertiveQueen","English_AnimeCharacter","English_Jovialman","English_WhimsicalGirl","English_Kind-heartedGirl","Chinese (Mandarin)_Reliable_Executive","Chinese (Mandarin)_News_Anchor","Chinese (Mandarin)_Unrestrained_Young_Man","Chinese (Mandarin)_Mature_Woman","Arrogant_Miss","Robot_Armor","Chinese (Mandarin)_Kind-hearted_Antie","Chinese (Mandarin)_Refreshing_Young_Man","Chinese (Mandarin)_HK_Flight_Attendant","Chinese (Mandarin)_Humorous_Elder","Chinese (Mandarin)_Gentleman","Chinese (Mandarin)_Warm_Bestie","Chinese (Mandarin)_Stubborn_Friend","Chinese (Mandarin)_Sweet_Lady","Chinese (Mandarin)_Southern_Young_Man","Chinese (Mandarin)_Wise_Women","Chinese (Mandarin)_Gentle_Youth","Chinese (Mandarin)_Warm_Girl","Chinese (Mandarin)_Male_Announcer","Chinese (Mandarin)_Kind-hearted_Elder","Chinese (Mandarin)_Cute_Spirit","Chinese (Mandarin)_Radio_Host","Chinese (Mandarin)_Lyrical_Voice","Chinese (Mandarin)_Straightforward_Boy","Chinese (Mandarin)_Sincere_Adult","Chinese (Mandarin)_Gentle_Senior","Chinese (Mandarin)_Crisp_Girl","Chinese (Mandarin)_Pure-hearted_Boy","Chinese (Mandarin)_Soft_Girl","Chinese (Mandarin)_IntellectualGirl","Chinese (Mandarin)_Warm_HeartedGirl","Chinese (Mandarin)_Laid_BackGirl","Chinese (Mandarin)_ExplorativeGirl","Chinese (Mandarin)_Warm-HeartedAunt","Chinese (Mandarin)_BashfulGirl","Japanese_IntellectualSenior","Japanese_DecisivePrincess","Japanese_LoyalKnight","Japanese_DominantMan","Japanese_SeriousCommander","Japanese_ColdQueen","Japanese_DependableWoman","Japanese_GentleButler","Japanese_KindLady","Japanese_CalmLady","Japanese_OptimisticYouth","Japanese_GenerousIzakayaOwner","Japanese_SportyStudent","Japanese_InnocentBoy","Japanese_GracefulMaiden","Cantonese_ProfessionalHost(F)","Cantonese_GentleLady","Cantonese_ProfessionalHost(M)","Cantonese_PlayfulMan","Cantonese_CuteGirl","Cantonese_KindWoman","Korean_SweetGirl","Korean_CheerfulBoyfriend","Korean_EnchantingSister","Korean_ShyGirl","Korean_ReliableSister","Korean_StrictBoss","Korean_SassyGirl","Korean_ChildhoodFriendGirl","Korean_PlayboyCharmer","Korean_ElegantPrincess","Korean_BraveFemaleWarrior","Korean_BraveYouth","Korean_CalmLady","Korean_EnthusiasticTeen","Korean_SoothingLady","Korean_IntellectualSenior","Korean_LonelyWarrior","Korean_MatureLady","Korean_InnocentBoy","Korean_CharmingSister","Korean_AthleticStudent","Korean_BraveAdventurer","Korean_CalmGentleman","Korean_WiseElf","Korean_CheerfulCoolJunior","Korean_DecisiveQueen","Korean_ColdYoungMan","Korean_MysteriousGirl","Korean_QuirkyGirl","Korean_ConsiderateSenior","Korean_CheerfulLittleSister","Korean_DominantMan","Korean_AirheadedGirl","Korean_ReliableYouth","Korean_FriendlyBigSister","Korean_GentleBoss","Korean_ColdGirl","Korean_HaughtyLady","Korean_CharmingElderSister","Korean_IntellectualMan","Korean_CaringWoman","Korean_WiseTeacher","Korean_ConfidentBoss","Korean_AthleticGirl","Korean_PossessiveMan","Korean_GentleWoman","Korean_CockyGuy","Korean_ThoughtfulWoman","Korean_OptimisticYouth","Spanish_SereneWoman","Spanish_MaturePartner","Spanish_CaptivatingStoryteller","Spanish_Narrator","Spanish_WiseScholar","Spanish_Kind-heartedGirl","Spanish_DeterminedManager","Spanish_BossyLeader","Spanish_ReservedYoungMan","Spanish_ConfidentWoman","Spanish_ThoughtfulMan","Spanish_Strong-WilledBoy","Spanish_SophisticatedLady","Spanish_RationalMan","Spanish_AnimeCharacter","Spanish_Deep-tonedMan","Spanish_Fussyhostess","Spanish_SincereTeen","Spanish_FrankLady","Spanish_Comedian","Spanish_Debator","Spanish_ToughBoss","Spanish_Wiselady","Spanish_Steadymentor","Spanish_Jovialman","Spanish_SantaClaus","Spanish_Rudolph","Spanish_Intonategirl","Spanish_Arnold","Spanish_Ghost","Spanish_HumorousElder","Spanish_EnergeticBoy","Spanish_WhimsicalGirl","Spanish_StrictBoss","Spanish_ReliableMan","Spanish_SereneElder","Spanish_AngryMan","Spanish_AssertiveQueen","Spanish_CaringGirlfriend","Spanish_PowerfulSoldier","Spanish_PassionateWarrior","Spanish_ChattyGirl","Spanish_RomanticHusband","Spanish_CompellingGirl","Spanish_PowerfulVeteran","Spanish_SensibleManager","Spanish_ThoughtfulLady","Portuguese_SentimentalLady","Portuguese_BossyLeader","Portuguese_Wiselady","Portuguese_Strong-WilledBoy","Portuguese_Deep-VoicedGentleman","Portuguese_UpsetGirl","Portuguese_PassionateWarrior","Portuguese_AnimeCharacter","Portuguese_ConfidentWoman","Portuguese_AngryMan","Portuguese_CaptivatingStoryteller","Portuguese_Godfather","Portuguese_ReservedYoungMan","Portuguese_SmartYoungGirl","Portuguese_Kind-heartedGirl","Portuguese_Pompouslady","Portuguese_Grinch","Portuguese_Debator","Portuguese_SweetGirl","Portuguese_AttractiveGirl","Portuguese_ThoughtfulMan","Portuguese_PlayfulGirl","Portuguese_GorgeousLady","Portuguese_LovelyLady","Portuguese_SereneWoman","Portuguese_SadTeen","Portuguese_MaturePartner","Portuguese_Comedian","Portuguese_NaughtySchoolgirl","Portuguese_Narrator","Portuguese_ToughBoss","Portuguese_Fussyhostess","Portuguese_Dramatist","Portuguese_Steadymentor","Portuguese_Jovialman","Portuguese_CharmingQueen","Portuguese_SantaClaus","Portuguese_Rudolph","Portuguese_Arnold","Portuguese_CharmingSanta","Portuguese_CharmingLady","Portuguese_Ghost","Portuguese_HumorousElder","Portuguese_CalmLeader","Portuguese_GentleTeacher","Portuguese_EnergeticBoy","Portuguese_ReliableMan","Portuguese_SereneElder","Portuguese_GrimReaper","Portuguese_AssertiveQueen","Portuguese_WhimsicalGirl","Portuguese_StressedLady","Portuguese_FriendlyNeighbor","Portuguese_CaringGirlfriend","Portuguese_PowerfulSoldier","Portuguese_FascinatingBoy","Portuguese_RomanticHusband","Portuguese_StrictBoss","Portuguese_InspiringLady","Portuguese_PlayfulSpirit","Portuguese_ElegantGirl","Portuguese_CompellingGirl","Portuguese_PowerfulVeteran","Portuguese_SensibleManager","Portuguese_ThoughtfulLady","Portuguese_TheatricalActor","Portuguese_FragileBoy","Portuguese_ChattyGirl","Portuguese_Conscientiousinstructor","Portuguese_RationalMan","Portuguese_WiseScholar","Portuguese_FrankLady","Portuguese_DeterminedManager","French_Male_Speech_New","French_Female_News Anchor","French_CasualMan","French_MovieLeadFemale","French_FemaleAnchor","French_MaleNarrator","Indonesian_SweetGirl","Indonesian_ReservedYoungMan","Indonesian_CharmingGirl","Indonesian_CalmWoman","Indonesian_ConfidentWoman","Indonesian_CaringMan","Indonesian_BossyLeader","Indonesian_DeterminedBoy","Indonesian_GentleGirl","German_FriendlyMan","German_SweetLady","German_PlayfulMan","Russian_HandsomeChildhoodFriend","Russian_BrightHeroine","Russian_AmbitiousWoman","Russian_ReliableMan","Russian_CrazyQueen","Russian_PessimisticGirl","Russian_AttractiveGuy","Russian_Bad-temperedBoy","Italian_BraveHeroine","Italian_Narrator","Italian_WanderingSorcerer","Italian_DiligentLeader","Dutch_kindhearted_girl","Dutch_bossy_leader","Vietnamese_kindhearted_girl","Arabic_CalmWoman","Arabic_FriendlyGuy","Turkish_CalmWoman","Turkish_Trustworthyman","Ukrainian_CalmWoman"],Ds=[{value:"auto",label:"Auto"},{value:"happy",label:"Happy"},{value:"sad",label:"Sad"},{value:"angry",label:"Angry"},{value:"fearful",label:"Fearful"},{value:"disgusted",label:"Disgusted"},{value:"surprised",label:"Surprised"},{value:"neutral",label:"Neutral"}],Gs=[{value:"English",label:"English"},{value:"Chinese",label:"Chinese"},{value:"Japanese",label:"Japanese"},{value:"Korean",label:"Korean"},{value:"Spanish",label:"Spanish"},{value:"Portuguese",label:"Portuguese"},{value:"French",label:"French"},{value:"Indonesian",label:"Indonesian"},{value:"German",label:"German"},{value:"Russian",label:"Russian"},{value:"Italian",label:"Italian"},{value:"Dutch",label:"Dutch"},{value:"Vietnamese",label:"Vietnamese"},{value:"Arabic",label:"Arabic"},{value:"Turkish",label:"Turkish"},{value:"Ukrainian",label:"Ukrainian"},{value:"Cantonese",label:"Cantonese"}],As=[{value:"mp3",label:"MP3"},{value:"wav",label:"WAV"},{value:"flac",label:"FLAC"}];function xt({open:l,onOpenChange:c,onSave:n}){const m=(()=>{if(typeof window>"u")return null;try{const o=localStorage.getItem(Is);return o?JSON.parse(o):null}catch{return null}})(),[u,j]=t.useState(""),[h,N]=t.useState(m?.voiceId||"English_Trustworth_Man"),[P,S]=t.useState(m?.useCustomVoice||!1),[d,x]=t.useState(m?.customVoiceId||""),[y,E]=t.useState(m?.speed??1),[w,b]=t.useState(m?.pitch??0),[_,z]=t.useState(m?.emotion||"auto"),[M,T]=t.useState(m?.languageBoost||"English"),[A,v]=t.useState(m?.audioFormat||"mp3"),[k,q]=t.useState(null),[L,D]=t.useState(!1),[I,g]=t.useState(!1),[K,Y]=t.useState(0),H=t.useRef(null),{toast:ee}=$e();t.useEffect(()=>{const o={voiceId:h,useCustomVoice:P,customVoiceId:d,speed:y,pitch:w,emotion:_,languageBoost:M,audioFormat:A};localStorage.setItem(Is,JSON.stringify(o))},[h,P,d,y,w,_,M,A]),t.useEffect(()=>(L?(Y(0),H.current=setInterval(()=>{Y(o=>o+1)},1e3)):H.current&&(clearInterval(H.current),H.current=null),()=>{H.current&&clearInterval(H.current)}),[L]);const O=async()=>{if(!u.trim()){ee({title:"Text required",description:"Please enter text to generate audio",variant:"destructive"});return}D(!0),q(null);try{const o=P?d:h,te=new AbortController,i=setTimeout(()=>te.abort(),3e5),F=await fetch(`${ae}/api/v1/resources/generate-audio`,{method:"POST",headers:{"Content-Type":"application/json"},signal:te.signal,body:JSON.stringify({text:u,voice_id:o,speed:y,pitch:w,emotion:_,language_boost:M,audio_format:A})});if(clearTimeout(i),F.status===504||F.status===502||F.status===408)throw new Error("Request timed out. The audio model may be warming up - please try again.");const se=F.headers.get("content-type");if(!se||!se.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const X=await F.json();if(!F.ok||!X.success){const re=X.error?.message||"Failed to generate audio",ue=X.error?.code==="MISSING_API_TOKEN";throw new Error(ue?"Replicate API token not configured. Please add it in Settings → Integrations.":re)}q(X.data.audioUrl),ee({title:"Audio generated",description:"Your audio has been generated successfully"})}catch(o){console.error("Generation error:",o);const te=o instanceof Error&&o.name==="AbortError",i=te?"Request timed out after 5 minutes. The model may be overloaded - please try again.":o instanceof Error?o.message:"Failed to generate audio.",F=te||i.toLowerCase().includes("timeout")||i.toLowerCase().includes("timed out");ee({title:F?"Generation timed out":"Generation failed",description:i,variant:"destructive"})}finally{D(!1)}};t.useEffect(()=>{const o=te=>{l&&(te.metaKey||te.ctrlKey)&&te.key==="Enter"&&(te.preventDefault(),u.trim()&&!L&&!I&&O())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[l,u,L,I]);const V=async()=>{if(k){g(!0);try{await n(k),j(""),N("English_Trustworth_Man"),S(!1),x(""),E(1),b(0),z("auto"),T("English"),v("mp3"),q(null),c(!1)}catch(o){ee({title:"Save failed",description:o instanceof Error?o.message:"Failed to save audio. Please try again.",variant:"destructive"})}finally{g(!1)}}},Q=()=>{!L&&!I&&c(!1)};return e.jsx(pe,{open:l,onOpenChange:Q,children:e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Generate Audio"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:L?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):k?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{className:"h-16 w-16 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-4 bg-muted/50 flex justify-center",children:e.jsx("audio",{src:k,controls:!0,className:"w-full max-w-[90%]",children:"Your browser does not support the audio tag."})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(fe,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"})]})}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[55vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"text-mobile",className:"text-xs",children:"Text"}),e.jsx(ye,{id:"text-mobile",placeholder:"Enter text to convert to speech...",value:u,onChange:o=>j(o.target.value),rows:3,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Voice"}),e.jsxs(W,{value:P?"__custom__":h,onValueChange:o=>{o==="__custom__"?S(!0):(S(!1),N(o))},children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsxs(U,{className:"max-h-60",children:[Ts.map(o=>e.jsx(G,{value:o,className:"text-xs",children:o.replace(/_/g," ")},o)),e.jsx(G,{value:"__custom__",className:"text-xs font-medium",children:"Custom Voice ID..."})]})]}),P&&e.jsx(We,{placeholder:"Enter custom voice ID",value:d,onChange:o=>x(o.target.value),className:"h-8 text-xs mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs",children:["Speed: ",y.toFixed(1),"x"]}),e.jsx(Pe,{value:[y],onValueChange:([o])=>E(o),min:.5,max:2,step:.1,className:"w-full"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs",children:["Pitch: ",w>0?"+":"",w]}),e.jsx(Pe,{value:[w],onValueChange:([o])=>b(o),min:-12,max:12,step:1,className:"w-full"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Emotion"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ds.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Language"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Gs.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Format"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:As.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:O,disabled:!u.trim()||L||I,className:"flex-1 h-9",size:"sm",children:L?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:[K,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:V,disabled:!k||L||I,variant:"outline",className:"flex-1 h-9",size:"sm",children:I?e.jsx(le,{className:"h-4 w-4 animate-spin"}):"Save"})]})]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsx("div",{className:"w-[30%] border-r p-6 overflow-y-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"text",children:"Text"}),e.jsx(ye,{id:"text",placeholder:"Enter text to convert to speech...",value:u,onChange:o=>j(o.target.value),rows:6,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Voice"}),e.jsxs(W,{value:P?"__custom__":h,onValueChange:o=>{o==="__custom__"?S(!0):(S(!1),N(o))},children:[e.jsx(B,{children:e.jsx($,{})}),e.jsxs(U,{className:"max-h-80",children:[Ts.map(o=>e.jsx(G,{value:o,children:o.replace(/_/g," ")},o)),e.jsx(G,{value:"__custom__",className:"font-medium",children:"Custom Voice ID..."})]})]}),P&&e.jsx(We,{placeholder:"Enter custom voice ID",value:d,onChange:o=>x(o.target.value),className:"mt-2"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Speed: ",y.toFixed(1),"x"]}),e.jsx(Pe,{value:[y],onValueChange:([o])=>E(o),min:.5,max:2,step:.1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0.5x"}),e.jsx("span",{children:"2x"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Pitch: ",w>0?"+":"",w]}),e.jsx(Pe,{value:[w],onValueChange:([o])=>b(o),min:-12,max:12,step:1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"-12"}),e.jsx("span",{children:"+12"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Emotion"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:Ds.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Language Boost"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:Gs.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Audio Format"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:As.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:O,disabled:!u.trim()||L||I,className:"w-full",children:L?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:["Generating... ",K,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:V,disabled:!k||L||I,variant:"outline",className:"w-full",children:I?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:L?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating audio..."})]}):k?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{className:"h-24 w-24 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-6 bg-muted/50 flex justify-center",children:e.jsx("audio",{src:k,controls:!0,className:"w-3/4 min-w-[300px]",children:"Your browser does not support the audio tag."})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(fe,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated audio will appear here"})]})})})]})]})})}const Ls="video-generator-settings";function Ks(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Os=[{value:"5",label:"5 seconds"},{value:"8",label:"8 seconds"},{value:"10",label:"10 seconds"}],Vs=[{value:"480p",label:"480p"},{value:"720p",label:"720p"},{value:"1080p",label:"1080p"}],Ws=[{value:"16:9",label:"16:9 (Landscape)"},{value:"9:16",label:"9:16 (Portrait)"},{value:"1:1",label:"1:1 (Square)"}];function ft({open:l,onOpenChange:c,onSave:n}){const m=(()=>{if(typeof window>"u")return null;try{const i=localStorage.getItem(Ls);return i?JSON.parse(i):null}catch{return null}})(),[u,j]=t.useState(""),[h,N]=t.useState(m?.duration||"8"),[P,S]=t.useState(m?.resolution||"720p"),[d,x]=t.useState(m?.aspectRatio||"16:9"),[y,E]=t.useState(m?.generateAudio??!0),[w,b]=t.useState(null),[_,z]=t.useState(null),[M,T]=t.useState(null),[A,v]=t.useState(0),k=t.useRef(null),[q,L]=t.useState(!1),[D,I]=t.useState(!1),[g,K]=t.useState([]),{toast:Y}=$e();t.useEffect(()=>{const i={duration:h,resolution:P,aspectRatio:d,generateAudio:y};localStorage.setItem(Ls,JSON.stringify(i))},[h,P,d,y]),t.useEffect(()=>(q?(v(0),k.current=setInterval(()=>{v(i=>i+1)},1e3)):k.current&&(clearInterval(k.current),k.current=null),()=>{k.current&&clearInterval(k.current)}),[q]),t.useEffect(()=>{l&&H()},[l]);const H=async()=>{try{const F=await(await fetch(`${ae}/api/v1/resources`)).json();if(F.success){const se=(F.data||[]).filter(X=>{const re=X.type==="image/jpeg"||X.name.toLowerCase().endsWith(".jpg")||X.name.toLowerCase().endsWith(".jpeg"),ue=X.type==="image/png"||X.name.toLowerCase().endsWith(".png");return(re||ue)&&X.thumbnailPath});K(se)}}catch(i){console.error("Failed to fetch image resources:",i)}},ee=i=>{i===_?z(null):i===w?(b(null),z(i)):w?z(i):b(i)},O=()=>{b(null),z(null)},V=async()=>{if(!u.trim()){Y({title:"Prompt required",description:"Please enter a prompt to generate a video",variant:"destructive"});return}L(!0),T(null);try{const i=new AbortController,F=setTimeout(()=>i.abort(),3e5),se=await fetch(`${ae}/api/v1/resources/generate-video`,{method:"POST",headers:{"Content-Type":"application/json"},signal:i.signal,body:JSON.stringify({prompt:u,image:w||void 0,last_frame:_||void 0,duration:parseInt(h),resolution:P,aspect_ratio:d,generate_audio:y})});if(clearTimeout(F),se.status===504||se.status===502||se.status===408)throw new Error("Request timed out. The video model may be warming up - please try again.");const X=se.headers.get("content-type");if(!X||!X.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const re=await se.json();if(!se.ok||!re.success){const ue=re.error?.message||"Failed to generate video",he=re.error?.code==="MISSING_API_TOKEN";throw new Error(he?"Replicate API token not configured. Please add it in Settings → Integrations.":ue)}T(re.data.videoUrl),Y({title:"Video generated",description:"Your video has been generated successfully"})}catch(i){console.error("Generation error:",i);const F=i instanceof Error&&i.name==="AbortError",se=F?"Request timed out after 5 minutes. The model may be overloaded - please try again.":i instanceof Error?i.message:"Failed to generate video.",X=F||se.toLowerCase().includes("timeout")||se.toLowerCase().includes("timed out");Y({title:X?"Generation timed out":"Generation failed",description:se,variant:"destructive"})}finally{L(!1)}};t.useEffect(()=>{const i=F=>{l&&(F.metaKey||F.ctrlKey)&&F.key==="Enter"&&(F.preventDefault(),u.trim()&&!q&&!D&&V())};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[l,u,q,D]);const Q=async()=>{if(M){I(!0);try{await n(M),j(""),N("8"),S("720p"),x("16:9"),E(!0),b(null),z(null),T(null),c(!1)}catch(i){Y({title:"Save failed",description:i instanceof Error?i.message:"Failed to save video. Please try again.",variant:"destructive"})}finally{I(!1)}}},o=()=>{!q&&!D&&c(!1)},te=i=>i===w?"start":i===_?"end":null;return e.jsx(pe,{open:l,onOpenChange:o,children:e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Generate Video"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:q?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):M?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:M,controls:!0,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg",children:"Your browser does not support the video tag."})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(Be,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"})]})}),e.jsxs("div",{className:"border-t bg-background p-2 flex-shrink-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2 px-1",children:"Select start and end frames (optional)"}),e.jsxs("div",{className:"flex gap-1.5 overflow-x-auto pb-1",children:[e.jsx("button",{onClick:O,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${!w&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),g.map(i=>{const F=te(i.id);return e.jsxs("button",{onClick:()=>ee(i.id),className:`relative flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${F?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${ae}/api/v1/resources/${i.id}/thumbnail`,alt:i.name,className:"w-full h-full object-cover"}),F&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-green-500 text-white text-[10px] font-medium text-center py-0.5",children:F==="start"?"Start":"End"})]},i.id)})]})]}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[40vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(ye,{id:"prompt-mobile",placeholder:"Describe the video you want to generate...",value:u,onChange:i=>j(i.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Duration"}),e.jsxs(W,{value:h,onValueChange:N,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Os.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Resolution"}),e.jsxs(W,{value:P,onValueChange:S,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Vs.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Ratio"}),e.jsxs(W,{value:d,onValueChange:x,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ws.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"generateAudio-mobile",checked:y,onCheckedChange:i=>E(i===!0)}),e.jsx(C,{htmlFor:"generateAudio-mobile",className:"text-xs cursor-pointer",children:"Generate audio"})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:V,disabled:!u.trim()||q||D,className:"flex-1 h-9",size:"sm",children:q?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{}),e.jsxs("span",{children:[A,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:Q,disabled:!M||q||D,variant:"outline",className:"flex-1 h-9",size:"sm",children:D?e.jsx(le,{className:"h-4 w-4 animate-spin"}):"Save"})]})]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsx("div",{className:"w-[22%] border-r p-6 overflow-y-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"prompt",children:"Prompt"}),e.jsx(ye,{id:"prompt",placeholder:"Describe the video you want to generate...",value:u,onChange:i=>j(i.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"duration",children:"Duration"}),e.jsxs(W,{value:h,onValueChange:N,children:[e.jsx(B,{id:"duration",children:e.jsx($,{})}),e.jsx(U,{children:Os.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(W,{value:P,onValueChange:S,children:[e.jsx(B,{id:"resolution",children:e.jsx($,{})}),e.jsx(U,{children:Vs.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(W,{value:d,onValueChange:x,children:[e.jsx(B,{id:"aspectRatio",children:e.jsx($,{})}),e.jsx(U,{children:Ws.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"generateAudio",checked:y,onCheckedChange:i=>E(i===!0)}),e.jsx(C,{htmlFor:"generateAudio",className:"cursor-pointer",children:"Generate audio"})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:V,disabled:!u.trim()||q||D,className:"w-full",children:q?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{}),e.jsxs("span",{children:["Generating... ",A,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:Q,disabled:!M||q||D,variant:"outline",className:"w-full",children:D?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:q?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating video..."})]}):M?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:M,controls:!0,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg",children:"Your browser does not support the video tag."})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(Be,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated video will appear here"})]})}),e.jsxs("div",{className:"border-t bg-background p-4 flex-shrink-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Select start and end frames (optional)"}),e.jsxs("div",{className:"flex gap-2 overflow-x-auto",children:[e.jsx("button",{onClick:O,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${!w&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),g.map(i=>{const F=te(i.id);return e.jsxs("button",{onClick:()=>ee(i.id),className:`relative flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${F?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${ae}/api/v1/resources/${i.id}/thumbnail`,alt:i.name,className:"w-full h-full object-cover"}),F&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-green-500 text-white text-xs font-medium text-center py-1",children:F==="start"?"Start":"End"})]},i.id)})]})]})]})]})]})})}function pt({open:l,onOpenChange:c,resource:n,onCopyPath:p,onDownload:m,onNavigate:u,canNavigatePrev:j,canNavigateNext:h}){const[N,P]=t.useState(null),[S,d]=t.useState(!1),[x,y]=t.useState(!1);t.useEffect(()=>{y(!1)},[n?.id,l]);const E=n?`${ae}/api/v1/resources/${n.id}`:"",w=n?.type.startsWith("image/")??!1,b=n?n.type==="image/svg+xml"||n.name.toLowerCase().endsWith(".svg"):!1,_=n?n.type==="application/pdf"||n.name.toLowerCase().endsWith(".pdf"):!1,z=n?.type.startsWith("video/")??!1,M=n?.type.startsWith("audio/")??!1,T=n?n.type.startsWith("text/")||n.type==="application/json"||n.type.includes("javascript")||n.type.includes("typescript")||n.type.includes("xml")||n.name.toLowerCase().match(/\.(txt|md|json|js|ts|jsx|tsx|css|html|xml|yaml|yml|log|sh|bash|zsh|fish)$/)!==null:!1,A=n?n.name.toLowerCase().endsWith(".md")||n.name.toLowerCase().endsWith(".markdown"):!1,v=n?n.type==="application/json"||n.name.toLowerCase().endsWith(".json"):!1,k=n?n.type==="text/html"||n.name.toLowerCase().endsWith(".html"):!1;if(t.useEffect(()=>{const g=K=>{if(l){if(K.key==="Escape"){x?y(!1):c(!1);return}if(!x){if(K.key==="ArrowLeft"&&j){K.preventDefault(),u("prev");return}K.key==="ArrowRight"&&h&&(K.preventDefault(),u("next"))}}};if(l)return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[l,c,u,j,h,x]),t.useEffect(()=>{l&&n&&(T||A||v||k)?(d(!0),fetch(E).then(g=>{if(g.ok)return g.text();throw new Error("Failed to load file")}).then(g=>{P(g)}).catch(g=>{console.error("Failed to load text content:",g),P(null)}).finally(()=>{d(!1)})):P(null)},[l,n?.id,T,A,v,k,E]),!n)return null;const q=g=>{if(g===0)return"0 B";const K=1024,Y=["B","KB","MB","GB"],H=Math.floor(Math.log(g)/Math.log(K));return parseFloat((g/Math.pow(K,H)).toFixed(2))+" "+Y[H]},L=g=>new Date(g).toLocaleString(),D=g=>g.startsWith("image/")?e.jsx(Ne,{className:"h-6 w-6"}):g.startsWith("video/")?e.jsx(Be,{className:"h-6 w-6"}):g.startsWith("audio/")?e.jsx(fe,{className:"h-6 w-6"}):g.includes("text")||g.includes("document")||g.includes("code")?e.jsx(we,{className:"h-6 w-6"}):g.includes("json")||g.includes("javascript")||g.includes("typescript")?e.jsx(ss,{className:"h-6 w-6"}):e.jsx(Ze,{className:"h-6 w-6"}),I=()=>{if(b)return e.jsxs(e.Fragment,{children:[e.jsx("img",{src:E,alt:n.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}),e.jsx(R,{variant:"secondary",size:"icon",className:"absolute bottom-3 right-3 h-8 w-8 opacity-70 hover:opacity-100 transition-opacity",onClick:()=>y(!0),children:e.jsx(ys,{className:"h-4 w-4"})})]});if(_)return e.jsx("iframe",{src:E,className:"w-full h-full min-h-[600px] rounded-lg border",title:n.name});if(z)return e.jsx("video",{src:E,controls:!0,className:"max-w-full max-h-full rounded-lg shadow-lg",children:"Your browser does not support the video tag."});if(M)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{className:"h-24 w-24 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-6 bg-muted/30 flex justify-center",children:e.jsx("audio",{src:E,controls:!0,className:"w-3/4 min-w-[300px]",children:"Your browser does not support the audio tag."})})]});if(A&&N!==null)return S?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("div",{className:"w-full h-full overflow-auto p-6 prose prose-sm dark:prose-invert max-w-none",children:e.jsx(pa,{remarkPlugins:[va],rehypePlugins:[ga],children:N})});if(k&&N!==null)return S?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("iframe",{srcDoc:N,className:"w-full h-full min-h-[600px] rounded-lg border",title:n.name,sandbox:"allow-same-origin"});if(v&&N!==null){if(S)return e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})});let g=N;try{const K=JSON.parse(N);g=JSON.stringify(K,null,2)}catch{}return e.jsx("div",{className:"w-full h-full overflow-auto p-6",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-auto",children:e.jsx("code",{children:g})})})}return T&&N!==null?S?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("div",{className:"w-full h-full overflow-auto p-6",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-auto whitespace-pre-wrap",children:e.jsx("code",{children:N})})}):w?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:E,alt:n.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}),e.jsx(R,{variant:"secondary",size:"icon",className:"absolute bottom-3 right-3 h-8 w-8 opacity-70 hover:opacity-100 transition-opacity",onClick:()=>y(!0),children:e.jsx(ys,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[D(n.type),e.jsx("p",{className:"text-sm",children:"Preview not available for this file type"}),e.jsxs(R,{variant:"outline",onClick:()=>m(n),children:[e.jsx(es,{className:"mr-2 h-4 w-4"}),"Download to view"]})]})};return e.jsxs(e.Fragment,{children:[e.jsx(pe,{open:l,onOpenChange:c,children:e.jsxs(ge,{className:"max-w-[90vw] w-[90vw] max-h-[90vh] h-[90vh] p-0 gap-0 flex flex-col [&>button]:hidden",children:[e.jsx(ve,{className:"px-6 pt-6 pb-4 border-b flex-shrink-0",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[D(n.type),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-3",children:[e.jsx(je,{className:"text-xl truncate",children:n.name}),e.jsx("p",{className:"text-sm text-muted-foreground flex-shrink-0",children:n.type})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>p(n),title:"Copy path to clipboard",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>m(n),title:"Download",children:e.jsx(es,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>c(!1),title:"Close",children:e.jsx(cs,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 flex overflow-hidden",children:e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 relative flex items-center justify-center bg-muted/30 p-6 overflow-hidden",children:[j&&e.jsx("button",{type:"button",onClick:()=>u("prev"),className:"absolute left-4 top-1/2 -translate-y-1/2 rounded-full border bg-background/80 p-2 shadow-sm hover:bg-background transition-colors","aria-label":"Previous resource",children:e.jsx(zs,{className:"h-5 w-5"})}),h&&e.jsx("button",{type:"button",onClick:()=>u("next"),className:"absolute right-4 top-1/2 -translate-y-1/2 rounded-full border bg-background/80 p-2 shadow-sm hover:bg-background transition-colors","aria-label":"Next resource",children:e.jsx($s,{className:"h-5 w-5"})}),I()]}),e.jsx("div",{className:"border-t p-6 flex-shrink-0 bg-background",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-x-6 gap-y-2 md:grid-cols-2 text-sm",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(La,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Size:"}),e.jsx("span",{children:q(n.size)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Uploaded:"}),e.jsx("span",{children:L(n.uploadedAt)})]})]}),e.jsx("div",{className:"space-y-2",children:n.metadata.tags&&n.metadata.tags.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pa,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Tags:"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:n.metadata.tags.map(g=>e.jsx(Me,{variant:"secondary",className:"text-xs",children:g},g))})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[n.metadata.description?e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Description:"}),e.jsx("span",{className:"truncate flex-1",title:n.metadata.description,children:n.metadata.description})]}):e.jsx("div",{className:"flex-1"}),n.metadata.generationPrompt&&e.jsxs(R,{size:"sm",className:"h-6 text-xs px-2 flex-shrink-0",onClick:()=>{navigator.clipboard.writeText(n.metadata.generationPrompt||"")},children:[e.jsx(Xe,{className:"h-2.5 w-2.5 mr-1"}),"Copy Prompt"]})]})]})})]})})]})}),x&&(w||b)&&e.jsxs("div",{className:"fixed inset-0 z-[100] bg-black/95 flex items-center justify-center",onClick:()=>y(!1),children:[e.jsx(R,{variant:"ghost",size:"icon",className:"absolute top-4 right-4 h-10 w-10 text-white hover:bg-white/20",onClick:()=>y(!1),children:e.jsx(cs,{className:"h-6 w-6"})}),e.jsx("img",{src:E,alt:n.name,className:"max-w-[95vw] max-h-[95vh] object-contain",onClick:g=>g.stopPropagation()})]})]})}function Mt(){const[l,c]=t.useState([]),[n,p]=t.useState(!0),[m,u]=t.useState(!1),[j,h]=t.useState(""),[N,P]=t.useState(!1),[S,d]=t.useState([]),[x,y]=t.useState(""),[E,w]=t.useState(""),[b,_]=t.useState([]),[z,M]=t.useState(!1),[T,A]=t.useState(!1),[v,k]=t.useState(!1),[q,L]=t.useState(null),[D,I]=t.useState(null),[g,K]=t.useState(null),[Y,H]=t.useState(1),ee=12,O=t.useRef(null),{toast:V}=$e();t.useEffect(()=>{Q()},[]);const Q=async()=>{try{p(!0);const r=await(await fetch(`${ae}/api/v1/resources`)).json();r.success&&c(r.data||[])}catch(s){console.error("Failed to fetch resources:",s)}finally{p(!1)}},o=s=>{s.length!==0&&_(Array.from(s))},te=async()=>{if(b.length!==0){u(!0);try{for(const s of b){const r=new FormData;if(r.append("file",s),r.append("tags",S.join(", ")),r.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:r})).ok)throw new Error("Upload failed")}d([]),y(""),w(""),_([]),P(!1),await Q(),V({title:"Upload successful",description:`${b.length} file(s) uploaded successfully`})}catch(s){console.error("Upload failed:",s),V({title:"Upload failed",description:"Failed to upload files. Please try again.",variant:"destructive"})}finally{u(!1)}}},i=()=>{d([]),y(""),w(""),_([]),P(!1)},F=s=>{if(s.key==="Enter"){s.preventDefault();const r=x.trim();r&&!S.includes(r)&&(d([...S,r]),y(""))}},se=s=>{d(S.filter(r=>r!==s))},X=s=>{_(b.filter((r,f)=>f!==s))},re=async()=>{if(g)try{if((await fetch(`${ae}/api/v1/resources/${g.id}`,{method:"DELETE"})).ok)await Q(),V({title:"Resource deleted",description:`${g.name} has been deleted`});else throw new Error("Delete failed")}catch(s){console.error("Failed to delete resource:",s),V({title:"Delete failed",description:"Failed to delete resource. Please try again.",variant:"destructive"})}finally{K(null)}},ue=async s=>{try{const r=`.nut/resources/files/${s.path}`;await Ca(r),V({title:"Path copied!",description:`Copied ${r} to clipboard`})}catch(r){console.error("Failed to copy path:",r),V({title:"Failed to copy",description:"Unable to copy path to clipboard",variant:"destructive"})}},he=s=>{if(s===0)return"0 B";const r=1024,f=["B","KB","MB","GB"],Z=Math.floor(Math.log(s)/Math.log(r));return parseFloat((s/Math.pow(r,Z)).toFixed(2))+" "+f[Z]},Ie=(s,r)=>{const f=r.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||f.endsWith(".svg")?e.jsx(fs,{className:"h-4 w-4"}):e.jsx(Ne,{className:"h-4 w-4"}):s.startsWith("video/")?e.jsx(gs,{className:"h-4 w-4"}):s.startsWith("audio/")?e.jsx(xs,{className:"h-4 w-4"}):s==="application/pdf"||f.endsWith(".pdf")?e.jsx(we,{className:"h-4 w-4"}):f.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(ss,{className:"h-4 w-4"}):s==="application/json"||f.endsWith(".json")?e.jsx(ps,{className:"h-4 w-4"}):s.includes("spreadsheet")||s.includes("excel")||f.match(/\.(xls|xlsx|csv)$/)?e.jsx(vs,{className:"h-4 w-4"}):s.includes("presentation")||s.includes("powerpoint")||f.match(/\.(ppt|pptx)$/)?e.jsx(bs,{className:"h-4 w-4"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(we,{className:"h-4 w-4"}):s.includes("font")||f.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(js,{className:"h-4 w-4"}):e.jsx(Ze,{className:"h-4 w-4"})},Re=(s,r)=>{const f=r.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||f.endsWith(".svg")?e.jsx(fs,{className:"h-16 w-16"}):e.jsx(Ne,{className:"h-16 w-16"}):s.startsWith("video/")?e.jsx(gs,{className:"h-16 w-16"}):s.startsWith("audio/")?e.jsx(xs,{className:"h-16 w-16"}):s==="application/pdf"||f.endsWith(".pdf")?e.jsx(we,{className:"h-16 w-16"}):f.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(ss,{className:"h-16 w-16"}):s==="application/json"||f.endsWith(".json")?e.jsx(ps,{className:"h-16 w-16"}):s.includes("spreadsheet")||s.includes("excel")||f.match(/\.(xls|xlsx|csv)$/)?e.jsx(vs,{className:"h-16 w-16"}):s.includes("presentation")||s.includes("powerpoint")||f.match(/\.(ppt|pptx)$/)?e.jsx(bs,{className:"h-16 w-16"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(we,{className:"h-16 w-16"}):s.includes("font")||f.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(js,{className:"h-16 w-16"}):e.jsx(Ze,{className:"h-16 w-16"})},xe=s=>{const r=s.name.toLowerCase(),f=s.type.startsWith("image/");return s.type==="image/svg+xml"||r.endsWith(".svg")?e.jsx("div",{className:"w-full h-32 flex items-center justify-center bg-muted/30 rounded-md border overflow-hidden p-2",children:e.jsx("img",{src:`${ae}/api/v1/resources/${s.id}`,alt:s.name,className:"w-full h-full object-contain"})}):f&&s.thumbnailPath?e.jsx("img",{src:`${ae}/api/v1/resources/${s.id}/thumbnail`,alt:s.name,className:"w-full h-32 object-cover rounded-md border",onError:ne=>{ne.currentTarget.style.display="none"}}):e.jsx("div",{className:"w-full h-32 flex items-center justify-center bg-muted/50 rounded-md border",children:e.jsx("div",{className:"text-muted-foreground",children:Re(s.type,s.name)})})},ie=l.filter(s=>{if(!j)return!0;const r=j.toLowerCase();return s.name.toLowerCase().includes(r)||s.metadata.description?.toLowerCase().includes(r)||s.metadata.tags?.some(f=>f.toLowerCase().includes(r))}),J=Math.ceil(ie.length/ee),Ce=(Y-1)*ee,Te=ie.slice(Ce,Ce+ee);t.useEffect(()=>{H(1)},[j]);const ze=s=>{s.preventDefault(),s.stopPropagation()},ke=s=>{s.preventDefault(),s.stopPropagation(),s.dataTransfer.files&&s.dataTransfer.files.length>0&&o(s.dataTransfer.files)},De=(s,r)=>{if(r.target.closest("button"))return;L(s);const Z=ie.findIndex(ne=>ne.id===s.id);I(Z>=0?Z:null)},Ge=s=>{window.open(`${ae}/api/v1/resources/${s.id}?download=true`)},Ae=async(s,r)=>{u(!0);try{const f=await fetch(s);if(!f.ok)throw new Error("Failed to download generated image");const Z=await f.blob(),ne=`generated-image-${Date.now()}.png`,de=new FormData;de.append("file",Z,ne),de.append("tags",S.join(","));const ce=r?.prompt?`Generated with: "${r.prompt}"${r.model?` (${r.model})`:""}`:E;if(de.append("description",ce),r?.prompt&&de.append("generationPrompt",r.prompt),r?.model&&de.append("generationModel",r.model),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:de})).ok)throw new Error("Upload failed");await Q(),V({title:"Image saved",description:"Generated image has been saved to resources"})}catch(f){throw console.error("Failed to save generated image:",f),V({title:"Save failed",description:f instanceof Error?f.message:"Failed to save generated image",variant:"destructive"}),f}finally{u(!1)}},Le=s=>{window.dispatchEvent(new CustomEvent("customize-prompt-in-assistant",{detail:{prompt:s}}))},qe=async s=>{u(!0);try{const r=await fetch(s);if(!r.ok)throw new Error("Failed to download generated audio");const f=await r.blob();let Z="mp3";const ne=r.headers.get("content-type");ne?.includes("wav")?Z="wav":ne?.includes("flac")?Z="flac":s.includes(".wav")?Z="wav":s.includes(".flac")&&(Z="flac");const de=`generated-audio-${Date.now()}.${Z}`,ce=new FormData;if(ce.append("file",f,de),ce.append("tags",S.join(",")),ce.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:ce})).ok)throw new Error("Upload failed");await Q(),V({title:"Audio saved",description:"Generated audio has been saved to resources"})}catch(r){throw console.error("Failed to save generated audio:",r),V({title:"Save failed",description:r instanceof Error?r.message:"Failed to save generated audio",variant:"destructive"}),r}finally{u(!1)}},He=async s=>{u(!0);try{const r=await fetch(s);if(!r.ok)throw new Error("Failed to download generated video");const f=await r.blob();let Z="mp4";(r.headers.get("content-type")?.includes("webm")||s.includes(".webm"))&&(Z="webm");const de=`generated-video-${Date.now()}.${Z}`,ce=new FormData;if(ce.append("file",f,de),ce.append("tags",S.join(",")),ce.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:ce})).ok)throw new Error("Upload failed");await Q(),V({title:"Video saved",description:"Generated video has been saved to resources"})}catch(r){throw console.error("Failed to save generated video:",r),V({title:"Save failed",description:r instanceof Error?r.message:"Failed to save generated video",variant:"destructive"}),r}finally{u(!1)}},a=s=>{if(D===null)return;const r=s==="next"?D+1:D-1;if(r<0||r>=ie.length)return;const f=ie[r];I(r),L(f)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Resources"}),e.jsx("p",{className:"text-muted-foreground",children:"Upload and generate media assets for your project"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(ja,{children:[e.jsx(ya,{asChild:!0,children:e.jsxs(R,{variant:"outline",size:"sm",children:[e.jsx(Ee,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Generate"}),e.jsx(ba,{className:"h-3 w-3 ml-1 opacity-50"})]})}),e.jsxs(wa,{align:"end",className:"min-w-[var(--radix-dropdown-menu-trigger-width)]",children:[e.jsxs(Je,{onClick:()=>M(!0),children:[e.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Image"]}),e.jsxs(Je,{onClick:()=>A(!0),children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Audio"]}),e.jsxs(Je,{onClick:()=>k(!0),children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Video"]})]})]}),e.jsxs(R,{size:"sm",onClick:()=>P(!N),children:[e.jsx(hs,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Upload Resources"})]})]})]}),e.jsx(pe,{open:N,onOpenChange:s=>!s&&i(),children:e.jsxs(ge,{className:"max-w-2xl",children:[e.jsxs(ve,{children:[e.jsx(je,{children:"Upload Resource"}),e.jsx(ds,{children:"Add files to your project resources"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"border-2 border-dashed border-muted-foreground/25 rounded-lg p-8 text-center cursor-pointer hover:border-muted-foreground/50 transition-colors",onDragOver:ze,onDrop:ke,onClick:()=>O.current?.click(),children:[e.jsx($a,{className:"mx-auto h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"mt-2 text-sm font-medium",children:"Drop files here or click to browse"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Support for images, documents, and other files"})]}),e.jsx("input",{ref:O,type:"file",multiple:!0,className:"hidden",onChange:s=>s.target.files&&o(s.target.files)}),b.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Selected Files (",b.length,")"]}),e.jsx("div",{className:"border rounded-lg p-3 max-h-40 overflow-y-auto space-y-2",children:b.map((s,r)=>e.jsxs("div",{className:"flex items-center justify-between text-sm bg-muted/50 rounded px-3 py-2",children:[e.jsx("span",{className:"truncate flex-1",children:s.name}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>X(r),className:"h-6 w-6 p-0 ml-2",children:e.jsx(us,{className:"h-3 w-3"})})]},r))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"tags",children:"Tags"}),e.jsx(We,{id:"tags",placeholder:"Type a tag and press Enter",value:x,onChange:s=>y(s.target.value),onKeyDown:F}),S.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:S.map(s=>e.jsxs(Me,{variant:"secondary",className:"text-xs",children:[s,e.jsx("button",{type:"button",onClick:()=>se(s),className:"ml-1 hover:text-destructive",children:"×"})]},s))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"description",children:"Description"}),e.jsx(ye,{id:"description",placeholder:"Brief description of this resource...",value:E,onChange:s=>w(s.target.value),rows:3})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:i,disabled:m,children:"Cancel"}),e.jsx(R,{onClick:te,disabled:b.length===0||m,children:m?"Uploading...":`Upload ${b.length>0?`(${b.length})`:""}`})]})]})]})}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs("div",{className:"relative flex-1 w-full",children:[e.jsx(Ea,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(We,{placeholder:"Search resources...",value:j,onChange:s=>h(s.target.value),className:"pl-8"})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:n?Array.from({length:6}).map((s,r)=>e.jsxs(Ye,{className:"animate-pulse",children:[e.jsxs(ms,{children:[e.jsx("div",{className:"h-4 bg-muted rounded w-3/4"}),e.jsx("div",{className:"h-3 bg-muted rounded w-1/2"})]}),e.jsx(Qe,{children:e.jsx("div",{className:"h-20 bg-muted rounded"})})]},r)):ie.length>0?Te.map(s=>e.jsxs(Ye,{className:"hover:shadow-lg hover:bg-muted transition-all cursor-pointer",onClick:r=>De(s,r),children:[e.jsxs(ms,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[Ie(s.type,s.name),e.jsx(_a,{className:"text-sm font-medium truncate",children:s.name})]}),e.jsxs(Sa,{className:"text-xs",children:[he(s.size)," • ",new Date(s.uploadedAt).toLocaleDateString()]}),e.jsxs("div",{className:"flex justify-end space-x-1 mt-2",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),ue(s)},title:"Copy path to clipboard",children:e.jsx(Xe,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),Ge(s)},children:e.jsx(es,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),K(s)},children:e.jsx(us,{className:"h-3 w-3"})})]})]}),e.jsxs(Qe,{className:"pt-0",children:[e.jsx("div",{className:"mb-3",children:xe(s)}),s.metadata.description&&e.jsx("p",{className:"text-sm text-muted-foreground mb-2 line-clamp-2",children:s.metadata.description}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:s.metadata.tags.map(r=>e.jsx(Me,{variant:"secondary",className:"text-xs",children:r},r))})]})]},s.id)):e.jsx("div",{className:"col-span-full",children:e.jsx(Ye,{children:e.jsxs(Qe,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(Na,{className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("h3",{className:"mt-4 text-lg font-semibold",children:"No resources yet"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground text-center max-w-sm",children:"Upload files to get started. Resources can be referenced by LLMs and team members for enhanced context."}),e.jsxs(R,{className:"mt-4",onClick:()=>P(!0),children:[e.jsx(hs,{className:"mr-2 h-4 w-4"}),"Add First Resource"]})]})})})}),ie.length>ee&&e.jsxs("div",{className:"flex items-center justify-center gap-4 pt-4 pb-8",children:[e.jsxs(R,{variant:Y===1?"outline":"default",size:"sm",onClick:()=>H(s=>Math.max(1,s-1)),disabled:Y===1,children:[e.jsx(zs,{className:"h-4 w-4 mr-1"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",Y," of ",J]}),e.jsxs(R,{variant:Y===J?"outline":"default",size:"sm",onClick:()=>H(s=>Math.min(J,s+1)),disabled:Y===J,children:["Next",e.jsx($s,{className:"h-4 w-4 ml-1"})]})]}),m&&e.jsx("div",{className:"fixed bottom-4 right-4 bg-background border rounded-lg shadow-lg p-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-primary"}),e.jsx("span",{className:"text-sm",children:"Uploading files..."})]})}),e.jsx(Ja,{open:z,onOpenChange:M,onSave:Ae,onCustomizeInAssistant:Le}),e.jsx(xt,{open:T,onOpenChange:A,onSave:qe}),e.jsx(ft,{open:v,onOpenChange:k,onSave:He}),e.jsx(pt,{open:!!q,onOpenChange:s=>{s||L(null),s||I(null)},resource:q,onCopyPath:ue,onDownload:Ge,onNavigate:a,canNavigatePrev:D!==null&&D>0,canNavigateNext:D!==null&&D<ie.length-1}),e.jsx(pe,{open:!!g,onOpenChange:s=>!s&&K(null),children:e.jsxs(ge,{className:"max-w-md",children:[e.jsxs(ve,{children:[e.jsx(je,{children:"Delete Resource"}),e.jsxs(ds,{children:["Are you sure you want to delete ",e.jsx("strong",{children:g?.name}),"? This action cannot be undone."]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:()=>K(null),children:"Cancel"}),e.jsx(R,{variant:"destructive",onClick:re,children:"Delete"})]})]})})]})}export{Mt as default};
|
|
71
|
+
*/const Ua=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Be=oe("video",Ua);async function qs(l){const c=l.startsWith("http")?l:`${Us}${l}`,n=await fetch(c,{headers:{Accept:"application/json","User-Agent":"coconut-frontend"}});if(!n.ok)throw new Error(`Failed to fetch registry resource: ${n.status}`);return n.json()}async function za(){return qs("/registry/resources/root.json")}async function ws(l){return qs(l)}function Ke(l){if(l)return l.startsWith("http")?l:`${Us}${l}`}function qa({open:l,onOpenChange:c,onSelectExample:n,onCustomizeInAssistant:p}){const[m,u]=t.useState([]),[j,h]=t.useState(!1),[N,P]=t.useState(null),[S,d]=t.useState(null),[x,y]=t.useState(null),[E,w]=t.useState(!1),[b,_]=t.useState(null);t.useEffect(()=>{l&&(h(!0),P(null),d(null),y(null),_(null),za().then(v=>{u(v.elements??[]),v.elements&&v.elements.length>0&&z(v.elements[0])}).catch(v=>{console.error("Failed to load registry resources",v),u([]),P("Failed to load examples from registry")}).finally(()=>h(!1)))},[l]);const z=async v=>{d(v.id),_(null),y(null),w(!0);try{const k=await ws(v.endpoint);y(k)}catch(k){console.error("Failed to load resource detail",k),_("Unable to load details for this example")}finally{w(!1)}},M=()=>{x?.prompt&&(n(x.prompt),c(!1))},T=()=>{x?.prompt&&p&&(p(x.prompt),c(!1))},A=async v=>{if(S===v.id&&x?.prompt){n(x.prompt),c(!1);return}try{const k=await ws(v.endpoint);k.prompt&&(n(k.prompt),c(!1))}catch(k){console.error("Failed to load resource detail",k)}};return e.jsx(pe,{open:l,onOpenChange:c,children:e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Example Prompts"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden relative",children:[e.jsx("div",{className:"h-[40%] min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:E?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading..."]}):b?e.jsx("p",{className:"text-sm text-muted-foreground",children:b}):x?e.jsx("img",{src:Ke(x.imageUrl),alt:x.title,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select an example"})}),e.jsxs("div",{className:"flex-1 min-h-0 border-t flex flex-col",children:[j?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):N?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N}):m.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(is,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-2",children:m.map(v=>e.jsxs("button",{onClick:()=>z(v),onDoubleClick:()=>A(v),className:`w-full text-left p-2 rounded-lg border-2 transition-all flex gap-3 ${S===v.id?"border-primary bg-primary/5":"border-transparent bg-muted/50 hover:bg-muted"}`,children:[v.thumbnailUrl&&e.jsx("img",{src:Ke(v.thumbnailUrl),alt:"",className:"w-12 h-12 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:v.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:v.description})]})]},v.id))})}),e.jsx("div",{className:"p-3 border-t flex-shrink-0",children:e.jsxs(R,{onClick:M,disabled:!x?.prompt||E,className:"w-full",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]}),x&&p&&e.jsx("div",{className:"absolute bottom-16 right-3 z-10",children:e.jsxs(R,{size:"sm",variant:"secondary",onClick:T,children:[e.jsx(Ee,{className:"mr-1.5 h-3.5 w-3.5"}),"Customize"]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsxs("div",{className:"w-[35%] border-r flex flex-col",children:[j?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):N?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N}):m.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(is,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-3",children:m.map(v=>e.jsxs("button",{onClick:()=>z(v),onDoubleClick:()=>A(v),className:`w-full text-left p-3 rounded-lg border-2 transition-all flex gap-3 ${S===v.id?"border-primary bg-primary/5 shadow-sm":"border-transparent bg-muted/50 hover:bg-muted hover:border-muted-foreground/20"}`,children:[v.thumbnailUrl&&e.jsx("img",{src:Ke(v.thumbnailUrl),alt:"",className:"w-16 h-16 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:v.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-1",children:v.description}),v.tags&&v.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[v.tags.slice(0,3).map(k=>e.jsx(Me,{variant:"secondary",className:"text-[10px]",children:k},k)),v.tags.length>3&&e.jsxs(Me,{variant:"outline",className:"text-[10px]",children:["+",v.tags.length-3]})]})]})]},v.id))})}),e.jsx("div",{className:"p-4 border-t flex-shrink-0",children:e.jsxs(R,{onClick:M,disabled:!x?.prompt||E,className:"w-full",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:E?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading details..."]}):b?e.jsx("p",{className:"text-sm text-muted-foreground",children:b}):x?e.jsx("img",{src:Ke(x.imageUrl),alt:x.title,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select an example to preview"})}),x&&e.jsxs("div",{className:"border-t p-4 bg-background flex-shrink-0 max-h-[30%] overflow-y-auto",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2 font-medium",children:"Full Prompt:"}),e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap",children:x.prompt})]}),x&&p&&e.jsx("div",{className:"absolute bottom-4 right-4 z-10",children:e.jsxs(R,{size:"sm",variant:"secondary",onClick:T,children:[e.jsx(Ee,{className:"mr-1.5 h-3.5 w-3.5"}),"Customize in Assistant"]})})]})]})]})})}const Ns="image-generator-settings";function _s(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Ve={"nano-banana-pro":{id:"nano-banana-pro",label:"Nano Banana Pro",replicateId:"google/nano-banana-pro",features:{resolution:!0,outputQuality:!1,quality:!1,goFast:!1,safetyTolerance:!1,matchInputImage:!1,background:!1},resolutionOptions:[{value:"1K",label:"1K"},{value:"2K",label:"2K"},{value:"4K",label:"4K"}],defaults:{resolution:"2K"}},"flux-2-dev":{id:"flux-2-dev",label:"FLUX.2 Dev",replicateId:"black-forest-labs/flux-2-dev",features:{resolution:!1,outputQuality:!0,quality:!1,goFast:!0,safetyTolerance:!1,matchInputImage:!0,background:!1},defaults:{outputQuality:80,goFast:!0}},"flux-2-pro":{id:"flux-2-pro",label:"FLUX.2 Pro",replicateId:"black-forest-labs/flux-2-pro",features:{resolution:!0,outputQuality:!0,quality:!1,goFast:!1,safetyTolerance:!0,matchInputImage:!1,background:!1},resolutionOptions:[{value:"0.5 MP",label:"0.5 MP"},{value:"1 MP",label:"1 MP"},{value:"2 MP",label:"2 MP"},{value:"4 MP",label:"4 MP"}],defaults:{resolution:"2 MP",outputQuality:80,safetyTolerance:2}},"gpt-image-1.5":{id:"gpt-image-1.5",label:"GPT Image 1.5",replicateId:"openai/gpt-image-1.5",features:{resolution:!1,outputQuality:!1,quality:!0,goFast:!1,safetyTolerance:!1,matchInputImage:!1,background:!0},aspectRatioOptions:[{value:"1:1",label:"1:1"},{value:"3:2",label:"3:2"},{value:"2:3",label:"2:3"}],defaults:{aspectRatio:"1:1",quality:"high",background:"auto"}}},Ss=Object.values(Ve).map(l=>({value:l.id,label:l.label})),Cs=[{value:"1:1",label:"1:1"},{value:"2:3",label:"2:3"},{value:"3:2",label:"3:2"},{value:"3:4",label:"3:4"},{value:"4:3",label:"4:3"},{value:"4:5",label:"4:5"},{value:"5:4",label:"5:4"},{value:"9:16",label:"9:16"},{value:"16:9",label:"16:9"},{value:"21:9",label:"21:9"}],Ha={value:"match_input_image",label:"Match Input"},ks=[{value:"png",label:"PNG"},{value:"jpg",label:"JPG"},{value:"webp",label:"WebP"}],Ps=[{value:"60",label:"60"},{value:"70",label:"70"},{value:"80",label:"80"},{value:"90",label:"90"},{value:"100",label:"100"}],Es=[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}],Ms=[{value:"auto",label:"Auto"},{value:"transparent",label:"Transparent"},{value:"opaque",label:"Opaque"}],Fs=[{value:"1",label:"1 (Strict)"},{value:"2",label:"2"},{value:"3",label:"3"},{value:"4",label:"4"},{value:"5",label:"5"},{value:"6",label:"6 (Relaxed)"}];function Ja({open:l,onOpenChange:c,onSave:n,onCustomizeInAssistant:p}){const m=a=>a.aspectRatioOptions?a.aspectRatioOptions:a.features.matchInputImage?[Ha,...Cs]:Cs,u=(a,s)=>typeof s!="string"?!1:new Set(m(a).map(f=>f.value)).has(s),h=(()=>{if(typeof window>"u")return null;try{const a=localStorage.getItem(Ns);return a?JSON.parse(a):null}catch{return null}})(),N=h?.model||"nano-banana-pro",P=Ve[N],S=u(P,h?.aspectRatio)?h?.aspectRatio:P.defaults.aspectRatio||"16:9",[d,x]=t.useState(""),[y,E]=t.useState(N),[w,b]=t.useState(S),[_,z]=t.useState(h?.resolution||"2K"),[M,T]=t.useState(h?.outputFormat||"png"),[A,v]=t.useState(h?.outputQuality||"80"),[k,q]=t.useState(h?.quality||"high"),[L,D]=t.useState(h?.goFast??!0),[I,g]=t.useState(h?.safetyTolerance||"2"),[K,Y]=t.useState(h?.background||"auto"),[H,ee]=t.useState(null),[V,O]=t.useState(!1),[Q,o]=t.useState(!1),[te,i]=t.useState([]),[F,se]=t.useState([]),[X,re]=t.useState(!0),[ue,he]=t.useState(!1),[Ie,Re]=t.useState(0),xe=t.useRef(null),{toast:ie}=$e();t.useEffect(()=>{const a={model:y,aspectRatio:w,resolution:_,outputFormat:M,outputQuality:A,quality:k,goFast:L,safetyTolerance:I,background:K};localStorage.setItem(Ns,JSON.stringify(a))},[y,w,_,M,A,k,L,I,K]),t.useEffect(()=>(V?(Re(0),xe.current=setInterval(()=>{Re(a=>a+1)},1e3)):xe.current&&(clearInterval(xe.current),xe.current=null),()=>{xe.current&&clearInterval(xe.current)}),[V]);const J=Ve[y],Ce=m(J),Te=J.resolutionOptions||[];t.useEffect(()=>{const a=Ve[y];a.defaults.resolution&&a.features.resolution&&z(a.defaults.resolution),a.defaults.outputQuality!==void 0&&v(String(a.defaults.outputQuality)),a.defaults.quality!==void 0&&a.features.quality&&q(String(a.defaults.quality)),a.defaults.goFast!==void 0&&D(a.defaults.goFast),a.defaults.safetyTolerance!==void 0&&g(String(a.defaults.safetyTolerance)),a.defaults.background!==void 0&&a.features.background&&Y(String(a.defaults.background)),b(s=>{const r=m(a).map(f=>f.value);return r.includes(s)?s:a.defaults.aspectRatio||r[0]||"16:9"})},[y]),t.useEffect(()=>{l&&ze()},[l]);const ze=async()=>{try{const s=await(await fetch(`${ae}/api/v1/resources`)).json();if(s.success){const r=(s.data||[]).filter(f=>{const Z=f.type==="image/jpeg"||f.name.toLowerCase().endsWith(".jpg")||f.name.toLowerCase().endsWith(".jpeg"),ne=f.type==="image/png"||f.name.toLowerCase().endsWith(".png");return(Z||ne)&&f.thumbnailPath});i(r)}}catch(a){console.error("Failed to fetch image resources:",a)}},ke=async()=>{if(!d.trim()){ie({title:"Prompt required",description:"Please enter a prompt to generate an image",variant:"destructive"});return}O(!0),ee(null);try{const a=X||F.length===0?[]:[...F],s=new AbortController,r=setTimeout(()=>s.abort(),3e5),f=await fetch(`${ae}/api/v1/resources/generate`,{method:"POST",headers:{"Content-Type":"application/json"},signal:s.signal,body:JSON.stringify({prompt:d,model:y,dimensions:w,resolution:J.features.resolution?_:void 0,output_format:M,output_quality:J.features.outputQuality?parseInt(A):void 0,quality:J.features.quality?k:void 0,go_fast:J.features.goFast?L:void 0,safety_tolerance:J.features.safetyTolerance?parseInt(I):void 0,background:J.features.background?K:void 0,image_input:a})});if(clearTimeout(r),f.status===504||f.status===502||f.status===408)throw new Error("Request timed out. The image model may be warming up - please try again.");const Z=f.headers.get("content-type");if(!Z||!Z.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const ne=await f.json();if(!f.ok||!ne.success){const de=ne.error?.message||"Failed to generate image",ce=ne.error?.code==="MISSING_API_TOKEN";throw new Error(ce?"Replicate API token not configured. Please add it in Settings → Integrations.":de)}ee(ne.data.imageUrl),ie({title:"Image generated",description:"Your image has been generated successfully"})}catch(a){console.error("Generation error:",a);const s=a instanceof Error&&a.name==="AbortError",r=s?"Request timed out after 5 minutes. The model may be overloaded - please try again.":a instanceof Error?a.message:"Failed to generate image.",f=s||r.toLowerCase().includes("timeout")||r.toLowerCase().includes("timed out");ie({title:f?"Generation timed out":"Generation failed",description:r,variant:"destructive"})}finally{O(!1)}};t.useEffect(()=>{const a=s=>{l&&(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&(s.preventDefault(),d.trim()&&!V&&!Q&&ke())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[l,d,V,Q]);const De=async()=>{if(H){o(!0);try{await n(H,{prompt:d,model:y}),x(""),E("nano-banana-pro"),b("16:9"),z("2K"),T("png"),v("80"),q("high"),D(!0),g("2"),Y("auto"),ee(null),re(!0),se([]),c(!1)}catch(a){ie({title:"Save failed",description:a instanceof Error?a.message:"Failed to save image. Please try again.",variant:"destructive"})}finally{o(!1)}}},Ge=()=>{!V&&!Q&&c(!1)},Ae=()=>{re(!0),se([])},Le=a=>{X&&re(!1),F.includes(a)?(se(F.filter(s=>s!==a)),F.length===1&&re(!0)):F.length<3?se([...F,a]):ie({title:"Maximum selection",description:"You can only select up to 3 images",variant:"destructive"})},qe=a=>{x(a)},He=a=>{p&&(he(!1),c(!1),p(`"${a}" Please customize this (and respond back just the updated markdown):`))};return e.jsxs(pe,{open:l,onOpenChange:Ge,children:[e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Generate Image"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:V?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):H?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:H,alt:"Generated",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(Ne,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"}),e.jsxs(R,{size:"sm",onClick:()=>he(!0),className:"mt-2",children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"View Examples"]})]})}),e.jsx("div",{className:"border-t bg-background p-2 flex-shrink-0",children:e.jsxs("div",{className:"flex gap-1.5 overflow-x-auto pb-1",children:[e.jsx("button",{onClick:Ae,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${X?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),te.map(a=>{const s=F.includes(a.id);return e.jsx("button",{onClick:()=>Le(a.id),className:`flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${s?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${ae}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[45vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(ye,{id:"prompt-mobile",placeholder:"Describe the image...",value:d,onChange:a=>x(a.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"model-mobile",className:"text-xs",children:"Model"}),e.jsxs(W,{value:y,onValueChange:a=>E(a),children:[e.jsx(B,{id:"model-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ss.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"outputFormat-mobile",className:"text-xs",children:"Format"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{id:"outputFormat-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:ks.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.background&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"background-mobile",className:"text-xs",children:"Background"}),e.jsxs(W,{value:K,onValueChange:Y,children:[e.jsx(B,{id:"background-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ms.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.goFast&&e.jsx("div",{className:"space-y-1 flex flex-col justify-end",children:e.jsxs("div",{className:"flex items-center space-x-2 h-8",children:[e.jsx(Oe,{id:"goFast-mobile",checked:L,onCheckedChange:a=>D(a===!0)}),e.jsx(C,{htmlFor:"goFast-mobile",className:"text-xs cursor-pointer",children:"Go Fast"})]})}),J.features.safetyTolerance&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"safetyTolerance-mobile",className:"text-xs",children:"Safety"}),e.jsxs(W,{value:I,onValueChange:g,children:[e.jsx(B,{id:"safetyTolerance-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Fs.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[J.features.resolution&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"resolution-mobile",className:"text-xs",children:"Resolution"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{id:"resolution-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Te.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"aspectRatio-mobile",className:"text-xs",children:"Ratio"}),e.jsxs(W,{value:w,onValueChange:b,children:[e.jsx(B,{id:"aspectRatio-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ce.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.outputQuality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"outputQuality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{id:"outputQuality-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ps.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.quality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"quality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(W,{value:k,onValueChange:q,children:[e.jsx(B,{id:"quality-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Es.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:ke,disabled:!d.trim()||V||Q,className:"flex-1 h-9",size:"sm",children:V?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(_s,{}),e.jsxs("span",{children:[Ie,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:De,disabled:!H||V||Q,variant:"outline",className:"flex-1 h-9",size:"sm",children:Q?e.jsx(le,{className:"h-4 w-4 animate-spin"}):"Save"})]})]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsx("div",{className:"w-[22%] border-r p-6 overflow-y-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"prompt",children:"Prompt"}),e.jsx(ye,{id:"prompt",placeholder:"Describe the image you want to generate...",value:d,onChange:a=>x(a.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"model",children:"Model"}),e.jsxs(W,{value:y,onValueChange:a=>E(a),children:[e.jsx(B,{id:"model",children:e.jsx($,{})}),e.jsx(U,{children:Ss.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(W,{value:w,onValueChange:b,children:[e.jsx(B,{id:"aspectRatio",children:e.jsx($,{})}),e.jsx(U,{children:Ce.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.resolution&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{id:"resolution",children:e.jsx($,{})}),e.jsx(U,{children:Te.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"outputFormat",children:"Output Format"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{id:"outputFormat",children:e.jsx($,{})}),e.jsx(U,{children:ks.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.background&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"background",children:"Background"}),e.jsxs(W,{value:K,onValueChange:Y,children:[e.jsx(B,{id:"background",children:e.jsx($,{})}),e.jsx(U,{children:Ms.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.outputQuality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"outputQuality",children:"Output Quality"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{id:"outputQuality",children:e.jsx($,{})}),e.jsx(U,{children:Ps.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.quality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"quality",children:"Quality"}),e.jsxs(W,{value:k,onValueChange:q,children:[e.jsx(B,{id:"quality",children:e.jsx($,{})}),e.jsx(U,{children:Es.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.goFast&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Oe,{id:"goFast",checked:L,onCheckedChange:a=>D(a===!0)}),e.jsx(C,{htmlFor:"goFast",className:"cursor-pointer",children:"Go Fast"})]}),J.features.safetyTolerance&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"safetyTolerance",children:"Safety Tolerance"}),e.jsxs(W,{value:I,onValueChange:g,children:[e.jsx(B,{id:"safetyTolerance",children:e.jsx($,{})}),e.jsx(U,{children:Fs.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:ke,disabled:!d.trim()||V||Q,className:"w-full",children:V?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(_s,{}),e.jsxs("span",{children:["Generating... ",Ie,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:De,disabled:!H||V||Q,variant:"outline",className:"w-full",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:V?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating image..."})]}):H?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:H,alt:"Generated",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(Ne,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated image will appear here"}),e.jsxs(R,{onClick:()=>he(!0),className:"mt-2",children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"View Examples"]})]})}),e.jsx("div",{className:"border-t bg-background p-4 flex-shrink-0",children:e.jsxs("div",{className:"flex gap-2 overflow-x-auto",children:[e.jsx("button",{onClick:Ae,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${X?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),te.map(a=>{const s=F.includes(a.id);return e.jsx("button",{onClick:()=>Le(a.id),className:`flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${s?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${ae}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})})]})]})]}),e.jsx(qa,{open:ue,onOpenChange:he,onSelectExample:qe,onCustomizeInAssistant:p?He:void 0})]})}var Hs=["PageUp","PageDown"],Js=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Ys={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Se="Slider",[as,Ya,Qa]=ua(Se),[Qs,Et]=da(Se,[Qa]),[Xa,Ue]=Qs(Se),Xs=t.forwardRef((l,c)=>{const{name:n,min:p=0,max:m=100,step:u=1,orientation:j="horizontal",disabled:h=!1,minStepsBetweenThumbs:N=0,defaultValue:P=[p],value:S,onValueChange:d=()=>{},onValueCommit:x=()=>{},inverted:y=!1,form:E,...w}=l,b=t.useRef(new Set),_=t.useRef(0),M=j==="horizontal"?Za:et,[T=[],A]=ca({prop:S,defaultProp:P,onChange:I=>{[...b.current][_.current]?.focus(),d(I)}}),v=t.useRef(T);function k(I){const g=lt(T,I);D(I,g)}function q(I){D(I,_.current)}function L(){const I=v.current[_.current];T[_.current]!==I&&x(T)}function D(I,g,{commit:K}={commit:!1}){const Y=ct(u),H=dt(Math.round((I-p)/u)*u+p,Y),ee=Bs(H,[p,m]);A((V=[])=>{const O=tt(V,ee,g);if(ot(O,N*u)){_.current=O.indexOf(ee);const Q=String(O)!==String(V);return Q&&K&&x(O),Q?O:V}else return V})}return e.jsx(Xa,{scope:l.__scopeSlider,name:n,disabled:h,min:p,max:m,valueIndexToChangeRef:_,thumbs:b.current,values:T,orientation:j,form:E,children:e.jsx(as.Provider,{scope:l.__scopeSlider,children:e.jsx(as.Slot,{scope:l.__scopeSlider,children:e.jsx(M,{"aria-disabled":h,"data-disabled":h?"":void 0,...w,ref:c,onPointerDown:be(w.onPointerDown,()=>{h||(v.current=T)}),min:p,max:m,inverted:y,onSlideStart:h?void 0:k,onSlideMove:h?void 0:q,onSlideEnd:h?void 0:L,onHomeKeyDown:()=>!h&&D(p,0,{commit:!0}),onEndKeyDown:()=>!h&&D(m,T.length-1,{commit:!0}),onStepKeyDown:({event:I,direction:g})=>{if(!h){const H=Hs.includes(I.key)||I.shiftKey&&Js.includes(I.key)?10:1,ee=_.current,V=T[ee],O=u*H*g;D(V+O,ee,{commit:!0})}}})})})})});Xs.displayName=Se;var[Zs,ea]=Qs(Se,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Za=t.forwardRef((l,c)=>{const{min:n,max:p,dir:m,inverted:u,onSlideStart:j,onSlideMove:h,onSlideEnd:N,onStepKeyDown:P,...S}=l,[d,x]=t.useState(null),y=_e(c,M=>x(M)),E=t.useRef(void 0),w=ma(m),b=w==="ltr",_=b&&!u||!b&&u;function z(M){const T=E.current||d.getBoundingClientRect(),A=[0,T.width],k=ls(A,_?[n,p]:[p,n]);return E.current=T,k(M-T.left)}return e.jsx(Zs,{scope:l.__scopeSlider,startEdge:_?"left":"right",endEdge:_?"right":"left",direction:_?1:-1,size:"width",children:e.jsx(sa,{dir:w,"data-orientation":"horizontal",...S,ref:y,style:{...S.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:M=>{const T=z(M.clientX);j?.(T)},onSlideMove:M=>{const T=z(M.clientX);h?.(T)},onSlideEnd:()=>{E.current=void 0,N?.()},onStepKeyDown:M=>{const A=Ys[_?"from-left":"from-right"].includes(M.key);P?.({event:M,direction:A?-1:1})}})})}),et=t.forwardRef((l,c)=>{const{min:n,max:p,inverted:m,onSlideStart:u,onSlideMove:j,onSlideEnd:h,onStepKeyDown:N,...P}=l,S=t.useRef(null),d=_e(c,S),x=t.useRef(void 0),y=!m;function E(w){const b=x.current||S.current.getBoundingClientRect(),_=[0,b.height],M=ls(_,y?[p,n]:[n,p]);return x.current=b,M(w-b.top)}return e.jsx(Zs,{scope:l.__scopeSlider,startEdge:y?"bottom":"top",endEdge:y?"top":"bottom",size:"height",direction:y?1:-1,children:e.jsx(sa,{"data-orientation":"vertical",...P,ref:d,style:{...P.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:w=>{const b=E(w.clientY);u?.(b)},onSlideMove:w=>{const b=E(w.clientY);j?.(b)},onSlideEnd:()=>{x.current=void 0,h?.()},onStepKeyDown:w=>{const _=Ys[y?"from-bottom":"from-top"].includes(w.key);N?.({event:w,direction:_?-1:1})}})})}),sa=t.forwardRef((l,c)=>{const{__scopeSlider:n,onSlideStart:p,onSlideMove:m,onSlideEnd:u,onHomeKeyDown:j,onEndKeyDown:h,onStepKeyDown:N,...P}=l,S=Ue(Se,n);return e.jsx(Fe.span,{...P,ref:c,onKeyDown:be(l.onKeyDown,d=>{d.key==="Home"?(j(d),d.preventDefault()):d.key==="End"?(h(d),d.preventDefault()):Hs.concat(Js).includes(d.key)&&(N(d),d.preventDefault())}),onPointerDown:be(l.onPointerDown,d=>{const x=d.target;x.setPointerCapture(d.pointerId),d.preventDefault(),S.thumbs.has(x)?x.focus():p(d)}),onPointerMove:be(l.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&m(d)}),onPointerUp:be(l.onPointerUp,d=>{const x=d.target;x.hasPointerCapture(d.pointerId)&&(x.releasePointerCapture(d.pointerId),u(d))})})}),aa="SliderTrack",ta=t.forwardRef((l,c)=>{const{__scopeSlider:n,...p}=l,m=Ue(aa,n);return e.jsx(Fe.span,{"data-disabled":m.disabled?"":void 0,"data-orientation":m.orientation,...p,ref:c})});ta.displayName=aa;var ts="SliderRange",na=t.forwardRef((l,c)=>{const{__scopeSlider:n,...p}=l,m=Ue(ts,n),u=ea(ts,n),j=t.useRef(null),h=_e(c,j),N=m.values.length,P=m.values.map(x=>ia(x,m.min,m.max)),S=N>1?Math.min(...P):0,d=100-Math.max(...P);return e.jsx(Fe.span,{"data-orientation":m.orientation,"data-disabled":m.disabled?"":void 0,...p,ref:h,style:{...l.style,[u.startEdge]:S+"%",[u.endEdge]:d+"%"}})});na.displayName=ts;var ns="SliderThumb",la=t.forwardRef((l,c)=>{const n=Ya(l.__scopeSlider),[p,m]=t.useState(null),u=_e(c,h=>m(h)),j=t.useMemo(()=>p?n().findIndex(h=>h.ref.current===p):-1,[n,p]);return e.jsx(st,{...l,ref:u,index:j})}),st=t.forwardRef((l,c)=>{const{__scopeSlider:n,index:p,name:m,...u}=l,j=Ue(ns,n),h=ea(ns,n),[N,P]=t.useState(null),S=_e(c,z=>P(z)),d=N?j.form||!!N.closest("form"):!0,x=ha(N),y=j.values[p],E=y===void 0?0:ia(y,j.min,j.max),w=nt(p,j.values.length),b=x?.[h.size],_=b?rt(b,E,h.direction):0;return t.useEffect(()=>{if(N)return j.thumbs.add(N),()=>{j.thumbs.delete(N)}},[N,j.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[h.startEdge]:`calc(${E}% + ${_}px)`},children:[e.jsx(as.ItemSlot,{scope:l.__scopeSlider,children:e.jsx(Fe.span,{role:"slider","aria-label":l["aria-label"]||w,"aria-valuemin":j.min,"aria-valuenow":y,"aria-valuemax":j.max,"aria-orientation":j.orientation,"data-orientation":j.orientation,"data-disabled":j.disabled?"":void 0,tabIndex:j.disabled?void 0:0,...u,ref:S,style:y===void 0?{display:"none"}:l.style,onFocus:be(l.onFocus,()=>{j.valueIndexToChangeRef.current=p})})}),d&&e.jsx(ra,{name:m??(j.name?j.name+(j.values.length>1?"[]":""):void 0),form:j.form,value:y},p)]})});la.displayName=ns;var at="RadioBubbleInput",ra=t.forwardRef(({__scopeSlider:l,value:c,...n},p)=>{const m=t.useRef(null),u=_e(m,p),j=xa(c);return t.useEffect(()=>{const h=m.current;if(!h)return;const N=window.HTMLInputElement.prototype,S=Object.getOwnPropertyDescriptor(N,"value").set;if(j!==c&&S){const d=new Event("input",{bubbles:!0});S.call(h,c),h.dispatchEvent(d)}},[j,c]),e.jsx(Fe.input,{style:{display:"none"},...n,ref:u,defaultValue:c})});ra.displayName=at;function tt(l=[],c,n){const p=[...l];return p[n]=c,p.sort((m,u)=>m-u)}function ia(l,c,n){const u=100/(n-c)*(l-c);return Bs(u,[0,100])}function nt(l,c){return c>2?`Value ${l+1} of ${c}`:c===2?["Minimum","Maximum"][l]:void 0}function lt(l,c){if(l.length===1)return 0;const n=l.map(m=>Math.abs(m-c)),p=Math.min(...n);return n.indexOf(p)}function rt(l,c,n){const p=l/2,u=ls([0,50],[0,p]);return(p-u(c)*n)*n}function it(l){return l.slice(0,-1).map((c,n)=>l[n+1]-c)}function ot(l,c){if(c>0){const n=it(l);return Math.min(...n)>=c}return!0}function ls(l,c){return n=>{if(l[0]===l[1]||c[0]===c[1])return c[0];const p=(c[1]-c[0])/(l[1]-l[0]);return c[0]+p*(n-l[0])}}function ct(l){return(String(l).split(".")[1]||"").length}function dt(l,c){const n=Math.pow(10,c);return Math.round(l*n)/n}var oa=Xs,ut=ta,mt=na,ht=la;const Pe=t.forwardRef(({className:l,...c},n)=>e.jsxs(oa,{ref:n,className:fa("relative flex w-full touch-none select-none items-center",l),...c,children:[e.jsx(ut,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(mt,{className:"absolute h-full bg-primary"})}),e.jsx(ht,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));Pe.displayName=oa.displayName;const Is="audio-generator-settings";function Rs(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Ts=["English_Trustworth_Man","English_Aussie_Bloke","English_CalmWoman","English_UpsetGirl","English_Gentle-voiced_man","English_Whispering_girl","English_Diligent_Man","English_Graceful_Lady","English_ReservedYoungMan","English_PlayfulGirl","English_ManWithDeepVoice","English_MaturePartner","English_FriendlyPerson","English_MatureBoss","English_Debator","English_LovelyGirl","English_Steadymentor","English_Deep-VoicedGentleman","English_Wiselady","English_CaptivatingStoryteller","English_DecentYoungMan","English_SentimentalLady","English_ImposingManner","English_SadTeen","English_PassionateWarrior","English_WiseScholar","English_Soft-spokenGirl","English_SereneWoman","English_ConfidentWoman","English_PatientMan","English_Comedian","English_BossyLeader","English_Strong-WilledBoy","English_StressedLady","English_AssertiveQueen","English_AnimeCharacter","English_Jovialman","English_WhimsicalGirl","English_Kind-heartedGirl","Chinese (Mandarin)_Reliable_Executive","Chinese (Mandarin)_News_Anchor","Chinese (Mandarin)_Unrestrained_Young_Man","Chinese (Mandarin)_Mature_Woman","Arrogant_Miss","Robot_Armor","Chinese (Mandarin)_Kind-hearted_Antie","Chinese (Mandarin)_Refreshing_Young_Man","Chinese (Mandarin)_HK_Flight_Attendant","Chinese (Mandarin)_Humorous_Elder","Chinese (Mandarin)_Gentleman","Chinese (Mandarin)_Warm_Bestie","Chinese (Mandarin)_Stubborn_Friend","Chinese (Mandarin)_Sweet_Lady","Chinese (Mandarin)_Southern_Young_Man","Chinese (Mandarin)_Wise_Women","Chinese (Mandarin)_Gentle_Youth","Chinese (Mandarin)_Warm_Girl","Chinese (Mandarin)_Male_Announcer","Chinese (Mandarin)_Kind-hearted_Elder","Chinese (Mandarin)_Cute_Spirit","Chinese (Mandarin)_Radio_Host","Chinese (Mandarin)_Lyrical_Voice","Chinese (Mandarin)_Straightforward_Boy","Chinese (Mandarin)_Sincere_Adult","Chinese (Mandarin)_Gentle_Senior","Chinese (Mandarin)_Crisp_Girl","Chinese (Mandarin)_Pure-hearted_Boy","Chinese (Mandarin)_Soft_Girl","Chinese (Mandarin)_IntellectualGirl","Chinese (Mandarin)_Warm_HeartedGirl","Chinese (Mandarin)_Laid_BackGirl","Chinese (Mandarin)_ExplorativeGirl","Chinese (Mandarin)_Warm-HeartedAunt","Chinese (Mandarin)_BashfulGirl","Japanese_IntellectualSenior","Japanese_DecisivePrincess","Japanese_LoyalKnight","Japanese_DominantMan","Japanese_SeriousCommander","Japanese_ColdQueen","Japanese_DependableWoman","Japanese_GentleButler","Japanese_KindLady","Japanese_CalmLady","Japanese_OptimisticYouth","Japanese_GenerousIzakayaOwner","Japanese_SportyStudent","Japanese_InnocentBoy","Japanese_GracefulMaiden","Cantonese_ProfessionalHost(F)","Cantonese_GentleLady","Cantonese_ProfessionalHost(M)","Cantonese_PlayfulMan","Cantonese_CuteGirl","Cantonese_KindWoman","Korean_SweetGirl","Korean_CheerfulBoyfriend","Korean_EnchantingSister","Korean_ShyGirl","Korean_ReliableSister","Korean_StrictBoss","Korean_SassyGirl","Korean_ChildhoodFriendGirl","Korean_PlayboyCharmer","Korean_ElegantPrincess","Korean_BraveFemaleWarrior","Korean_BraveYouth","Korean_CalmLady","Korean_EnthusiasticTeen","Korean_SoothingLady","Korean_IntellectualSenior","Korean_LonelyWarrior","Korean_MatureLady","Korean_InnocentBoy","Korean_CharmingSister","Korean_AthleticStudent","Korean_BraveAdventurer","Korean_CalmGentleman","Korean_WiseElf","Korean_CheerfulCoolJunior","Korean_DecisiveQueen","Korean_ColdYoungMan","Korean_MysteriousGirl","Korean_QuirkyGirl","Korean_ConsiderateSenior","Korean_CheerfulLittleSister","Korean_DominantMan","Korean_AirheadedGirl","Korean_ReliableYouth","Korean_FriendlyBigSister","Korean_GentleBoss","Korean_ColdGirl","Korean_HaughtyLady","Korean_CharmingElderSister","Korean_IntellectualMan","Korean_CaringWoman","Korean_WiseTeacher","Korean_ConfidentBoss","Korean_AthleticGirl","Korean_PossessiveMan","Korean_GentleWoman","Korean_CockyGuy","Korean_ThoughtfulWoman","Korean_OptimisticYouth","Spanish_SereneWoman","Spanish_MaturePartner","Spanish_CaptivatingStoryteller","Spanish_Narrator","Spanish_WiseScholar","Spanish_Kind-heartedGirl","Spanish_DeterminedManager","Spanish_BossyLeader","Spanish_ReservedYoungMan","Spanish_ConfidentWoman","Spanish_ThoughtfulMan","Spanish_Strong-WilledBoy","Spanish_SophisticatedLady","Spanish_RationalMan","Spanish_AnimeCharacter","Spanish_Deep-tonedMan","Spanish_Fussyhostess","Spanish_SincereTeen","Spanish_FrankLady","Spanish_Comedian","Spanish_Debator","Spanish_ToughBoss","Spanish_Wiselady","Spanish_Steadymentor","Spanish_Jovialman","Spanish_SantaClaus","Spanish_Rudolph","Spanish_Intonategirl","Spanish_Arnold","Spanish_Ghost","Spanish_HumorousElder","Spanish_EnergeticBoy","Spanish_WhimsicalGirl","Spanish_StrictBoss","Spanish_ReliableMan","Spanish_SereneElder","Spanish_AngryMan","Spanish_AssertiveQueen","Spanish_CaringGirlfriend","Spanish_PowerfulSoldier","Spanish_PassionateWarrior","Spanish_ChattyGirl","Spanish_RomanticHusband","Spanish_CompellingGirl","Spanish_PowerfulVeteran","Spanish_SensibleManager","Spanish_ThoughtfulLady","Portuguese_SentimentalLady","Portuguese_BossyLeader","Portuguese_Wiselady","Portuguese_Strong-WilledBoy","Portuguese_Deep-VoicedGentleman","Portuguese_UpsetGirl","Portuguese_PassionateWarrior","Portuguese_AnimeCharacter","Portuguese_ConfidentWoman","Portuguese_AngryMan","Portuguese_CaptivatingStoryteller","Portuguese_Godfather","Portuguese_ReservedYoungMan","Portuguese_SmartYoungGirl","Portuguese_Kind-heartedGirl","Portuguese_Pompouslady","Portuguese_Grinch","Portuguese_Debator","Portuguese_SweetGirl","Portuguese_AttractiveGirl","Portuguese_ThoughtfulMan","Portuguese_PlayfulGirl","Portuguese_GorgeousLady","Portuguese_LovelyLady","Portuguese_SereneWoman","Portuguese_SadTeen","Portuguese_MaturePartner","Portuguese_Comedian","Portuguese_NaughtySchoolgirl","Portuguese_Narrator","Portuguese_ToughBoss","Portuguese_Fussyhostess","Portuguese_Dramatist","Portuguese_Steadymentor","Portuguese_Jovialman","Portuguese_CharmingQueen","Portuguese_SantaClaus","Portuguese_Rudolph","Portuguese_Arnold","Portuguese_CharmingSanta","Portuguese_CharmingLady","Portuguese_Ghost","Portuguese_HumorousElder","Portuguese_CalmLeader","Portuguese_GentleTeacher","Portuguese_EnergeticBoy","Portuguese_ReliableMan","Portuguese_SereneElder","Portuguese_GrimReaper","Portuguese_AssertiveQueen","Portuguese_WhimsicalGirl","Portuguese_StressedLady","Portuguese_FriendlyNeighbor","Portuguese_CaringGirlfriend","Portuguese_PowerfulSoldier","Portuguese_FascinatingBoy","Portuguese_RomanticHusband","Portuguese_StrictBoss","Portuguese_InspiringLady","Portuguese_PlayfulSpirit","Portuguese_ElegantGirl","Portuguese_CompellingGirl","Portuguese_PowerfulVeteran","Portuguese_SensibleManager","Portuguese_ThoughtfulLady","Portuguese_TheatricalActor","Portuguese_FragileBoy","Portuguese_ChattyGirl","Portuguese_Conscientiousinstructor","Portuguese_RationalMan","Portuguese_WiseScholar","Portuguese_FrankLady","Portuguese_DeterminedManager","French_Male_Speech_New","French_Female_News Anchor","French_CasualMan","French_MovieLeadFemale","French_FemaleAnchor","French_MaleNarrator","Indonesian_SweetGirl","Indonesian_ReservedYoungMan","Indonesian_CharmingGirl","Indonesian_CalmWoman","Indonesian_ConfidentWoman","Indonesian_CaringMan","Indonesian_BossyLeader","Indonesian_DeterminedBoy","Indonesian_GentleGirl","German_FriendlyMan","German_SweetLady","German_PlayfulMan","Russian_HandsomeChildhoodFriend","Russian_BrightHeroine","Russian_AmbitiousWoman","Russian_ReliableMan","Russian_CrazyQueen","Russian_PessimisticGirl","Russian_AttractiveGuy","Russian_Bad-temperedBoy","Italian_BraveHeroine","Italian_Narrator","Italian_WanderingSorcerer","Italian_DiligentLeader","Dutch_kindhearted_girl","Dutch_bossy_leader","Vietnamese_kindhearted_girl","Arabic_CalmWoman","Arabic_FriendlyGuy","Turkish_CalmWoman","Turkish_Trustworthyman","Ukrainian_CalmWoman"],Ds=[{value:"auto",label:"Auto"},{value:"happy",label:"Happy"},{value:"sad",label:"Sad"},{value:"angry",label:"Angry"},{value:"fearful",label:"Fearful"},{value:"disgusted",label:"Disgusted"},{value:"surprised",label:"Surprised"},{value:"neutral",label:"Neutral"}],Gs=[{value:"English",label:"English"},{value:"Chinese",label:"Chinese"},{value:"Japanese",label:"Japanese"},{value:"Korean",label:"Korean"},{value:"Spanish",label:"Spanish"},{value:"Portuguese",label:"Portuguese"},{value:"French",label:"French"},{value:"Indonesian",label:"Indonesian"},{value:"German",label:"German"},{value:"Russian",label:"Russian"},{value:"Italian",label:"Italian"},{value:"Dutch",label:"Dutch"},{value:"Vietnamese",label:"Vietnamese"},{value:"Arabic",label:"Arabic"},{value:"Turkish",label:"Turkish"},{value:"Ukrainian",label:"Ukrainian"},{value:"Cantonese",label:"Cantonese"}],As=[{value:"mp3",label:"MP3"},{value:"wav",label:"WAV"},{value:"flac",label:"FLAC"}];function xt({open:l,onOpenChange:c,onSave:n}){const m=(()=>{if(typeof window>"u")return null;try{const o=localStorage.getItem(Is);return o?JSON.parse(o):null}catch{return null}})(),[u,j]=t.useState(""),[h,N]=t.useState(m?.voiceId||"English_Trustworth_Man"),[P,S]=t.useState(m?.useCustomVoice||!1),[d,x]=t.useState(m?.customVoiceId||""),[y,E]=t.useState(m?.speed??1),[w,b]=t.useState(m?.pitch??0),[_,z]=t.useState(m?.emotion||"auto"),[M,T]=t.useState(m?.languageBoost||"English"),[A,v]=t.useState(m?.audioFormat||"mp3"),[k,q]=t.useState(null),[L,D]=t.useState(!1),[I,g]=t.useState(!1),[K,Y]=t.useState(0),H=t.useRef(null),{toast:ee}=$e();t.useEffect(()=>{const o={voiceId:h,useCustomVoice:P,customVoiceId:d,speed:y,pitch:w,emotion:_,languageBoost:M,audioFormat:A};localStorage.setItem(Is,JSON.stringify(o))},[h,P,d,y,w,_,M,A]),t.useEffect(()=>(L?(Y(0),H.current=setInterval(()=>{Y(o=>o+1)},1e3)):H.current&&(clearInterval(H.current),H.current=null),()=>{H.current&&clearInterval(H.current)}),[L]);const V=async()=>{if(!u.trim()){ee({title:"Text required",description:"Please enter text to generate audio",variant:"destructive"});return}D(!0),q(null);try{const o=P?d:h,te=new AbortController,i=setTimeout(()=>te.abort(),3e5),F=await fetch(`${ae}/api/v1/resources/generate-audio`,{method:"POST",headers:{"Content-Type":"application/json"},signal:te.signal,body:JSON.stringify({text:u,voice_id:o,speed:y,pitch:w,emotion:_,language_boost:M,audio_format:A})});if(clearTimeout(i),F.status===504||F.status===502||F.status===408)throw new Error("Request timed out. The audio model may be warming up - please try again.");const se=F.headers.get("content-type");if(!se||!se.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const X=await F.json();if(!F.ok||!X.success){const re=X.error?.message||"Failed to generate audio",ue=X.error?.code==="MISSING_API_TOKEN";throw new Error(ue?"Replicate API token not configured. Please add it in Settings → Integrations.":re)}q(X.data.audioUrl),ee({title:"Audio generated",description:"Your audio has been generated successfully"})}catch(o){console.error("Generation error:",o);const te=o instanceof Error&&o.name==="AbortError",i=te?"Request timed out after 5 minutes. The model may be overloaded - please try again.":o instanceof Error?o.message:"Failed to generate audio.",F=te||i.toLowerCase().includes("timeout")||i.toLowerCase().includes("timed out");ee({title:F?"Generation timed out":"Generation failed",description:i,variant:"destructive"})}finally{D(!1)}};t.useEffect(()=>{const o=te=>{l&&(te.metaKey||te.ctrlKey)&&te.key==="Enter"&&(te.preventDefault(),u.trim()&&!L&&!I&&V())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[l,u,L,I]);const O=async()=>{if(k){g(!0);try{await n(k),j(""),N("English_Trustworth_Man"),S(!1),x(""),E(1),b(0),z("auto"),T("English"),v("mp3"),q(null),c(!1)}catch(o){ee({title:"Save failed",description:o instanceof Error?o.message:"Failed to save audio. Please try again.",variant:"destructive"})}finally{g(!1)}}},Q=()=>{!L&&!I&&c(!1)};return e.jsx(pe,{open:l,onOpenChange:Q,children:e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Generate Audio"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:L?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):k?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{className:"h-16 w-16 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-4 bg-muted/50 flex justify-center",children:e.jsx("audio",{src:k,controls:!0,className:"w-full max-w-[90%]",children:"Your browser does not support the audio tag."})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(fe,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"})]})}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[55vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"text-mobile",className:"text-xs",children:"Text"}),e.jsx(ye,{id:"text-mobile",placeholder:"Enter text to convert to speech...",value:u,onChange:o=>j(o.target.value),rows:3,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Voice"}),e.jsxs(W,{value:P?"__custom__":h,onValueChange:o=>{o==="__custom__"?S(!0):(S(!1),N(o))},children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsxs(U,{className:"max-h-60",children:[Ts.map(o=>e.jsx(G,{value:o,className:"text-xs",children:o.replace(/_/g," ")},o)),e.jsx(G,{value:"__custom__",className:"text-xs font-medium",children:"Custom Voice ID..."})]})]}),P&&e.jsx(We,{placeholder:"Enter custom voice ID",value:d,onChange:o=>x(o.target.value),className:"h-8 text-xs mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs",children:["Speed: ",y.toFixed(1),"x"]}),e.jsx(Pe,{value:[y],onValueChange:([o])=>E(o),min:.5,max:2,step:.1,className:"w-full"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs",children:["Pitch: ",w>0?"+":"",w]}),e.jsx(Pe,{value:[w],onValueChange:([o])=>b(o),min:-12,max:12,step:1,className:"w-full"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Emotion"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ds.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Language"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Gs.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Format"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:As.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:V,disabled:!u.trim()||L||I,className:"flex-1 h-9",size:"sm",children:L?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:[K,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:O,disabled:!k||L||I,variant:"outline",className:"flex-1 h-9",size:"sm",children:I?e.jsx(le,{className:"h-4 w-4 animate-spin"}):"Save"})]})]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsx("div",{className:"w-[30%] border-r p-6 overflow-y-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"text",children:"Text"}),e.jsx(ye,{id:"text",placeholder:"Enter text to convert to speech...",value:u,onChange:o=>j(o.target.value),rows:6,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Voice"}),e.jsxs(W,{value:P?"__custom__":h,onValueChange:o=>{o==="__custom__"?S(!0):(S(!1),N(o))},children:[e.jsx(B,{children:e.jsx($,{})}),e.jsxs(U,{className:"max-h-80",children:[Ts.map(o=>e.jsx(G,{value:o,children:o.replace(/_/g," ")},o)),e.jsx(G,{value:"__custom__",className:"font-medium",children:"Custom Voice ID..."})]})]}),P&&e.jsx(We,{placeholder:"Enter custom voice ID",value:d,onChange:o=>x(o.target.value),className:"mt-2"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Speed: ",y.toFixed(1),"x"]}),e.jsx(Pe,{value:[y],onValueChange:([o])=>E(o),min:.5,max:2,step:.1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0.5x"}),e.jsx("span",{children:"2x"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Pitch: ",w>0?"+":"",w]}),e.jsx(Pe,{value:[w],onValueChange:([o])=>b(o),min:-12,max:12,step:1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"-12"}),e.jsx("span",{children:"+12"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Emotion"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:Ds.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Language Boost"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:Gs.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Audio Format"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:As.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:V,disabled:!u.trim()||L||I,className:"w-full",children:L?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:["Generating... ",K,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:O,disabled:!k||L||I,variant:"outline",className:"w-full",children:I?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:L?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating audio..."})]}):k?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{className:"h-24 w-24 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-6 bg-muted/50 flex justify-center",children:e.jsx("audio",{src:k,controls:!0,className:"w-3/4 min-w-[300px]",children:"Your browser does not support the audio tag."})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(fe,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated audio will appear here"})]})})})]})]})})}const Ls="video-generator-settings";function Ks(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Vs=[{value:"5",label:"5 seconds"},{value:"8",label:"8 seconds"},{value:"10",label:"10 seconds"}],Os=[{value:"480p",label:"480p"},{value:"720p",label:"720p"},{value:"1080p",label:"1080p"}],Ws=[{value:"16:9",label:"16:9 (Landscape)"},{value:"9:16",label:"9:16 (Portrait)"},{value:"1:1",label:"1:1 (Square)"}];function ft({open:l,onOpenChange:c,onSave:n}){const m=(()=>{if(typeof window>"u")return null;try{const i=localStorage.getItem(Ls);return i?JSON.parse(i):null}catch{return null}})(),[u,j]=t.useState(""),[h,N]=t.useState(m?.duration||"8"),[P,S]=t.useState(m?.resolution||"720p"),[d,x]=t.useState(m?.aspectRatio||"16:9"),[y,E]=t.useState(m?.generateAudio??!0),[w,b]=t.useState(null),[_,z]=t.useState(null),[M,T]=t.useState(null),[A,v]=t.useState(0),k=t.useRef(null),[q,L]=t.useState(!1),[D,I]=t.useState(!1),[g,K]=t.useState([]),{toast:Y}=$e();t.useEffect(()=>{const i={duration:h,resolution:P,aspectRatio:d,generateAudio:y};localStorage.setItem(Ls,JSON.stringify(i))},[h,P,d,y]),t.useEffect(()=>(q?(v(0),k.current=setInterval(()=>{v(i=>i+1)},1e3)):k.current&&(clearInterval(k.current),k.current=null),()=>{k.current&&clearInterval(k.current)}),[q]),t.useEffect(()=>{l&&H()},[l]);const H=async()=>{try{const F=await(await fetch(`${ae}/api/v1/resources`)).json();if(F.success){const se=(F.data||[]).filter(X=>{const re=X.type==="image/jpeg"||X.name.toLowerCase().endsWith(".jpg")||X.name.toLowerCase().endsWith(".jpeg"),ue=X.type==="image/png"||X.name.toLowerCase().endsWith(".png");return(re||ue)&&X.thumbnailPath});K(se)}}catch(i){console.error("Failed to fetch image resources:",i)}},ee=i=>{i===_?z(null):i===w?(b(null),z(i)):w?z(i):b(i)},V=()=>{b(null),z(null)},O=async()=>{if(!u.trim()){Y({title:"Prompt required",description:"Please enter a prompt to generate a video",variant:"destructive"});return}L(!0),T(null);try{const i=new AbortController,F=setTimeout(()=>i.abort(),3e5),se=await fetch(`${ae}/api/v1/resources/generate-video`,{method:"POST",headers:{"Content-Type":"application/json"},signal:i.signal,body:JSON.stringify({prompt:u,image:w||void 0,last_frame:_||void 0,duration:parseInt(h),resolution:P,aspect_ratio:d,generate_audio:y})});if(clearTimeout(F),se.status===504||se.status===502||se.status===408)throw new Error("Request timed out. The video model may be warming up - please try again.");const X=se.headers.get("content-type");if(!X||!X.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const re=await se.json();if(!se.ok||!re.success){const ue=re.error?.message||"Failed to generate video",he=re.error?.code==="MISSING_API_TOKEN";throw new Error(he?"Replicate API token not configured. Please add it in Settings → Integrations.":ue)}T(re.data.videoUrl),Y({title:"Video generated",description:"Your video has been generated successfully"})}catch(i){console.error("Generation error:",i);const F=i instanceof Error&&i.name==="AbortError",se=F?"Request timed out after 5 minutes. The model may be overloaded - please try again.":i instanceof Error?i.message:"Failed to generate video.",X=F||se.toLowerCase().includes("timeout")||se.toLowerCase().includes("timed out");Y({title:X?"Generation timed out":"Generation failed",description:se,variant:"destructive"})}finally{L(!1)}};t.useEffect(()=>{const i=F=>{l&&(F.metaKey||F.ctrlKey)&&F.key==="Enter"&&(F.preventDefault(),u.trim()&&!q&&!D&&O())};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[l,u,q,D]);const Q=async()=>{if(M){I(!0);try{await n(M),j(""),N("8"),S("720p"),x("16:9"),E(!0),b(null),z(null),T(null),c(!1)}catch(i){Y({title:"Save failed",description:i instanceof Error?i.message:"Failed to save video. Please try again.",variant:"destructive"})}finally{I(!1)}}},o=()=>{!q&&!D&&c(!1)},te=i=>i===w?"start":i===_?"end":null;return e.jsx(pe,{open:l,onOpenChange:o,children:e.jsxs(ge,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{className:"text-base sm:text-lg",children:"Generate Video"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:q?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):M?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:M,controls:!0,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg",children:"Your browser does not support the video tag."})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(Be,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"})]})}),e.jsxs("div",{className:"border-t bg-background p-2 flex-shrink-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2 px-1",children:"Select start and end frames (optional)"}),e.jsxs("div",{className:"flex gap-1.5 overflow-x-auto pb-1",children:[e.jsx("button",{onClick:V,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${!w&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),g.map(i=>{const F=te(i.id);return e.jsxs("button",{onClick:()=>ee(i.id),className:`relative flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${F?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${ae}/api/v1/resources/${i.id}/thumbnail`,alt:i.name,className:"w-full h-full object-cover"}),F&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-green-500 text-white text-[10px] font-medium text-center py-0.5",children:F==="start"?"Start":"End"})]},i.id)})]})]}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[40vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(ye,{id:"prompt-mobile",placeholder:"Describe the video you want to generate...",value:u,onChange:i=>j(i.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Duration"}),e.jsxs(W,{value:h,onValueChange:N,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Vs.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Resolution"}),e.jsxs(W,{value:P,onValueChange:S,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Os.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Ratio"}),e.jsxs(W,{value:d,onValueChange:x,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ws.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Oe,{id:"generateAudio-mobile",checked:y,onCheckedChange:i=>E(i===!0)}),e.jsx(C,{htmlFor:"generateAudio-mobile",className:"text-xs cursor-pointer",children:"Generate audio"})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:O,disabled:!u.trim()||q||D,className:"flex-1 h-9",size:"sm",children:q?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{}),e.jsxs("span",{children:[A,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:Q,disabled:!M||q||D,variant:"outline",className:"flex-1 h-9",size:"sm",children:D?e.jsx(le,{className:"h-4 w-4 animate-spin"}):"Save"})]})]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsx("div",{className:"w-[22%] border-r p-6 overflow-y-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"prompt",children:"Prompt"}),e.jsx(ye,{id:"prompt",placeholder:"Describe the video you want to generate...",value:u,onChange:i=>j(i.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"duration",children:"Duration"}),e.jsxs(W,{value:h,onValueChange:N,children:[e.jsx(B,{id:"duration",children:e.jsx($,{})}),e.jsx(U,{children:Vs.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(W,{value:P,onValueChange:S,children:[e.jsx(B,{id:"resolution",children:e.jsx($,{})}),e.jsx(U,{children:Os.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(W,{value:d,onValueChange:x,children:[e.jsx(B,{id:"aspectRatio",children:e.jsx($,{})}),e.jsx(U,{children:Ws.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Oe,{id:"generateAudio",checked:y,onCheckedChange:i=>E(i===!0)}),e.jsx(C,{htmlFor:"generateAudio",className:"cursor-pointer",children:"Generate audio"})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:O,disabled:!u.trim()||q||D,className:"w-full",children:q?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{}),e.jsxs("span",{children:["Generating... ",A,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:Q,disabled:!M||q||D,variant:"outline",className:"w-full",children:D?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:q?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating video..."})]}):M?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:M,controls:!0,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg",children:"Your browser does not support the video tag."})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(Be,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated video will appear here"})]})}),e.jsxs("div",{className:"border-t bg-background p-4 flex-shrink-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Select start and end frames (optional)"}),e.jsxs("div",{className:"flex gap-2 overflow-x-auto",children:[e.jsx("button",{onClick:V,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${!w&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),g.map(i=>{const F=te(i.id);return e.jsxs("button",{onClick:()=>ee(i.id),className:`relative flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${F?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${ae}/api/v1/resources/${i.id}/thumbnail`,alt:i.name,className:"w-full h-full object-cover"}),F&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-green-500 text-white text-xs font-medium text-center py-1",children:F==="start"?"Start":"End"})]},i.id)})]})]})]})]})]})})}function pt({open:l,onOpenChange:c,resource:n,onCopyPath:p,onDownload:m,onNavigate:u,canNavigatePrev:j,canNavigateNext:h}){const[N,P]=t.useState(null),[S,d]=t.useState(!1),[x,y]=t.useState(!1);t.useEffect(()=>{y(!1)},[n?.id,l]);const E=n?`${ae}/api/v1/resources/${n.id}`:"",w=n?.type.startsWith("image/")??!1,b=n?n.type==="image/svg+xml"||n.name.toLowerCase().endsWith(".svg"):!1,_=n?n.type==="application/pdf"||n.name.toLowerCase().endsWith(".pdf"):!1,z=n?.type.startsWith("video/")??!1,M=n?.type.startsWith("audio/")??!1,T=n?n.type.startsWith("text/")||n.type==="application/json"||n.type.includes("javascript")||n.type.includes("typescript")||n.type.includes("xml")||n.name.toLowerCase().match(/\.(txt|md|json|js|ts|jsx|tsx|css|html|xml|yaml|yml|log|sh|bash|zsh|fish)$/)!==null:!1,A=n?n.name.toLowerCase().endsWith(".md")||n.name.toLowerCase().endsWith(".markdown"):!1,v=n?n.type==="application/json"||n.name.toLowerCase().endsWith(".json"):!1,k=n?n.type==="text/html"||n.name.toLowerCase().endsWith(".html"):!1;if(t.useEffect(()=>{const g=K=>{if(l){if(K.key==="Escape"){x?y(!1):c(!1);return}if(!x){if(K.key==="ArrowLeft"&&j){K.preventDefault(),u("prev");return}K.key==="ArrowRight"&&h&&(K.preventDefault(),u("next"))}}};if(l)return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[l,c,u,j,h,x]),t.useEffect(()=>{l&&n&&(T||A||v||k)?(d(!0),fetch(E).then(g=>{if(g.ok)return g.text();throw new Error("Failed to load file")}).then(g=>{P(g)}).catch(g=>{console.error("Failed to load text content:",g),P(null)}).finally(()=>{d(!1)})):P(null)},[l,n?.id,T,A,v,k,E]),!n)return null;const q=g=>{if(g===0)return"0 B";const K=1024,Y=["B","KB","MB","GB"],H=Math.floor(Math.log(g)/Math.log(K));return parseFloat((g/Math.pow(K,H)).toFixed(2))+" "+Y[H]},L=g=>new Date(g).toLocaleString(),D=g=>g.startsWith("image/")?e.jsx(Ne,{className:"h-6 w-6"}):g.startsWith("video/")?e.jsx(Be,{className:"h-6 w-6"}):g.startsWith("audio/")?e.jsx(fe,{className:"h-6 w-6"}):g.includes("text")||g.includes("document")||g.includes("code")?e.jsx(we,{className:"h-6 w-6"}):g.includes("json")||g.includes("javascript")||g.includes("typescript")?e.jsx(ss,{className:"h-6 w-6"}):e.jsx(Ze,{className:"h-6 w-6"}),I=()=>{if(b)return e.jsxs(e.Fragment,{children:[e.jsx("img",{src:E,alt:n.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}),e.jsx(R,{variant:"secondary",size:"icon",className:"absolute bottom-3 right-3 h-8 w-8 opacity-70 hover:opacity-100 transition-opacity",onClick:()=>y(!0),children:e.jsx(ys,{className:"h-4 w-4"})})]});if(_)return e.jsx("iframe",{src:E,className:"w-full h-full min-h-[600px] rounded-lg border",title:n.name});if(z)return e.jsx("video",{src:E,controls:!0,className:"max-w-full max-h-full rounded-lg shadow-lg",children:"Your browser does not support the video tag."});if(M)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{className:"h-24 w-24 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-6 bg-muted/30 flex justify-center",children:e.jsx("audio",{src:E,controls:!0,className:"w-3/4 min-w-[300px]",children:"Your browser does not support the audio tag."})})]});if(A&&N!==null)return S?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("div",{className:"w-full h-full overflow-auto p-6 prose prose-sm dark:prose-invert max-w-none",children:e.jsx(pa,{remarkPlugins:[va],rehypePlugins:[ga],children:N})});if(k&&N!==null)return S?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("iframe",{srcDoc:N,className:"w-full h-full min-h-[600px] rounded-lg border",title:n.name,sandbox:"allow-same-origin"});if(v&&N!==null){if(S)return e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})});let g=N;try{const K=JSON.parse(N);g=JSON.stringify(K,null,2)}catch{}return e.jsx("div",{className:"w-full h-full overflow-auto p-6",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-auto",children:e.jsx("code",{children:g})})})}return T&&N!==null?S?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("div",{className:"w-full h-full overflow-auto p-6",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-auto whitespace-pre-wrap",children:e.jsx("code",{children:N})})}):w?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:E,alt:n.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}),e.jsx(R,{variant:"secondary",size:"icon",className:"absolute bottom-3 right-3 h-8 w-8 opacity-70 hover:opacity-100 transition-opacity",onClick:()=>y(!0),children:e.jsx(ys,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[D(n.type),e.jsx("p",{className:"text-sm",children:"Preview not available for this file type"}),e.jsxs(R,{variant:"outline",onClick:()=>m(n),children:[e.jsx(es,{className:"mr-2 h-4 w-4"}),"Download to view"]})]})};return e.jsxs(e.Fragment,{children:[e.jsx(pe,{open:l,onOpenChange:c,children:e.jsxs(ge,{className:"max-w-[90vw] w-[90vw] max-h-[90vh] h-[90vh] p-0 gap-0 flex flex-col [&>button]:hidden",children:[e.jsx(ve,{className:"px-6 pt-6 pb-4 border-b flex-shrink-0",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[D(n.type),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-3",children:[e.jsx(je,{className:"text-xl truncate",children:n.name}),e.jsx("p",{className:"text-sm text-muted-foreground flex-shrink-0",children:n.type})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>p(n),title:"Copy path to clipboard",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>m(n),title:"Download",children:e.jsx(es,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>c(!1),title:"Close",children:e.jsx(cs,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 flex overflow-hidden",children:e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 relative flex items-center justify-center bg-muted/30 p-6 overflow-hidden",children:[j&&e.jsx("button",{type:"button",onClick:()=>u("prev"),className:"absolute left-4 top-1/2 -translate-y-1/2 rounded-full border bg-background/80 p-2 shadow-sm hover:bg-background transition-colors","aria-label":"Previous resource",children:e.jsx(zs,{className:"h-5 w-5"})}),h&&e.jsx("button",{type:"button",onClick:()=>u("next"),className:"absolute right-4 top-1/2 -translate-y-1/2 rounded-full border bg-background/80 p-2 shadow-sm hover:bg-background transition-colors","aria-label":"Next resource",children:e.jsx($s,{className:"h-5 w-5"})}),I()]}),e.jsx("div",{className:"border-t p-6 flex-shrink-0 bg-background",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-x-6 gap-y-2 md:grid-cols-2 text-sm",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(La,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Size:"}),e.jsx("span",{children:q(n.size)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Uploaded:"}),e.jsx("span",{children:L(n.uploadedAt)})]})]}),e.jsx("div",{className:"space-y-2",children:n.metadata.tags&&n.metadata.tags.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pa,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Tags:"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:n.metadata.tags.map(g=>e.jsx(Me,{variant:"secondary",className:"text-xs",children:g},g))})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[n.metadata.description?e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Description:"}),e.jsx("span",{className:"truncate flex-1",title:n.metadata.description,children:n.metadata.description})]}):e.jsx("div",{className:"flex-1"}),n.metadata.generationPrompt&&e.jsxs(R,{size:"sm",className:"h-6 text-xs px-2 flex-shrink-0",onClick:()=>{navigator.clipboard.writeText(n.metadata.generationPrompt||"")},children:[e.jsx(Xe,{className:"h-2.5 w-2.5 mr-1"}),"Copy Prompt"]})]})]})})]})})]})}),x&&(w||b)&&e.jsxs("div",{className:"fixed inset-0 z-[100] bg-black/95 flex items-center justify-center",onClick:()=>y(!1),children:[e.jsx(R,{variant:"ghost",size:"icon",className:"absolute top-4 right-4 h-10 w-10 text-white hover:bg-white/20",onClick:()=>y(!1),children:e.jsx(cs,{className:"h-6 w-6"})}),e.jsx("img",{src:E,alt:n.name,className:"max-w-[95vw] max-h-[95vh] object-contain",onClick:g=>g.stopPropagation()})]})]})}function Mt(){const[l,c]=t.useState([]),[n,p]=t.useState(!0),[m,u]=t.useState(!1),[j,h]=t.useState(""),[N,P]=t.useState(!1),[S,d]=t.useState([]),[x,y]=t.useState(""),[E,w]=t.useState(""),[b,_]=t.useState([]),[z,M]=t.useState(!1),[T,A]=t.useState(!1),[v,k]=t.useState(!1),[q,L]=t.useState(null),[D,I]=t.useState(null),[g,K]=t.useState(null),[Y,H]=t.useState(1),ee=12,V=t.useRef(null),{toast:O}=$e();t.useEffect(()=>{Q()},[]);const Q=async()=>{try{p(!0);const r=await(await fetch(`${ae}/api/v1/resources`)).json();r.success&&c(r.data||[])}catch(s){console.error("Failed to fetch resources:",s)}finally{p(!1)}},o=s=>{s.length!==0&&_(Array.from(s))},te=async()=>{if(b.length!==0){u(!0);try{for(const s of b){const r=new FormData;if(r.append("file",s),r.append("tags",S.join(", ")),r.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:r})).ok)throw new Error("Upload failed")}d([]),y(""),w(""),_([]),P(!1),await Q(),O({title:"Upload successful",description:`${b.length} file(s) uploaded successfully`})}catch(s){console.error("Upload failed:",s),O({title:"Upload failed",description:"Failed to upload files. Please try again.",variant:"destructive"})}finally{u(!1)}}},i=()=>{d([]),y(""),w(""),_([]),P(!1)},F=s=>{if(s.key==="Enter"){s.preventDefault();const r=x.trim();r&&!S.includes(r)&&(d([...S,r]),y(""))}},se=s=>{d(S.filter(r=>r!==s))},X=s=>{_(b.filter((r,f)=>f!==s))},re=async()=>{if(g)try{if((await fetch(`${ae}/api/v1/resources/${g.id}`,{method:"DELETE"})).ok)await Q(),O({title:"Resource deleted",description:`${g.name} has been deleted`});else throw new Error("Delete failed")}catch(s){console.error("Failed to delete resource:",s),O({title:"Delete failed",description:"Failed to delete resource. Please try again.",variant:"destructive"})}finally{K(null)}},ue=async s=>{try{const r=`.nut/resources/files/${s.path}`;await Ca(r),O({title:"Path copied!",description:`Copied ${r} to clipboard`})}catch(r){console.error("Failed to copy path:",r),O({title:"Failed to copy",description:"Unable to copy path to clipboard",variant:"destructive"})}},he=s=>{if(s===0)return"0 B";const r=1024,f=["B","KB","MB","GB"],Z=Math.floor(Math.log(s)/Math.log(r));return parseFloat((s/Math.pow(r,Z)).toFixed(2))+" "+f[Z]},Ie=(s,r)=>{const f=r.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||f.endsWith(".svg")?e.jsx(fs,{className:"h-4 w-4"}):e.jsx(Ne,{className:"h-4 w-4"}):s.startsWith("video/")?e.jsx(gs,{className:"h-4 w-4"}):s.startsWith("audio/")?e.jsx(xs,{className:"h-4 w-4"}):s==="application/pdf"||f.endsWith(".pdf")?e.jsx(we,{className:"h-4 w-4"}):f.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(ss,{className:"h-4 w-4"}):s==="application/json"||f.endsWith(".json")?e.jsx(ps,{className:"h-4 w-4"}):s.includes("spreadsheet")||s.includes("excel")||f.match(/\.(xls|xlsx|csv)$/)?e.jsx(vs,{className:"h-4 w-4"}):s.includes("presentation")||s.includes("powerpoint")||f.match(/\.(ppt|pptx)$/)?e.jsx(bs,{className:"h-4 w-4"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(we,{className:"h-4 w-4"}):s.includes("font")||f.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(js,{className:"h-4 w-4"}):e.jsx(Ze,{className:"h-4 w-4"})},Re=(s,r)=>{const f=r.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||f.endsWith(".svg")?e.jsx(fs,{className:"h-16 w-16"}):e.jsx(Ne,{className:"h-16 w-16"}):s.startsWith("video/")?e.jsx(gs,{className:"h-16 w-16"}):s.startsWith("audio/")?e.jsx(xs,{className:"h-16 w-16"}):s==="application/pdf"||f.endsWith(".pdf")?e.jsx(we,{className:"h-16 w-16"}):f.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(ss,{className:"h-16 w-16"}):s==="application/json"||f.endsWith(".json")?e.jsx(ps,{className:"h-16 w-16"}):s.includes("spreadsheet")||s.includes("excel")||f.match(/\.(xls|xlsx|csv)$/)?e.jsx(vs,{className:"h-16 w-16"}):s.includes("presentation")||s.includes("powerpoint")||f.match(/\.(ppt|pptx)$/)?e.jsx(bs,{className:"h-16 w-16"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(we,{className:"h-16 w-16"}):s.includes("font")||f.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(js,{className:"h-16 w-16"}):e.jsx(Ze,{className:"h-16 w-16"})},xe=s=>{const r=s.name.toLowerCase(),f=s.type.startsWith("image/");return s.type==="image/svg+xml"||r.endsWith(".svg")?e.jsx("div",{className:"w-full h-32 flex items-center justify-center bg-muted/30 rounded-md border overflow-hidden p-2",children:e.jsx("img",{src:`${ae}/api/v1/resources/${s.id}`,alt:s.name,className:"w-full h-full object-contain"})}):f&&s.thumbnailPath?e.jsx("img",{src:`${ae}/api/v1/resources/${s.id}/thumbnail`,alt:s.name,className:"w-full h-32 object-cover rounded-md border",onError:ne=>{ne.currentTarget.style.display="none"}}):e.jsx("div",{className:"w-full h-32 flex items-center justify-center bg-muted/50 rounded-md border",children:e.jsx("div",{className:"text-muted-foreground",children:Re(s.type,s.name)})})},ie=l.filter(s=>{if(!j)return!0;const r=j.toLowerCase();return s.name.toLowerCase().includes(r)||s.metadata.description?.toLowerCase().includes(r)||s.metadata.tags?.some(f=>f.toLowerCase().includes(r))}),J=Math.ceil(ie.length/ee),Ce=(Y-1)*ee,Te=ie.slice(Ce,Ce+ee);t.useEffect(()=>{H(1)},[j]);const ze=s=>{s.preventDefault(),s.stopPropagation()},ke=s=>{s.preventDefault(),s.stopPropagation(),s.dataTransfer.files&&s.dataTransfer.files.length>0&&o(s.dataTransfer.files)},De=(s,r)=>{if(r.target.closest("button"))return;L(s);const Z=ie.findIndex(ne=>ne.id===s.id);I(Z>=0?Z:null)},Ge=s=>{window.open(`${ae}/api/v1/resources/${s.id}?download=true`)},Ae=async(s,r)=>{u(!0);try{const f=await fetch(s);if(!f.ok)throw new Error("Failed to download generated image");const Z=await f.blob(),ne=`generated-image-${Date.now()}.png`,de=new FormData;de.append("file",Z,ne),de.append("tags",S.join(","));const ce=r?.prompt?`Generated with: "${r.prompt}"${r.model?` (${r.model})`:""}`:E;if(de.append("description",ce),r?.prompt&&de.append("generationPrompt",r.prompt),r?.model&&de.append("generationModel",r.model),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:de})).ok)throw new Error("Upload failed");await Q(),O({title:"Image saved",description:"Generated image has been saved to resources"})}catch(f){throw console.error("Failed to save generated image:",f),O({title:"Save failed",description:f instanceof Error?f.message:"Failed to save generated image",variant:"destructive"}),f}finally{u(!1)}},Le=s=>{window.dispatchEvent(new CustomEvent("customize-prompt-in-assistant",{detail:{prompt:s}}))},qe=async s=>{u(!0);try{const r=await fetch(s);if(!r.ok)throw new Error("Failed to download generated audio");const f=await r.blob();let Z="mp3";const ne=r.headers.get("content-type");ne?.includes("wav")?Z="wav":ne?.includes("flac")?Z="flac":s.includes(".wav")?Z="wav":s.includes(".flac")&&(Z="flac");const de=`generated-audio-${Date.now()}.${Z}`,ce=new FormData;if(ce.append("file",f,de),ce.append("tags",S.join(",")),ce.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:ce})).ok)throw new Error("Upload failed");await Q(),O({title:"Audio saved",description:"Generated audio has been saved to resources"})}catch(r){throw console.error("Failed to save generated audio:",r),O({title:"Save failed",description:r instanceof Error?r.message:"Failed to save generated audio",variant:"destructive"}),r}finally{u(!1)}},He=async s=>{u(!0);try{const r=await fetch(s);if(!r.ok)throw new Error("Failed to download generated video");const f=await r.blob();let Z="mp4";(r.headers.get("content-type")?.includes("webm")||s.includes(".webm"))&&(Z="webm");const de=`generated-video-${Date.now()}.${Z}`,ce=new FormData;if(ce.append("file",f,de),ce.append("tags",S.join(",")),ce.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:ce})).ok)throw new Error("Upload failed");await Q(),O({title:"Video saved",description:"Generated video has been saved to resources"})}catch(r){throw console.error("Failed to save generated video:",r),O({title:"Save failed",description:r instanceof Error?r.message:"Failed to save generated video",variant:"destructive"}),r}finally{u(!1)}},a=s=>{if(D===null)return;const r=s==="next"?D+1:D-1;if(r<0||r>=ie.length)return;const f=ie[r];I(r),L(f)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Resources"}),e.jsx("p",{className:"text-muted-foreground",children:"Upload and generate media assets for your project"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(ja,{children:[e.jsx(ya,{asChild:!0,children:e.jsxs(R,{variant:"outline",size:"sm",children:[e.jsx(Ee,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Generate"}),e.jsx(ba,{className:"h-3 w-3 ml-1 opacity-50"})]})}),e.jsxs(wa,{align:"end",className:"min-w-[var(--radix-dropdown-menu-trigger-width)]",children:[e.jsxs(Je,{onClick:()=>M(!0),children:[e.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Image"]}),e.jsxs(Je,{onClick:()=>A(!0),children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Audio"]}),e.jsxs(Je,{onClick:()=>k(!0),children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Video"]})]})]}),e.jsxs(R,{size:"sm",onClick:()=>P(!N),children:[e.jsx(hs,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Upload Resources"})]})]})]}),e.jsx(pe,{open:N,onOpenChange:s=>!s&&i(),children:e.jsxs(ge,{className:"max-w-2xl",children:[e.jsxs(ve,{children:[e.jsx(je,{children:"Upload Resource"}),e.jsx(ds,{children:"Add files to your project resources"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"border-2 border-dashed border-muted-foreground/25 rounded-lg p-8 text-center cursor-pointer hover:border-muted-foreground/50 transition-colors",onDragOver:ze,onDrop:ke,onClick:()=>V.current?.click(),children:[e.jsx($a,{className:"mx-auto h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"mt-2 text-sm font-medium",children:"Drop files here or click to browse"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Support for images, documents, and other files"})]}),e.jsx("input",{ref:V,type:"file",multiple:!0,className:"hidden",onChange:s=>s.target.files&&o(s.target.files)}),b.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Selected Files (",b.length,")"]}),e.jsx("div",{className:"border rounded-lg p-3 max-h-40 overflow-y-auto space-y-2",children:b.map((s,r)=>e.jsxs("div",{className:"flex items-center justify-between text-sm bg-muted/50 rounded px-3 py-2",children:[e.jsx("span",{className:"truncate flex-1",children:s.name}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>X(r),className:"h-6 w-6 p-0 ml-2",children:e.jsx(us,{className:"h-3 w-3"})})]},r))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"tags",children:"Tags"}),e.jsx(We,{id:"tags",placeholder:"Type a tag and press Enter",value:x,onChange:s=>y(s.target.value),onKeyDown:F}),S.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:S.map(s=>e.jsxs(Me,{variant:"secondary",className:"text-xs",children:[s,e.jsx("button",{type:"button",onClick:()=>se(s),className:"ml-1 hover:text-destructive",children:"×"})]},s))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"description",children:"Description"}),e.jsx(ye,{id:"description",placeholder:"Brief description of this resource...",value:E,onChange:s=>w(s.target.value),rows:3})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:i,disabled:m,children:"Cancel"}),e.jsx(R,{onClick:te,disabled:b.length===0||m,children:m?"Uploading...":`Upload ${b.length>0?`(${b.length})`:""}`})]})]})]})}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs("div",{className:"relative flex-1 w-full",children:[e.jsx(Ea,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(We,{placeholder:"Search resources...",value:j,onChange:s=>h(s.target.value),className:"pl-8"})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:n?Array.from({length:6}).map((s,r)=>e.jsxs(Ye,{className:"animate-pulse",children:[e.jsxs(ms,{children:[e.jsx("div",{className:"h-4 bg-muted rounded w-3/4"}),e.jsx("div",{className:"h-3 bg-muted rounded w-1/2"})]}),e.jsx(Qe,{children:e.jsx("div",{className:"h-20 bg-muted rounded"})})]},r)):ie.length>0?Te.map(s=>e.jsxs(Ye,{className:"hover:shadow-lg hover:bg-muted transition-all cursor-pointer",onClick:r=>De(s,r),children:[e.jsxs(ms,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[Ie(s.type,s.name),e.jsx(_a,{className:"text-sm font-medium truncate",children:s.name})]}),e.jsxs(Sa,{className:"text-xs",children:[he(s.size)," • ",new Date(s.uploadedAt).toLocaleDateString()]}),e.jsxs("div",{className:"flex justify-end space-x-1 mt-2",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),ue(s)},title:"Copy path to clipboard",children:e.jsx(Xe,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),Ge(s)},children:e.jsx(es,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),K(s)},children:e.jsx(us,{className:"h-3 w-3"})})]})]}),e.jsxs(Qe,{className:"pt-0",children:[e.jsx("div",{className:"mb-3",children:xe(s)}),s.metadata.description&&e.jsx("p",{className:"text-sm text-muted-foreground mb-2 line-clamp-2",children:s.metadata.description}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:s.metadata.tags.map(r=>e.jsx(Me,{variant:"secondary",className:"text-xs",children:r},r))})]})]},s.id)):e.jsx("div",{className:"col-span-full",children:e.jsx(Ye,{children:e.jsxs(Qe,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(Na,{className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("h3",{className:"mt-4 text-lg font-semibold",children:"No resources yet"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground text-center max-w-sm",children:"Upload files to get started. Resources can be referenced by LLMs and team members for enhanced context."}),e.jsxs(R,{className:"mt-4",onClick:()=>P(!0),children:[e.jsx(hs,{className:"mr-2 h-4 w-4"}),"Add First Resource"]})]})})})}),ie.length>ee&&e.jsxs("div",{className:"flex items-center justify-center gap-4 pt-4 pb-8",children:[e.jsxs(R,{variant:Y===1?"outline":"default",size:"sm",onClick:()=>H(s=>Math.max(1,s-1)),disabled:Y===1,children:[e.jsx(zs,{className:"h-4 w-4 mr-1"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",Y," of ",J]}),e.jsxs(R,{variant:Y===J?"outline":"default",size:"sm",onClick:()=>H(s=>Math.min(J,s+1)),disabled:Y===J,children:["Next",e.jsx($s,{className:"h-4 w-4 ml-1"})]})]}),m&&e.jsx("div",{className:"fixed bottom-4 right-4 bg-background border rounded-lg shadow-lg p-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-primary"}),e.jsx("span",{className:"text-sm",children:"Uploading files..."})]})}),e.jsx(Ja,{open:z,onOpenChange:M,onSave:Ae,onCustomizeInAssistant:Le}),e.jsx(xt,{open:T,onOpenChange:A,onSave:qe}),e.jsx(ft,{open:v,onOpenChange:k,onSave:He}),e.jsx(pt,{open:!!q,onOpenChange:s=>{s||L(null),s||I(null)},resource:q,onCopyPath:ue,onDownload:Ge,onNavigate:a,canNavigatePrev:D!==null&&D>0,canNavigateNext:D!==null&&D<ie.length-1}),e.jsx(pe,{open:!!g,onOpenChange:s=>!s&&K(null),children:e.jsxs(ge,{className:"max-w-md",children:[e.jsxs(ve,{children:[e.jsx(je,{children:"Delete Resource"}),e.jsxs(ds,{children:["Are you sure you want to delete ",e.jsx("strong",{children:g?.name}),"? This action cannot be undone."]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:()=>K(null),children:"Cancel"}),e.jsx(R,{variant:"destructive",onClick:re,children:"Delete"})]})]})})]})}export{Mt as default};
|