import{jsx as e,jsxs as t,Fragment as V}from"react/jsx-runtime";import{memo as K,useState as F,useCallback as L,useMemo as j}from"react";import{useAtomValue as g}from"jotai";import{LayoutVariant as $}from"@redocly/config";import{AfterOpenApiOperation as z}from"@redocly/theme/components/OpenApiDocs/hooks/AfterOpenApiOperation";import{BeforeOpenApiOperation as G}from"@redocly/theme/components/OpenApiDocs/hooks/BeforeOpenApiOperation";import{PageActions as J}from"@redocly/theme/components/PageActions/PageActions";import{Feedback as Q}from"@redocly/theme/components/Feedback/Feedback";import{SamplesMiddlePanel as s,SamplesPanel as U,ShareLink as X,Row as W,CustomBadges as Y}from"../common/index.js";import{CallbacksList as Z}from"../Callbacks/index.js";import{CallbackSamples as ee}from"../CallbackSamples/index.js";import{RequestSamples as ae}from"../RequestSamples/index.js";import{OperationResponseList as te}from"../Responses/index.js";import{ResponseSamples as oe}from"../ResponseSamples/index.js";import{makeDeepLink as ne,joinWithSeparator as se}from"../../services/index.js";import{layoutAtom as re,userClaimsAtom as ie}from"../../jotai/app.js";import{globalOptionsAtom as le,globalStoreAtom as ce}from"../../jotai/store.js";import{getOperation as pe}from"../../models/operation.js";import{RenderHook as B}from"../RenderHook/index.js";import{Heading as de,HeadingWrapper as me,Title as ge}from"../common/OperationItemTitle.js";import{LinkToField as ke}from"../common/LinkToField.js";import{RequestDetails as he}from"../Request/RequestDetails.js";import{StyledBadge as H}from"../common/Badges.js";import{useTranslate as ue}from"../../hooks/index.js";import{styled as k}from"../../styled-components.js";import{createPanelToggleEvent as be}from"../../events/index.js";import{SchemaCatalogLink as fe}from"../SchemaCatalogLink/SchemaCatalogLink.js";function Se({item:{operationDefinition:S,parent:v,href:h}}){const r=ue(),{parser:y,options:l}=g(ce),{events:x}=g(le),T=g(ie),n=g(re),[c,I]=F(),{unstable_hooks:C,feedback:p}=l,a=j(()=>pe(y,S,v,l,h,void 0,T),[h,S,l,v,y,T]),{name:O,deprecated:_,isWebhook:q,badges:D}=a||{},o=n===$.STACKED,R=p?.type||"sentiment",A=p?.hide!==!0,u=se(l.routingBasePath,a.href),[b,E]=F(null),P=L(m=>{c!==m&&I(m)},[c]),d=L((m,w)=>{if(!w)return;const N=be({operation:a,isExpanded:m,panelType:w});x?.panelToggle?.(N)},[x,a]),M=j(()=>A?e(ve,{children:e(Q,{type:R,settings:p.settings,path:u})}):null,[A,R,p.settings,u]);return t(ye,{layout:n,children:[e(i,{layout:n,children:t(s,{isStacked:o,children:[e(B,{Hook:G||C?.BeforeOperation,props:{operation:a}}),t(me,{children:[t(de,{"data-testid":"operation-item-header",children:[e(X,{to:h,"aria-label":`link to ${O}`}),e(Y,{badges:D,children:O}),_&&e(H,{deprecated:!0,children:r("openapi.badges.deprecated","Deprecated")}),q&&e(H,{children:r("openapi.badges.webhook","Webhook")})]}),e(J,{pageSlug:u})]})]})}),e(s,{isStacked:o,children:e(fe,{schemaRef:"#"+a.pointer})}),t(i,{layout:n,children:[e(s,{isStacked:o,children:e(he,{operation:a,translate:r,onPanelToggle:d})}),e(f,{isStacked:o,"data-testid":"samples-block",className:"panel-container-request-samples",children:e(ae,{operation:a,onPanelToggle:d})})]}),t(i,{layout:n,children:[e(s,{isStacked:o,children:a.responses?.length?e(te,{responses:a.responses,operationId:a.id,operationPointer:a.pointer,callbackId:a.callbackId,activeResponseTab:c,onTabChange:P,onPanelToggle:d}):null}),e(f,{isStacked:o,"data-testid":"samples-block",className:"panel-container-response-samples",children:e(oe,{operation:a,activeResponseTab:c,onTabChange:P,onPanelToggle:d})})]}),t(i,{layout:n,children:[t(s,{isStacked:o,children:[a.callbacks?.length?t(V,{children:[t(ge,{children:[e(ke,{to:ne(a.id,"callbacks")}),r("openapi.callbacks","Callbacks")]}),e(Z,{callbacks:a.callbacks,onExpand:E,selectedCallback:b})]}):null,e(B,{Hook:z||C?.AfterOperation,props:{operation:a}})]}),b?e(f,{isStacked:o,"data-testid":"samples-block",children:e(ee,{callback:b,translate:r})}):null]}),e(i,{layout:n,children:e(s,{isStacked:o,fullWidth:!0,children:M})})]})}const Qe=K(Se),f=k(U)`
  margin-left: auto;
  --code-block-padding: var(--spacing-xs) 0 var(--spacing-xs) 20px;
`,ve=k.div`
  & > div {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
  }

  & > div > div {
    width: 100%;
    max-width: var(--feedback-width);
  }
`,ye=k(W)`
  flex-direction: column;
  align-items: flex-start;
  padding: var(--spacing-base) 0 calc(var(--spacing-xl) + var(--spacing-xs));
`,i=k(W)`
  margin: calc(var(--spacing-unit) * 2) 0;
`;export{Qe as OperationItem,f as OperationSamplesPanel};
