import{jsx as e,jsxs as t,Fragment as V}from"react/jsx-runtime";import{memo as K,useState as L,useCallback as j,useMemo as W}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 f,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 be}from"../Request/RequestDetails.js";import{StyledBadge as H}from"../common/Badges.js";import{useTranslate as he}from"../../hooks/index.js";import{styled as i}from"../../styled-components.js";import{createPanelToggleEvent as ue}from"../../events/index.js";import{SchemaCatalogLink as fe}from"../SchemaCatalogLink/SchemaCatalogLink.js";function Se({item:{operationDefinition:v,parent:x,href:b}}){const r=he(),{parser:y,options:l}=g(ce),{events:C}=g(le),T=g(ie),n=g(re),[c,I]=L(),{unstable_hooks:O,feedback:p}=l,a=W(()=>pe(y,v,x,l,b,void 0,T),[b,v,l,x,y,T]),{name:R,deprecated:_,isWebhook:q,badges:D}=a||{},o=n===$.STACKED,A=p?.type||"sentiment",P=p?.hide!==!0,h=se(l.routingBasePath,a.href),[u,E]=L(null),w=j(m=>{c!==m&&I(m)},[c]),d=j((m,F)=>{if(!F)return;const N=ue({operation:a,isExpanded:m,panelType:F});C?.panelToggle?.(N)},[C,a]),M=W(()=>P?e(ve,{children:e(Q,{type:A,settings:p.settings,path:h})}):null,[P,A,p.settings,h]);return t(xe,{layout:n,children:[e(k,{layout:n,children:t(s,{isStacked:o,children:[e(B,{Hook:G||O?.BeforeOperation,props:{operation:a}}),t(me,{children:[t(de,{"data-testid":"operation-item-header",children:[e(X,{to:b,"aria-label":`link to ${R}`}),e(Y,{badges:D,children:R}),_&&e(H,{deprecated:!0,children:r("openapi.badges.deprecated","Deprecated")}),q&&e(H,{children:r("openapi.badges.webhook","Webhook")})]}),e(J,{pageSlug:h})]})]})}),e(s,{isStacked:o,children:e(fe,{schemaRef:"#"+a.pointer})}),t(k,{layout:n,children:[e(s,{isStacked:o,children:e(be,{operation:a,translate:r,onPanelToggle:d})}),e(S,{isStacked:o,"data-testid":"samples-block",className:"panel-container-request-samples",children:e(ae,{operation:a,onPanelToggle:d})})]}),t(k,{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:w,onPanelToggle:d}):null}),e(S,{isStacked:o,"data-testid":"samples-block",className:"panel-container-response-samples",children:e(oe,{operation:a,activeResponseTab:c,onTabChange:w,onPanelToggle:d})})]}),t(ye,{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:u})]}):null,e(B,{Hook:z||O?.AfterOperation,props:{operation:a}})]}),u?e(S,{isStacked:o,"data-testid":"samples-block",children:e(ee,{callback:u,translate:r})}):null]}),e(k,{layout:n,children:e(s,{isStacked:o,fullWidth:!0,children:M})})]})}const Ue=K(Se),S=i(U)`
  margin-left: auto;
  --code-block-padding: var(--spacing-xs) 0 var(--spacing-xs) 20px;
`,ve=i.div`
  & > div {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
  }

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