import{jsxs as l,jsx as o}from"react/jsx-runtime";import{memo as k,useMemo as T}from"react";import*as M from"react";import{useAtomValue as h}from"jotai";import{LayoutVariant as b}from"@redocly/config";import{CodeBlock as v}from"@redocly/theme/components/CodeBlock/CodeBlock";import{Tag as P}from"@redocly/theme/components/Tag/Tag";import{getSecurity as w}from"../../models/index.js";import{globalStoreAtom as j}from"../../jotai/store.js";import{Section as A,Row as B,SamplesMiddlePanel as F,SamplesPanel as L,CodeBlockPanel as E}from"../common/index.js";import{layoutAtom as I}from"../../jotai/app.js";import{useTranslate as V}from"../../hooks/index.js";import{Security as _}from"../Security/Security.js";import{styled as s}from"../../styled-components.js";function D({name:i}){const{parser:t}=h(j),c=V(),e=T(()=>(t.definition["x-mcp"]?.resources||[]).find(p=>p.name===i),[t,i]),r=T(()=>e?w(e.security,t):null,[t,e]);return e?o(A,{children:o(K,{uriTitle:c("openapi.mcp.uriTitle","Resource URI"),mimeTypeTitle:c("openapi.mcp.mimeTypeTitle","Resource MIME type"),exampleTitle:c("openapi.mcp.exampleTitle","Resource content"),uri:e.uri,mimeType:e.mimeType,content:e.blob??e.text??"",children:r&&o(_,{securities:r})})}):l("div",{children:["Resource not found: ",i]})}function K({uriTitle:i,mimeTypeTitle:t,exampleTitle:c,uri:e,mimeType:r,content:a,children:p}){const m=h(I),d=m===b.STACKED,[u,f]=M.useState(null),y=async(n,x,C)=>{C.stopPropagation();try{await navigator.clipboard.writeText(n),f(x),setTimeout(()=>f(null),2e3)}catch(R){console.error("Failed to copy text: ",R)}};return l(N,{layout:m,children:[o(U,{isStacked:d,children:l("div",{children:[p,l(g,{children:[i,":","  ",o(S,{onClick:n=>y(e,"uri",n),title:"Click to copy",children:u==="uri"?"\u2713 Copied!":e})]}),l(g,{children:[t,":"," ",o(S,{onClick:n=>y(r,"mimeType",n),title:"Click to copy",children:u==="mimeType"?"\u2713 Copied!":r})]})]})}),a&&o(L,{isStacked:d,children:o(E,{className:"panel-response-samples",header:c,children:o(q,{source:a,header:{title:r,controls:{copy:{}}}})})})]})}const N=s(B)`
  margin: calc(var(--spacing-unit) * 2) 0;

  & + & {
    margin-top: calc(var(--spacing-base) * 2);
  }
`,U=s(F)`
  && {
    padding-left: 0;
  }
`,te=k(D),S=s(P)`
  text-transform: none;
`,q=s(v)`
  border: none;
  padding: 0 8px;
`,g=s.div`
  margin: 1em 0;
`;export{te as McpResource};
