import{h as n,j as t}from"./codemirror-core-vkcnXJgD.js";import{t as $,a as C}from"./chunk-ML27DD5T-5CdR_75m.js";import{P as E,b as S,s as M}from"./index-GtUymKue.js";import{J as R}from"./react-dom-CwaHFgt6.js";import{a as _}from"./index-j3cnden5.js";import{u as j}from"./index-B-95QZyk.js";import{P as z}from"./plugin_manager-B7ACc_Tt.js";import"./chunk-UX7UMZL5-DCk8rE83.js";import"./index-CokAva9Y.js";import"./Item-CdZrGEbe.js";import"./iconBase-DqQMrcxU.js";function B(){const[u,d]=n.useState(!0),[i,m]=n.useState([]),[a,f]=n.useState(""),[w,p]=n.useState(!1),x=async()=>{var e;d(!0);try{const s=await z.getPluginList();s.pluginManagerNotFound?m([]):(m(s.extensionPages||[]),((e=s.extensionPages)==null?void 0:e.length)>0&&!a&&f(`${s.extensionPages[0].pluginId}:${s.extensionPages[0].path}`))}catch(s){const l=s.message;R.error(`获取扩展页面失败: ${l}`)}finally{d(!1)}},P=async()=>{await x()},N=n.useMemo(()=>i.map(e=>({key:`${e.pluginId}:${e.path}`,title:e.title,pluginId:e.pluginId,pluginName:e.pluginName,path:e.path,icon:e.icon,description:e.description})),[i]),c=n.useMemo(()=>{if(!a)return"";const[e,...s]=a.split(":"),l=s.join(":").replace(/^\//,"");return`/plugin/${e}/page/${l}`},[a]);n.useEffect(()=>{x()},[]),n.useEffect(()=>{c&&p(!0)},[c]);const v=()=>{p(!1)},k=(e,s)=>{const l=s.replace(/^\//,""),L=`/plugin/${e}/page/${l}`;window.open(L,"_blank")},r=n.useRef(null),o=n.useRef(!1),g=n.useRef(0),h=n.useRef(0),y=n.useCallback(e=>{const s=r.current;s&&(o.current=!0,g.current=e.clientX,h.current=s.scrollLeft,s.setPointerCapture(e.pointerId),s.style.cursor="grabbing",s.style.userSelect="none")},[]),I=n.useCallback(e=>{if(!o.current||!r.current)return;const s=e.clientX-g.current;r.current.scrollLeft=h.current-s},[]),b=n.useCallback(e=>{!o.current||!r.current||(o.current=!1,r.current.releasePointerCapture(e.pointerId),r.current.style.cursor="grab",r.current.style.userSelect="")},[]);return t.jsxs(t.Fragment,{children:[t.jsx("title",{children:"扩展页面 - NapCat WebUI"}),t.jsxs("div",{className:"p-2 md:p-4 relative h-[calc(100vh-6rem)] md:h-[calc(100vh-4rem)] flex flex-col",children:[t.jsx(E,{loading:u}),t.jsxs("div",{className:"flex mb-4 items-center gap-4 flex-nowrap min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-4 shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 text-default-600",children:[t.jsx(j,{size:24}),t.jsx("span",{className:"text-lg font-medium",children:"插件扩展页面"})]}),t.jsx(S,{isIconOnly:!0,className:"bg-default-100/50 hover:bg-default-200/50 text-default-700 backdrop-blur-md",radius:"full",onPress:P,children:t.jsx(_,{size:24})})]}),i.length>0&&t.jsx("div",{ref:r,className:"overflow-x-auto min-w-0 flex-1 scrollbar-thin scrollbar-thumb-default-300 scrollbar-track-transparent cursor-grab touch-pan-x",style:{WebkitOverflowScrolling:"touch"},onPointerDown:y,onPointerMove:I,onPointerUp:b,onPointerCancel:b,children:t.jsx($,{"aria-label":"Extension Pages",className:"w-max min-w-full",selectedKey:a,onSelectionChange:e=>f(e),classNames:{tabList:"bg-white/40 dark:bg-black/20 backdrop-blur-md flex-nowrap",cursor:"bg-white/80 dark:bg-white/10 backdrop-blur-md shadow-sm",panel:"hidden"},children:N.map(e=>t.jsx(C,{title:t.jsxs("div",{className:"flex items-center gap-2 whitespace-nowrap",children:[e.icon&&t.jsx("span",{children:e.icon}),t.jsx("span",{className:"cursor-pointer hover:underline truncate max-w-[6rem] md:max-w-none",title:`插件：${e.pluginName}
点击在新窗口打开`,onClick:s=>{s.stopPropagation(),k(e.pluginId,e.path)},children:e.title}),t.jsxs("span",{className:"text-xs text-default-400 hidden md:inline",children:["(",e.pluginName,")"]})]})},e.key))})})]}),i.length===0&&!u?t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-default-400",children:[t.jsx(j,{size:64,className:"mb-4 opacity-50"}),t.jsx("p",{className:"text-lg",children:"暂无插件扩展页面"}),t.jsx("p",{className:"text-sm mt-2",children:"插件可以通过注册页面来扩展 WebUI 功能"})]}):t.jsxs("div",{className:"flex-1 min-h-0 bg-white/40 dark:bg-black/20 backdrop-blur-md rounded-lg overflow-hidden relative",children:[w&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-default-100/50 z-10",children:t.jsx(M,{size:"lg"})}),t.jsx("iframe",{src:c,className:"w-full h-full border-0",onLoad:v,title:"extension-page",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"})]})]})]})}export{B as default};
