import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{memo,useState,useCallback,useMemo}from"react";import styled from"styled-components";import{useAtomValue}from"jotai";import{Feedback,LayoutVariant,BeforeOpenApiOperation,AfterOpenApiOperation,Badge}from"@redocly/theme";import{SamplesMiddlePanel,SamplesPanel,ShareLink,Row}from"../common";import{CallbacksList}from"../Callbacks";import{CallbackSamples}from"../CallbackSamples";import{RequestSamples}from"../RequestSamples";import{OperationResponseList}from"../Responses";import{ResponseSamples}from"../ResponseSamples";import{makeDeepLink}from"../../services";import{layoutAtom}from"../../jotai/app";import{globalStoreAtom}from"../../jotai/store";import{getOperation}from"../../models/operation";import{RenderHook}from"../RenderHook";import{Heading,Title}from"../common/OperationItemTitle";import{LinkToField}from"../common/LinkToField";import{RequestDetails}from"../Request/RequestDetails";const OperationSamplesPanel=styled(SamplesPanel)`
  margin-left: auto;
  --code-block-padding: var(--spacing-xs) 0 var(--spacing-xs) 20px;
`;function OperationItemComponent({item:{operationDefinition:e,parent:a,href:o}}){var t,s;const{parser:l,options:i}=useAtomValue(globalStoreAtom),n=useAtomValue(layoutAtom),[r,p]=useState(),{unstable_hooks:d,feedback:m}=i,c=useMemo((()=>getOperation(l,e,a,i,o)),[o,e,i,a,l]),{name:u,deprecated:k,isWebhook:x,badges:S}=c,b=n===LayoutVariant.STACKED,f=(null==m?void 0:m.type)||"sentiment",j=!0!==(null==m?void 0:m.hide),h=S.filter((({position:e})=>"before"===e)),_=S.filter((({position:e})=>"after"===e)),[g,O]=useState(null),R=useCallback((e=>{r!==e&&p(e)}),[r]);return _jsxs(OperationRow,{layout:n,children:[_jsx(OperationSubRowStyled,{layout:n,children:_jsxs(SamplesMiddlePanel,{isStacked:b,children:[_jsx(RenderHook,{Hook:BeforeOpenApiOperation||(null==d?void 0:d.BeforeOperation),props:{operation:c}}),_jsxs(Heading,{"data-testid":"operation-item-header",children:[_jsx(ShareLink,{to:o,"aria-label":`link to ${u}`}),h.map((({name:e,color:a})=>_jsx(OperationBadge,{color:a,children:e},e))),u,_.map((({name:e,color:a})=>_jsx(OperationBadge,{color:a,children:e},e))),k&&_jsx(OperationBadge,{deprecated:!0,children:"Deprecated"}),x&&_jsx(OperationBadge,{children:"Webhook"})]})]})}),_jsxs(OperationSubRowStyled,{layout:n,children:[_jsx(SamplesMiddlePanel,{isStacked:b,children:_jsx(RequestDetails,{operation:c})}),_jsx(OperationSamplesPanel,{isStacked:b,"data-testid":"samples-block",className:"panel-container-request-samples",children:_jsx(RequestSamples,{operation:c})})]}),_jsxs(OperationSubRowStyled,{layout:n,children:[_jsx(SamplesMiddlePanel,{isStacked:b,children:(null===(t=c.responses)||void 0===t?void 0:t.length)?_jsx(OperationResponseList,{responses:c.responses,operationId:c.id,operationPointer:c.pointer,callbackId:c.callbackId,activeResponseTab:r,onTabChange:R}):null}),_jsx(OperationSamplesPanel,{isStacked:b,"data-testid":"samples-block",className:"panel-container-response-samples",children:_jsx(ResponseSamples,{operation:c,activeResponseTab:r,onTabChange:R})})]}),_jsxs(OperationSubRowStyled,{layout:n,children:[_jsxs(SamplesMiddlePanel,{isStacked:b,children:[(null===(s=c.callbacks)||void 0===s?void 0:s.length)?_jsxs(_Fragment,{children:[_jsxs(Title,{children:[_jsx(LinkToField,{to:makeDeepLink(c.id,"callbacks")}),"Callbacks"]}),_jsx(CallbacksList,{callbacks:c.callbacks,onExpand:O,selectedCallback:g})]}):null,_jsx(RenderHook,{Hook:AfterOpenApiOperation||(null==d?void 0:d.AfterOperation),props:{operation:c}})]}),g?_jsx(OperationSamplesPanel,{isStacked:b,"data-testid":"samples-block",children:_jsx(CallbackSamples,{callback:g})}):null]}),_jsx(OperationSubRowStyled,{layout:n,children:_jsx(SamplesMiddlePanel,{isStacked:b,fullWidth:!0,children:j?_jsx(FeedbackWrapper,{children:_jsx(Feedback,{type:f,settings:m.settings,path:c.href})}):null})})]})}export const OperationItem=memo(OperationItemComponent);const FeedbackWrapper=styled.div`
  & > div {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
  }

  & > div > div {
    width: 100%;
    max-width: var(--feedback-width);
  }
`,OperationRow=styled(Row)`
  flex-direction: column;
  align-items: flex-start;
  padding: var(--spacing-base) 0 calc(var(--spacing-xl) + var(--spacing-xs));
`,OperationSubRowStyled=styled(Row)`
  margin: calc(var(--spacing-unit) * 2) 0;
`,OperationBadge=styled(Badge)`
  margin: 0;
  background-color: ${({color:e})=>e};
`;
//# sourceMappingURL=OperationItem.js.map