import{jsxs as m,jsx as n}from"react/jsx-runtime";import{memo as g}from"react";import{useAtom as y}from"jotai";import{StyledBadge as I,SelectionTitle as b}from"../common/index.js";import{Markdown as j}from"../Markdown/index.js";import{ConstraintsView as C}from"../common/ConstraintsView.js";import{Schema as T}from"./Schema.js";import{operationStore as w}from"../../jotai/operation.js";import{SchemaSelection as E}from"../common/SchemaSelection/index.js";import{useOneOfLocationIdx as N}from"./useOneOfLocationIdx.js";import{useTranslate as P}from"../../hooks/index.js";import{styled as l}from"../../styled-components.js";function z({schema:{oneOf:i},schema:e,onChange:f,oneOfLevel:a=1,...x}){const O=P(),[r,u]=y(w(e.operationPointer)),p=N(i,a),s=i.map((t,S)=>({label:t.title||t.typePrefix+t.displayType,value:S})),c=s.findIndex(t=>t.label===r.activeExampleName),d=p===-1?c!==-1?c:0:p,v=r.activeOneOf?.[e.pointer]!==void 0?r.activeOneOf[e.pointer]:d,o=i[v];if(!o)return null;const h=t=>{f?.({pointer:e.pointer,index:t}),u({activeExampleName:e.oneOf?.[t]?.title,activeOneOf:{[e.pointer]:t},requestValues:{body:null}})};return m(L,{children:[m(b,{children:[e.oneOfType,":"]}),n(E,{options:s,onChange:h,pointer:e.operationPointer,schema:e,defaultOneOfIdx:d}),o.deprecated&&n(I,{deprecated:!0,children:O("openapi.badges.deprecated","Deprecated")}),o.description&&n(D,{source:o.description}),n(C,{constraints:o.constraints}),n(T,{...x,schema:o,oneOfLevel:a+1})]})}const K=g(z),D=l(j)`
  margin-top: var(--spacing-xs);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
`,L=l.div`
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
`;export{K as OneOfSchema};
