import{q as A,a as w,s as D,u as E,j as s,P as re,I as de,r as i,R as Z,k as ue,i as pe,l as he,t as me}from"./index-BIVkyPD7.js";import{T as R}from"./TooltipText-59Xfc1Ui.js";import{X as K}from"./x-sRJSvoLm.js";/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ge=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],ye=A("arrow-left",ge);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const xe=[["path",{d:"M2 10v3",key:"1fnikh"}],["path",{d:"M6 6v11",key:"11sgs0"}],["path",{d:"M10 3v18",key:"yhl04a"}],["path",{d:"M14 8v7",key:"3a1oy3"}],["path",{d:"M18 5v13",key:"123xd1"}],["path",{d:"M22 10v3",key:"154ddg"}]],je=A("audio-lines",xe);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const _e=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}]],be=A("badge",_e);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ve=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],fe=A("box",ve);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ce=[["path",{d:"m12.296 3.464 3.02 3.956",key:"qash78"}],["path",{d:"M20.2 6 3 11l-.9-2.4c-.3-1.1.3-2.2 1.3-2.5l13.5-4c1.1-.3 2.2.3 2.5 1.3z",key:"1h7j8b"}],["path",{d:"M3 11h18v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"4lm6w1"}],["path",{d:"m6.18 5.276 3.1 3.899",key:"zjj9t3"}]],Ne=A("clapperboard",Ce);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ke=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],V=A("copy",ke);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const we=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]],Se=A("film",we);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ae=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Pe=A("search",Ae);/**
 * @license lucide-react v1.8.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ie=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],q=A("upload",Ie),Be=["image","decal","audio","mesh","model","video","animation"];function X(e){if(e.scope==="place"&&typeof e.placeId=="number")return{placeId:String(e.placeId)}}function L(e){const l=X(e);return l?`?placeId=${encodeURIComponent(l.placeId)}`:""}function G(e){return`/api/assets/${encodeURIComponent(e.scope)}/${encodeURIComponent(e.category)}`}function M(e,l){return`${G(e)}/${encodeURIComponent(l)}`}async function J(e){return w.get(G(e),X(e))}async function Re(e){const u=(await Promise.all(Be.map(a=>J({...e,category:a})))).flatMap(a=>a.assets);return u.sort((a,n)=>n.createdAt.localeCompare(a.createdAt)||n.id.localeCompare(a.id)),{assets:u,totalCount:u.length}}async function Le(e){return w.post(`${G(e)}/rescan${L(e)}`,{})}async function $e(e,l,u){return(await w.patch(`${M(e,l)}${L(e)}`,u)).asset}async function Ee(e,l,u){return(await w.post(`${M(e,l)}/upload${L(e)}`,u)).asset}async function Ue(e,l){return(await w.post(`${M(e,l)}/status-refresh${L(e)}`,{})).asset}async function De(e,l,u){const a={...e,placeId:u??e.placeId};return w.post(`${M(e,l)}/usage-scan${L(a)}`,{})}function Q(e){return e.fileUrl?`${D}${e.fileUrl}`:`${D}/api/assets/${e.scope.kind}/${e.category}/${encodeURIComponent(e.id)}/file${L({scope:e.scope.kind,placeId:e.scope.kind==="place"?e.scope.placeId:void 0})}`}function Me(e){return e.previewUrl?`${D}${e.previewUrl}`:`${D}/api/assets/${e.scope.kind}/${e.category}/${encodeURIComponent(e.id)}/preview${L({scope:e.scope.kind,placeId:e.scope.kind==="place"?e.scope.placeId:void 0})}`}const Fe="_page_1ld7j_1",Te="_headerRow_1ld7j_9",Oe="_headerMeta_1ld7j_28",He="_toolbar_1ld7j_41",ze="_toolbarActions_1ld7j_49",Ke="_actionRow_1ld7j_50",Ge="_copyRow_1ld7j_51",Ye="_buttonRow_1ld7j_52",We="_segmented_1ld7j_59",Ve="_segmentedActive_1ld7j_83",Ze="_filterLabel_1ld7j_88",qe="_commandButton_1ld7j_106",Xe="_primaryButton_1ld7j_107",Je="_iconButton_1ld7j_108",Qe="_grid_1ld7j_154",es="_assetCard_1ld7j_160",ss="_assetCardSelected_1ld7j_174",ts="_thumbnailWrap_1ld7j_179",as="_thumbnail_1ld7j_179",ls="_thumbnailFallback_1ld7j_195",ns="_assetCardBody_1ld7j_206",os="_assetName_1ld7j_213",is="_assetMeta_1ld7j_221",cs="_statusChip_1ld7j_228",rs="_categoryPill_1ld7j_229",ds="_status_uploaded_1ld7j_242",us="_status_failed_1ld7j_247",ps="_status_processing_1ld7j_252",hs="_status_uploading_1ld7j_253",ms="_assetId_1ld7j_258",gs="_scopeText_1ld7j_259",ys="_muted_1ld7j_260",xs="_emptyState_1ld7j_265",js="_notice_1ld7j_266",_s="_errorState_1ld7j_267",bs="_messageState_1ld7j_268",vs="_proNotice_1ld7j_298",fs="_drawer_1ld7j_314",Cs="_settingsDrawer_1ld7j_328",Ns="_detailPopupLayer_1ld7j_332",ks="_detailDialog_1ld7j_348",ws="_detailDialogHeader_1ld7j_365",Ss="_detailTitleBlock_1ld7j_376",As="_detailEyebrow_1ld7j_398",Ps="_detailHeaderActions_1ld7j_407",Is="_detailDialogBody_1ld7j_415",Bs="_detailPreviewPane_1ld7j_424",Rs="_detailPreview_1ld7j_424",Ls="_detailPreviewFallback_1ld7j_436",$s="_detailContentPane_1ld7j_463",Es="_formStack_1ld7j_469",Us="_drawerHeader_1ld7j_473",Ds="_preview_1ld7j_492",Ms="_previewFallback_1ld7j_493",Fs="_detailSection_1ld7j_520",Ts="_noticeList_1ld7j_521",Os="_settingsPanel_1ld7j_522",Hs="_field_1ld7j_539",zs="_twoColumn_1ld7j_559",Ks="_detailGrid_1ld7j_576",Gs="_compactMeta_1ld7j_577",Ys="_hashText_1ld7j_604",Ws="_usageList_1ld7j_608",Vs="_usageItem_1ld7j_614",Zs="_toggleRow_1ld7j_641",qs="_inlineHelp_1ld7j_655",t={page:Fe,headerRow:Te,headerMeta:Oe,toolbar:He,toolbarActions:ze,actionRow:Ke,copyRow:Ge,buttonRow:Ye,segmented:We,segmentedActive:Ve,filterLabel:Ze,commandButton:qe,primaryButton:Xe,iconButton:Je,grid:Qe,assetCard:es,assetCardSelected:ss,thumbnailWrap:ts,thumbnail:as,thumbnailFallback:ls,assetCardBody:ns,assetName:os,assetMeta:is,statusChip:cs,categoryPill:rs,status_uploaded:ds,status_failed:us,status_processing:ps,status_uploading:hs,assetId:ms,scopeText:gs,muted:ys,emptyState:xs,notice:js,errorState:_s,messageState:bs,proNotice:vs,drawer:fs,settingsDrawer:Cs,detailPopupLayer:Ns,detailDialog:ks,detailDialogHeader:ws,detailTitleBlock:Ss,detailEyebrow:As,detailHeaderActions:Ps,detailDialogBody:Is,detailPreviewPane:Bs,detailPreview:Rs,detailPreviewFallback:Ls,detailContentPane:$s,formStack:Es,drawerHeader:Us,preview:Ds,previewFallback:Ms,detailSection:Fs,noticeList:Ts,settingsPanel:Os,field:Hs,twoColumn:zs,detailGrid:Ks,compactMeta:Gs,hashText:Ys,usageList:Ws,usageItem:Vs,toggleRow:Zs,inlineHelp:qs},Xs={image:de,decal:be,audio:je,mesh:fe,model:re,video:Se,animation:Ne};function B(e,l){return l(`assets.category.${e}`,e)}function z(e,l){return l(`assets.status.${e}`,e)}function Js(e){return e.category==="image"||e.category==="decal"}function Qs({assets:e,selectedAssetId:l,onSelect:u}){const{t:a}=E();return e.length===0?s.jsxs("div",{className:t.emptyState,children:[s.jsx("p",{children:a("assets.empty.title","No assets yet")}),s.jsx("span",{children:a("assets.empty.body","Choose a scope and category, then rescan that inbox folder.")})]}):s.jsx("div",{className:t.grid,children:e.map(n=>{const _=Xs[n.category];return s.jsxs("button",{type:"button",className:[t.assetCard,l===n.id?t.assetCardSelected:""].filter(Boolean).join(" "),onClick:()=>u(n.id),children:[s.jsx("span",{className:t.thumbnailWrap,children:Js(n)?s.jsx("img",{className:t.thumbnail,src:Me(n),alt:n.displayName,loading:"lazy"}):s.jsx("span",{className:t.thumbnailFallback,"aria-hidden":"true",children:s.jsx(_,{size:30})})}),s.jsxs("span",{className:t.assetCardBody,children:[s.jsx("span",{className:t.assetName,children:n.displayName}),s.jsxs("span",{className:t.assetMeta,children:[s.jsx("span",{className:t.categoryPill,children:B(n.category,a)}),s.jsx("span",{className:`${t.statusChip} ${t[`status_${n.status}`]??""}`,children:z(n.status,a)})]}),s.jsxs("span",{className:t.assetMeta,children:[s.jsx("span",{className:t.scopeText,children:n.scope.kind==="shared"?a("assets.scope.shared","Shared"):a("assets.scope.place","Current Place")}),s.jsx("span",{className:t.assetId,children:n.roblox.assetId?`#${n.roblox.assetId}`:a("assets.status.localOnly","Local only")})]})]})]},n.id)})})}function et(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function st(e){return e.category==="image"||e.category==="decal"}function tt({asset:e,busyAction:l,canUpload:u,onClose:a,onSave:n,onUpload:_,onRefreshStatus:p,onScanUsage:m}){const{t:o}=E(),f=i.useRef(null),[g,k]=i.useState(""),[y,C]=i.useState("");if(i.useEffect(()=>{k((e==null?void 0:e.displayName)??""),C((e==null?void 0:e.description)??"")},[e==null?void 0:e.description,e==null?void 0:e.displayName,e==null?void 0:e.id]),i.useEffect(()=>{var c;if(!e)return;(c=f.current)==null||c.focus();const d=b=>{b.key==="Escape"&&a()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[e,a]),!e)return null;const P=e.status==="processing"&&!!(e.roblox.operationId??e.roblox.operationPath),x=!!e.roblox.assetUri;return s.jsx("div",{className:t.detailPopupLayer,onClick:a,role:"presentation",children:s.jsxs("section",{ref:f,className:t.detailDialog,role:"dialog","aria-modal":"true","aria-label":o("assets.detail.title","Asset details"),tabIndex:-1,onClick:d=>d.stopPropagation(),children:[s.jsxs("div",{className:t.detailDialogHeader,children:[s.jsxs("div",{className:t.detailTitleBlock,children:[s.jsxs("span",{className:t.detailEyebrow,children:[B(e.category,o)," · ",z(e.status,o)]}),s.jsx("h2",{children:o("assets.detail.title","Asset details")}),s.jsx("span",{children:e.id})]}),s.jsxs("div",{className:t.detailHeaderActions,children:[s.jsx(R,{text:u?o("assets.upload.open.tooltip","Upload this local file to Roblox with the saved API key."):o("assets.proOnly.tooltip","Roblox upload is available on Pro."),children:s.jsxs("button",{type:"button",className:t.commandButton,disabled:!u,onClick:_,children:[s.jsx(q,{size:15}),o("assets.upload.open","Upload")]})}),s.jsxs("button",{type:"button",className:t.commandButton,disabled:!P||l==="status-refresh",onClick:()=>void p(),children:[s.jsx(Z,{size:15}),o("assets.detail.refreshStatus","Refresh")]}),s.jsxs("button",{type:"button",className:t.commandButton,disabled:!e.roblox.assetId||l==="usage-scan",onClick:()=>void m(),children:[s.jsx(Pe,{size:15}),o("assets.detail.scanUsage","Scan usage")]}),s.jsx(R,{text:o("common.close","Close"),children:s.jsx("button",{type:"button",className:t.iconButton,onClick:a,"aria-label":o("common.close","Close"),children:s.jsx(K,{size:16})})})]})]}),s.jsxs("div",{className:t.detailDialogBody,children:[s.jsx("div",{className:t.detailPreviewPane,children:st(e)?s.jsx("img",{className:t.detailPreview,src:Q(e),alt:e.displayName}):s.jsxs("div",{className:t.detailPreviewFallback,children:[s.jsx("span",{children:B(e.category,o)}),s.jsx("code",{children:e.file.original})]})}),s.jsxs("div",{className:t.detailContentPane,children:[s.jsxs("div",{className:t.formStack,children:[s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:o("assets.detail.displayName","Display name")}),s.jsx("input",{value:g,onChange:d=>k(d.target.value)})]}),s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:o("assets.detail.description","Description")}),s.jsx("textarea",{value:y,rows:3,onChange:d=>C(d.target.value)})]}),s.jsx("button",{type:"button",className:t.primaryButton,disabled:l==="update",onClick:()=>void n(g,y),children:o("assets.detail.save","Save metadata")})]}),s.jsxs("section",{className:t.detailSection,children:[s.jsx("h3",{children:o("assets.detail.localFile","Local file")}),s.jsxs("dl",{className:t.detailGrid,children:[s.jsx("dt",{children:o("assets.detail.category","Category")}),s.jsx("dd",{children:B(e.category,o)}),s.jsx("dt",{children:o("assets.detail.scope","Scope")}),s.jsx("dd",{children:e.scope.kind==="shared"?o("assets.scope.shared","Shared"):o("assets.scope.place","Current Place")}),s.jsx("dt",{children:o("assets.detail.mimeType","Type")}),s.jsx("dd",{children:e.file.mimeType}),s.jsx("dt",{children:o("assets.detail.size","Size")}),s.jsx("dd",{children:et(e.file.sizeBytes)}),s.jsx("dt",{children:o("assets.detail.source","Source")}),s.jsx("dd",{children:e.source.originalPath}),s.jsx("dt",{children:o("assets.detail.sha256","SHA-256")}),s.jsx("dd",{className:t.hashText,children:e.file.sha256})]})]}),s.jsxs("section",{className:t.detailSection,children:[s.jsx("h3",{children:o("assets.detail.roblox","Roblox")}),s.jsxs("dl",{className:t.detailGrid,children:[s.jsx("dt",{children:o("assets.detail.status","Status")}),s.jsx("dd",{children:z(e.status,o)}),s.jsx("dt",{children:o("assets.detail.assetId","Asset ID")}),s.jsx("dd",{children:e.roblox.assetId??o("assets.status.localOnly","Local only")}),e.roblox.errorMessage&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:o("assets.detail.error","Error")}),s.jsx("dd",{children:e.roblox.errorMessage})]})]}),s.jsxs("div",{className:t.copyRow,children:[s.jsxs("button",{type:"button",className:t.commandButton,disabled:!e.roblox.assetId,onClick:()=>{var d;return e.roblox.assetId&&void((d=navigator.clipboard)==null?void 0:d.writeText(e.roblox.assetId))},children:[s.jsx(V,{size:15}),o("assets.detail.copyAssetId","Copy ID")]}),s.jsxs("button",{type:"button",className:t.commandButton,disabled:!x,onClick:()=>{var d;return e.roblox.assetUri&&void((d=navigator.clipboard)==null?void 0:d.writeText(e.roblox.assetUri))},children:[s.jsx(V,{size:15}),o("assets.detail.copyUri","Copy URI")]})]})]}),s.jsxs("section",{className:t.detailSection,children:[s.jsx("h3",{children:o("assets.detail.usedInPlace","Used in this Place")}),e.usage.references.length===0?s.jsx("p",{className:t.muted,children:o("assets.detail.noUsage","No local sync references found yet.")}):s.jsx("div",{className:t.usageList,children:e.usage.references.map((d,c)=>s.jsxs("div",{className:t.usageItem,children:[s.jsx("strong",{children:d.kind==="property"?d.instancePath:d.filePath}),s.jsx("span",{children:d.property??o("assets.detail.line","line {line}").replace("{line}",String(d.line??"-"))}),s.jsx("code",{children:d.value})]},`${d.kind}-${c}`))})]})]})]})]})})}function at(e){return e.category==="image"||e.category==="decal"}function lt({asset:e,open:l,canUpload:u,busyAction:a,onClose:n,onBack:_,onUpload:p}){const{t:m}=E(),o=i.useRef(null),[f,g]=i.useState(""),[k,y]=i.useState(""),[C,P]=i.useState("user"),[x,d]=i.useState("");return i.useEffect(()=>{g((e==null?void 0:e.displayName)??""),y((e==null?void 0:e.description)??""),d("")},[e==null?void 0:e.description,e==null?void 0:e.displayName,e==null?void 0:e.id]),i.useEffect(()=>{var b;if(!l||!e)return;(b=o.current)==null||b.focus();const c=N=>{N.key==="Escape"&&n()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[e,n,l]),!l||!e?null:s.jsx("div",{className:t.detailPopupLayer,onClick:n,role:"presentation",children:s.jsxs("section",{ref:o,className:t.detailDialog,role:"dialog","aria-modal":"true","aria-label":m("assets.upload.title","Upload asset"),tabIndex:-1,onClick:c=>c.stopPropagation(),children:[s.jsxs("div",{className:t.detailDialogHeader,children:[s.jsxs("div",{className:t.detailTitleBlock,children:[s.jsxs("span",{className:t.detailEyebrow,children:[B(e.category,m)," · ",m("assets.upload.intent","Upload to Roblox")]}),s.jsx("h2",{children:m("assets.upload.title","Upload asset")}),s.jsx("span",{children:e.displayName})]}),s.jsxs("div",{className:t.detailHeaderActions,children:[s.jsxs("button",{type:"button",className:t.commandButton,onClick:_,children:[s.jsx(ye,{size:15}),m("assets.upload.backToDetails","Back to details")]}),s.jsx(R,{text:m("common.close","Close"),children:s.jsx("button",{type:"button",className:t.iconButton,onClick:n,"aria-label":m("common.close","Close"),children:s.jsx(K,{size:16})})})]})]}),s.jsxs("div",{className:t.detailDialogBody,children:[s.jsx("div",{className:t.detailPreviewPane,children:at(e)?s.jsx("img",{className:t.detailPreview,src:Q(e),alt:e.displayName}):s.jsxs("div",{className:t.detailPreviewFallback,children:[s.jsx("span",{children:B(e.category,m)}),s.jsx("code",{children:e.file.original})]})}),s.jsxs("div",{className:t.detailContentPane,children:[!u&&s.jsx("div",{className:t.notice,children:m("assets.proOnly.upload","Roblox upload is available on Pro.")}),s.jsxs("dl",{className:t.compactMeta,children:[s.jsx("dt",{children:m("assets.detail.category","Category")}),s.jsx("dd",{children:B(e.category,m)}),s.jsx("dt",{children:m("assets.detail.source","Source")}),s.jsx("dd",{children:e.source.originalPath})]}),s.jsxs("div",{className:t.formStack,children:[s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:m("assets.detail.displayName","Display name")}),s.jsx("input",{value:f,disabled:!u,onChange:c=>g(c.target.value)})]}),s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:m("assets.detail.description","Description")}),s.jsx("textarea",{value:k,rows:3,disabled:!u,onChange:c=>y(c.target.value)})]}),s.jsxs("div",{className:t.twoColumn,children:[s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:m("assets.upload.creatorType","Creator type")}),s.jsxs("select",{value:C,disabled:!u,onChange:c=>P(c.target.value),children:[s.jsx("option",{value:"user",children:m("assets.creator.user","User")}),s.jsx("option",{value:"group",children:m("assets.creator.group","Group")})]})]}),s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:m("assets.upload.creatorId","Creator ID")}),s.jsx("input",{value:x,disabled:!u,onChange:c=>d(c.target.value)})]})]}),s.jsx("button",{type:"button",className:t.primaryButton,disabled:!u||a==="upload",onClick:()=>{const c=x.trim();p({displayName:f,description:k,...c?{creatorType:C,creatorId:c}:{}})},children:a==="upload"?m("assets.upload.uploading","Uploading..."):m("assets.upload.submit","Upload with API Key")})]}),s.jsxs("div",{className:t.noticeList,children:[s.jsx("p",{children:m("assets.upload.noDelete","WEPPY does not provide Roblox asset deletion.")}),s.jsx("p",{children:m("assets.upload.delay","Roblox processing and moderation can delay visibility in Studio or Creator Dashboard.")})]})]})]})]})})}function ee(e){return{assetUploadByOpenCloudEnabled:e.hot.ENABLE_ASSET_UPLOAD_BY_OPEN_CLOUD===!0}}function nt(e){const l={};return typeof e.assetUploadByOpenCloudEnabled=="boolean"&&(l.ENABLE_ASSET_UPLOAD_BY_OPEN_CLOUD=e.assetUploadByOpenCloudEnabled),l}async function ot(){const e=await w.get("/api/dashboard/settings");return ee(e)}async function it(e){const l=await w.patch("/api/dashboard/settings",nt(e));return ee(l)}async function ct(){return w.get("/api/dashboard/open-cloud/credential")}async function rt(e){return w.put("/api/dashboard/open-cloud/credential",e)}async function dt(e){return w.patch("/api/dashboard/open-cloud/credential/default-creator",e)}async function ut(e){return w.post("/api/dashboard/open-cloud/credential/test",e?{apiKey:e}:{})}async function pt(){return w.delete("/api/dashboard/open-cloud/credential")}function ht(e,l){return e!=null&&e.configured?e.storageProvider==="env"?l("assets.settings.credential.env","Environment variable"):e.maskedKey??l("assets.settings.credential.local","Local encrypted file"):l("assets.settings.credential.none","No API key saved")}function mt({open:e,tier:l,onClose:u}){const{t:a}=E(),[n,_]=i.useState(null),[p,m]=i.useState(null),[o,f]=i.useState(""),[g,k]=i.useState("user"),[y,C]=i.useState(""),[P,x]=i.useState(null),[d,c]=i.useState(!1),b=l==="basic",N=i.useCallback(async()=>{c(!0),x(null);try{const[r,j]=await Promise.all([ot(),ct()]);_(r),m(j.credential),j.credential.creatorType&&k(j.credential.creatorType),j.credential.creatorId&&C(j.credential.creatorId)}catch(r){x(r instanceof Error?r.message:a("assets.settings.loadFailed","Failed to load upload settings."))}finally{c(!1)}},[a]);if(i.useEffect(()=>{e&&N()},[N,e]),!e)return null;const F=(n==null?void 0:n.assetUploadByOpenCloudEnabled)===!0;return s.jsxs("aside",{className:`${t.drawer} ${t.settingsDrawer}`,"aria-label":a("assets.settings.title","Asset Library settings"),children:[s.jsxs("div",{className:t.drawerHeader,children:[s.jsxs("div",{children:[s.jsx("h2",{children:a("assets.settings.title","Asset Library settings")}),s.jsx("span",{children:ht(p,a)})]}),s.jsx(R,{text:a("common.close","Close"),children:s.jsx("button",{type:"button",className:t.iconButton,onClick:u,"aria-label":a("common.close","Close"),children:s.jsx(K,{size:16})})})]}),b&&s.jsx("div",{className:`${t.notice} ${t.proNotice}`,children:a("assets.settings.proOnly","Roblox upload settings and Open Cloud credential controls are available on Pro.")}),s.jsxs("section",{className:t.settingsPanel,children:[s.jsxs("label",{className:t.toggleRow,children:[s.jsxs("span",{children:[s.jsx("strong",{children:a("assets.settings.openCloudToggle","API Key local upload")}),s.jsx("small",{children:a("assets.settings.openCloudToggle.help","Controls whether server-side Open Cloud upload mutations can run.")})]}),s.jsx("input",{type:"checkbox",checked:F,disabled:b||d,onChange:r=>{(async()=>{c(!0);try{const j=await it({assetUploadByOpenCloudEnabled:r.target.checked});_(j),x(a("assets.settings.saved","Upload settings saved."))}catch(j){x(j instanceof Error?j.message:a("assets.settings.saveFailed","Failed to save upload settings."))}finally{c(!1)}})()}})]}),s.jsxs("div",{className:t.formStack,children:[s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:a("assets.settings.apiKey","Open Cloud API Key")}),s.jsx("input",{value:o,type:"password",disabled:b||d,onChange:r=>f(r.target.value)})]}),!(p!=null&&p.configured)&&s.jsx("p",{className:t.inlineHelp,children:s.jsx("a",{href:"https://create.roblox.com/docs/cloud/auth/api-keys",target:"_blank",rel:"noreferrer",children:a("assets.settings.apiKeyGuide","Create a Roblox API key with Assets API permissions.")})}),s.jsxs("div",{className:t.buttonRow,children:[s.jsx("button",{type:"button",className:t.commandButton,disabled:b||d||!o.trim(),onClick:()=>{(async()=>{c(!0);try{const r=await rt({apiKey:o.trim(),...y.trim()?{creatorType:g,creatorId:y.trim()}:{}});m(r.credential),f(""),x(r.message??a("assets.settings.saved","Upload settings saved."))}catch(r){x(r instanceof Error?r.message:a("assets.settings.saveFailed","Failed to save upload settings."))}finally{c(!1)}})()},children:a("assets.settings.saveApiKey","Save API Key")}),s.jsx("button",{type:"button",className:t.commandButton,disabled:b||d,onClick:()=>{(async()=>{var r;c(!0);try{const j=await ut(o.trim()||void 0);m(j.credential),x(((r=j.validation)==null?void 0:r.message)??a("assets.settings.tested","Connection tested."))}catch(j){x(j instanceof Error?j.message:a("assets.settings.testFailed","Connection test failed."))}finally{c(!1)}})()},children:a("assets.settings.testConnection","Test Connection")}),s.jsx("button",{type:"button",className:t.commandButton,disabled:b||d,onClick:()=>{(async()=>{c(!0);try{const r=await pt();m(r.credential),x(r.message??a("assets.settings.removed","API key removed."))}catch(r){x(r instanceof Error?r.message:a("assets.settings.removeFailed","Failed to remove API key."))}finally{c(!1)}})()},children:a("assets.settings.removeApiKey","Remove API Key")})]})]}),s.jsxs("div",{className:t.twoColumn,children:[s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:a("assets.upload.creatorType","Creator type")}),s.jsxs("select",{value:g,disabled:b||d||(p==null?void 0:p.storageProvider)==="env",onChange:r=>k(r.target.value),children:[s.jsx("option",{value:"user",children:a("assets.creator.user","User")}),s.jsx("option",{value:"group",children:a("assets.creator.group","Group")})]})]}),s.jsxs("label",{className:t.field,children:[s.jsx("span",{children:a("assets.upload.creatorId","Creator ID")}),s.jsx("input",{value:y,disabled:b||d||(p==null?void 0:p.storageProvider)==="env",onChange:r=>C(r.target.value)})]})]}),!(p!=null&&p.creatorId)&&s.jsx("p",{className:t.inlineHelp,children:a("assets.settings.creatorHelp","Use the numeric user ID from a profile URL or group ID from a group URL.")}),s.jsx("button",{type:"button",className:t.primaryButton,disabled:b||d||(p==null?void 0:p.storageProvider)==="env"||!y.trim(),onClick:()=>{(async()=>{c(!0);try{const r=await dt({creatorType:g,creatorId:y.trim()});m(r.credential),x(r.message??a("assets.settings.saved","Upload settings saved."))}catch(r){x(r instanceof Error?r.message:a("assets.settings.saveFailed","Failed to save upload settings."))}finally{c(!1)}})()},children:a("assets.settings.saveCreator","Save default Creator")})]}),P&&s.jsx("div",{className:t.messageState,children:P})]})}function H(e,l){return e instanceof Error&&e.message.trim().length>0?e.message:l}function gt(e,l){return e.some(a=>a.id===l.id)?e.map(a=>a.id===l.id?l:a):[l,...e]}function yt(e,l){if((l==null?void 0:l.id)===e)return l.category;const u=/^asset_(image|decal|audio|mesh|model|video|animation)_/.exec(e);return u!=null&&u[1]?u[1]:null}function xt(e){if(e.pluginConnected&&e.activePlaceId!==null)return{placeId:e.activePlaceId,placeName:e.activePlaceName};if(e.lastActivePlaceId!==null)return{placeId:e.lastActivePlaceId,placeName:e.lastActivePlaceName};const l=e.places[0];return{placeId:(l==null?void 0:l.placeId)??null,placeName:(l==null?void 0:l.placeName)??null}}function jt(){const[e,l]=i.useState([]),[u,a]=i.useState(0),[n,_]=i.useState(null),[p,m]=i.useState("place"),[o,f]=i.useState("all"),[g,k]=i.useState(null),[y,C]=i.useState(null),[P,x]=i.useState(!0),[d,c]=i.useState(null),[b,N]=i.useState(null),[F,r]=i.useState(null),j=i.useMemo(()=>e.find(h=>h.id===n)??null,[e,n]),Y=i.useCallback(()=>({scope:p,placeId:p==="place"?g:void 0}),[g,p]),U=i.useCallback(h=>({...Y(),category:h}),[Y]),W=i.useCallback(async()=>{try{const h=await ue(),v=xt(h);return k(v.placeId),C(v.placeName),v.placeId}catch{return k(null),C(null),null}},[]),T=i.useCallback(async()=>{N(null);try{const h=await W(),v={scope:p,placeId:p==="place"?h:void 0};if(p==="place"&&h===null){l([]),a(0),x(!1),N("No active place is connected for place-scoped assets.");return}const S=o==="all"?await Re(v):await J({...v,category:o});l(S.assets),a(S.totalCount)}catch(h){N(H(h,"Failed to load Asset Library."))}finally{x(!1)}},[o,W,p]);i.useEffect(()=>{T()},[T]);const I=i.useCallback(async(h,v,S)=>{const O=yt(v,j);if(!O)return N("Asset category is unavailable."),null;c(h),N(null),r(null);try{const $=await S(U(O));return l(ce=>gt(ce,$)),_($.id),r("Asset Library updated."),$}catch($){return N(H($,"Asset Library action failed.")),null}finally{c(null)}},[U,j]),se=i.useCallback(async()=>{if(o==="all"){N("Choose a category before rescanning inbox files.");return}c("rescan"),N(null),r(null);try{const h=await Le(U(o));l(h.assets),a(h.totalCount),r(`${h.adoptedCount} asset(s) added, ${h.skippedCount} skipped.`)}catch(h){N(H(h,"Asset Library rescan failed."))}finally{c(null)}},[o,U]),te=i.useCallback((h,v)=>I("update",h,S=>$e(S,h,v)),[I]),ae=i.useCallback((h,v)=>I("upload",h,S=>Ee(S,h,v)),[I]),le=i.useCallback(h=>I("status-refresh",h,v=>Ue(v,h)),[I]),ne=i.useCallback((h,v)=>I("usage-scan",h,async S=>(await De(S,h,v)).asset),[I]),oe=i.useCallback(h=>{m(h),_(null)},[]),ie=i.useCallback(h=>{f(h),_(null)},[]);return{assets:e,totalCount:u,selectedAsset:j,selectedAssetId:n,scope:p,categoryFilter:o,activePlaceId:g,activePlaceName:y,loading:P,busyAction:d,error:b,lastMessage:F,setScope:oe,setCategoryFilter:ie,selectAsset:_,refresh:T,rescan:se,updateMetadata:te,uploadAsset:ae,refreshStatus:le,scanUsage:ne}}const _t=["all","image","decal","audio","mesh","model","video","animation"];function Ct(){const{t:e}=E(),{trackEvent:l}=pe(),{tier:u,loading:a}=he(),n=jt(),[_,p]=i.useState(!1),[m,o]=i.useState(!1),f=!a&&u==="pro",g=n.selectedAsset,k=i.useMemo(()=>n.scope==="place"?n.activePlaceName??e("assets.scope.place","Current Place"):e("assets.scope.shared","Shared"),[n.activePlaceName,n.scope,e]);return s.jsxs("div",{className:t.page,children:[s.jsxs("div",{className:t.headerRow,children:[s.jsxs("div",{children:[s.jsx("h1",{children:e("assets.title","Assets")}),s.jsx("p",{children:e("assets.subtitle","Browse local originals, upload to Roblox, and inspect synced usage by place.")})]}),s.jsxs("div",{className:t.headerMeta,children:[s.jsx("span",{children:k}),s.jsx("strong",{children:n.totalCount})]})]}),s.jsxs("div",{className:t.toolbar,children:[s.jsxs("div",{className:t.segmented,role:"group","aria-label":e("assets.scope.label","Asset scope"),children:[s.jsx("button",{type:"button",className:n.scope==="place"?t.segmentedActive:"",onClick:()=>n.setScope("place"),children:e("assets.scope.place","Current Place")}),s.jsx("button",{type:"button",className:n.scope==="shared"?t.segmentedActive:"",onClick:()=>n.setScope("shared"),children:e("assets.scope.shared","Shared")})]}),s.jsxs("label",{className:t.filterLabel,children:[s.jsx("span",{children:e("assets.category.filter","Category")}),s.jsx("select",{value:n.categoryFilter,onChange:y=>n.setCategoryFilter(y.target.value),children:_t.map(y=>s.jsx("option",{value:y,children:y==="all"?e("assets.category.all","All"):B(y,e)},y))})]}),s.jsxs("div",{className:t.toolbarActions,children:[s.jsx(R,{text:n.categoryFilter==="all"?e("assets.rescan.chooseCategory","Choose a category before rescanning."):e("assets.rescan.tooltip","Scan the selected inbox folder."),children:s.jsxs("button",{type:"button",className:t.commandButton,disabled:n.categoryFilter==="all"||n.busyAction==="rescan",onClick:()=>{l("dashboard_click_event",{click_target:"assets_rescan",page:"assets"}),n.rescan()},children:[s.jsx(Z,{size:15}),e("assets.rescan","Rescan")]})}),s.jsx(R,{text:g?e("assets.upload.open.tooltip","Upload this local file to Roblox with the saved API key."):e("assets.upload.selectFirst","Select an asset first."),children:s.jsxs("button",{type:"button",className:t.commandButton,disabled:!g||!f,onClick:()=>{l("dashboard_click_event",{click_target:"assets_upload_open",page:"assets"}),p(!0)},children:[s.jsx(q,{size:15}),e("assets.upload.open","Upload")]})}),s.jsx(R,{text:e("assets.settings.open.tooltip","Open Roblox upload settings."),children:s.jsx("button",{type:"button",className:t.iconButton,onClick:()=>{l("dashboard_click_event",{click_target:"assets_open_settings",page:"assets"}),o(!0)},"aria-label":e("assets.settings.open","Open settings"),children:s.jsx(me,{size:16})})})]})]}),n.error&&s.jsx("div",{className:t.errorState,children:n.error}),n.lastMessage&&s.jsx("div",{className:t.messageState,children:n.lastMessage}),!f&&!a&&s.jsx("div",{className:`${t.notice} ${t.proNotice}`,children:e("assets.basic.notice","Browse, preview, edit metadata, and scan usage on Basic. Roblox upload controls are available on Pro.")}),n.loading?s.jsx("div",{className:t.emptyState,children:e("common.loading","Loading...")}):s.jsx(Qs,{assets:n.assets,selectedAssetId:n.selectedAssetId,onSelect:n.selectAsset}),s.jsx(tt,{asset:_?null:g,busyAction:n.busyAction,canUpload:f,onClose:()=>n.selectAsset(null),onSave:async(y,C)=>{g&&await n.updateMetadata(g.id,{displayName:y,description:C})},onUpload:()=>p(!0),onRefreshStatus:async()=>{g&&await n.refreshStatus(g.id)},onScanUsage:async()=>{g&&(l("dashboard_click_event",{click_target:"assets_usage_scan",page:"assets"}),await n.scanUsage(g.id,n.activePlaceId??void 0))}}),s.jsx(lt,{asset:g,open:_,canUpload:f,busyAction:n.busyAction,onClose:()=>{p(!1),n.selectAsset(null)},onBack:()=>p(!1),onUpload:async y=>{if(!g)return;l("dashboard_click_event",{click_target:"assets_upload_submit",page:"assets"}),await n.uploadAsset(g.id,y)&&p(!1)}}),s.jsx(mt,{open:m,tier:u,onClose:()=>o(!1)})]})}export{Ct as Component};
