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}from"@redocly/theme";import{SamplesMiddlePanel,SamplesPanel,ShareLink,Row,CustomBadges}from"../common";import{CallbacksList}from"../Callbacks";import{CallbackSamples}from"../CallbackSamples";import{RequestSamples}from"../RequestSamples";import{OperationResponseList}from"../Responses";import{ResponseSamples}from"../ResponseSamples";import{makeDeepLink,joinWithSeparator}from"../../services";import{layoutAtom,userClaimsAtom}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";import{StyledBadge}from"../common/Badges";import{useTranslate}from"../../hooks";function OperationItemComponent({item:{operationDefinition:e,parent:a,href:o}}){var t,s;const l=useTranslate(),{parser:i,options:n}=useAtomValue(globalStoreAtom),r=useAtomValue(userClaimsAtom),p=useAtomValue(layoutAtom),[d,m]=useState(),{unstable_hooks:c,feedback:u}=n,k=useMemo((()=>getOperation(i,e,a,n,o,void 0,r)),[o,e,n,a,i,r]),{name:S,deprecated:b,isWebhook:x,badges:h}=k||{},j=p===LayoutVariant.STACKED,f=(null==u?void 0:u.type)||"sentiment",g=!0!==(null==u?void 0:u.hide),[_,y]=useState(null),O=useCallback((e=>{d!==e&&m(e)}),[d]),R=useMemo((()=>g?_jsx(FeedbackWrapper,{children:_jsx(Feedback,{type:f,settings:u.settings,path:joinWithSeparator(n.routingBasePath,k.href)})}):null),[g,f,u.settings,n.routingBasePath,k.href]);return _jsxs(OperationRow,{layout:p,children:[_jsx(OperationSubRowStyled,{layout:p,children:_jsxs(SamplesMiddlePanel,{isStacked:j,children:[_jsx(RenderHook,{Hook:BeforeOpenApiOperation||(null==c?void 0:c.BeforeOperation),props:{operation:k}}),_jsxs(Heading,{"data-testid":"operation-item-header",children:[_jsx(ShareLink,{to:o,"aria-label":`link to ${S}`}),_jsx(CustomBadges,{badges:h,children:S}),b&&_jsx(StyledBadge,{deprecated:!0,children:l("openapi.badges.deprecated","Deprecated")}),x&&_jsx(StyledBadge,{children:l("openapi.badges.webhook","Webhook")})]})]})}),_jsxs(OperationSubRowStyled,{layout:p,children:[_jsx(SamplesMiddlePanel,{isStacked:j,children:_jsx(RequestDetails,{operation:k,translate:l})}),_jsx(OperationSamplesPanel,{isStacked:j,"data-testid":"samples-block",className:"panel-container-request-samples",children:_jsx(RequestSamples,{operation:k})})]}),_jsxs(OperationSubRowStyled,{layout:p,children:[_jsx(SamplesMiddlePanel,{isStacked:j,children:(null===(t=k.responses)||void 0===t?void 0:t.length)?_jsx(OperationResponseList,{responses:k.responses,operationId:k.id,operationPointer:k.pointer,callbackId:k.callbackId,activeResponseTab:d,onTabChange:O}):null}),_jsx(OperationSamplesPanel,{isStacked:j,"data-testid":"samples-block",className:"panel-container-response-samples",children:_jsx(ResponseSamples,{operation:k,activeResponseTab:d,onTabChange:O})})]}),_jsxs(OperationSubRowStyled,{layout:p,children:[_jsxs(SamplesMiddlePanel,{isStacked:j,children:[(null===(s=k.callbacks)||void 0===s?void 0:s.length)?_jsxs(_Fragment,{children:[_jsxs(Title,{children:[_jsx(LinkToField,{to:makeDeepLink(k.id,"callbacks")}),l("openapi.callbacks","Callbacks")]}),_jsx(CallbacksList,{callbacks:k.callbacks,onExpand:y,selectedCallback:_})]}):null,_jsx(RenderHook,{Hook:AfterOpenApiOperation||(null==c?void 0:c.AfterOperation),props:{operation:k}})]}),_?_jsx(OperationSamplesPanel,{isStacked:j,"data-testid":"samples-block",children:_jsx(CallbackSamples,{callback:_,translate:l})}):null]}),_jsx(OperationSubRowStyled,{layout:p,children:_jsx(SamplesMiddlePanel,{isStacked:j,fullWidth:!0,children:R})})]})}export const OperationItem=memo(OperationItemComponent);export const OperationSamplesPanel=styled(SamplesPanel)`
  margin-left: auto;
  --code-block-padding: var(--spacing-xs) 0 var(--spacing-xs) 20px;
`;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;
`;
//# sourceMappingURL=OperationItem.js.map