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

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