import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{memo,useMemo}from"react";import{useLocation}from"react-router-dom";import styled from"styled-components";import{useAtomValue}from"jotai";import{Tabs,useTabsState}from"../Tabs";import{ResponseDetails}from"./ResponseDetails";import{makeDeepLink}from"../../services";import{Row,StyledTitle}from"./styled";import{LinkToField}from"../common/LinkToField";import{pathIncludesLink}from"../../utils";import{ExpandAllButton}from"../ExpandAllButton";import{useTranslate}from"../../hooks";import{getActiveMediaType}from"../../models";import{activeMimeNameAtom}from"../../jotai/app";export const OperationResponseList=memo((({responses:e,renderTitle:o,operationId:t,operationPointer:s,activeResponseTab:i,onTabChange:n,callbackId:a})=>{const r=useLocation(),l=useTranslate(),m=useAtomValue(activeMimeNameAtom),p=e.map((({code:e})=>({key:e,title:e}))),d=p.find((({key:e})=>e===i||pathIncludesLink(r,t)&&pathIncludesLink(r,`c=${e}`))),{activeTab:c,handleTabChange:u}=useTabsState({tabs:p,defaultTab:null==d?void 0:d.key,onChange:n}),T=p.find((e=>e.key===(i||c))),f=e.find((e=>e.code===(null==T?void 0:T.key))),v=useMemo((()=>{var e;if(!(null==f?void 0:f.content))return!1;const{schema:o}=getActiveMediaType(null==f?void 0:f.content,m)||{};return null===(e=null==o?void 0:o.fields)||void 0===e?void 0:e.some((({schema:e})=>!e.isPrimitive&&!e.isCircular))}),[m,null==f?void 0:f.content]);return T?_jsxs(_Fragment,{children:[_jsxs(TitleWrap,{children:[(null==o?void 0:o(T))||_jsxs(StyledTitle,{children:[_jsx(LinkToField,{to:makeDeepLink(t,`response&c=${T.key}`)}),l("openapi.responses","Responses")]}),_jsx(Tabs,{tabs:p,activeTab:T,onChange:u}),v&&_jsx(ExpandAllButton,{type:"response",operationPointer:s})]}),f?_jsx("div",{children:_jsx(ResponseDetails,{response:f,operationId:t,callbackId:a})},f.code):null]}):null}));const TitleWrap=styled(Row)`
  flex-wrap: wrap;
  gap: var(--spacing-unit);
`;
//# sourceMappingURL=OperationResponseList.js.map