import{jsx as r}from"react/jsx-runtime";import{memo as y}from"react";import{useAtomValue as S}from"jotai";import{useLocation as g}from"react-router-dom";import{ArraySchema as I}from"./ArraySchema.js";import{ObjectSchema as p}from"./ObjectSchema.js";import{OneOfSchema as b}from"./OneOfSchema.js";import{RecursiveSchema as s}from"./RecursiveSchema.js";import{operationStore as j}from"../../jotai/operation.js";import{FieldDetails as A}from"../PropertyDetails/index.js";import{pathIncludesLink as C}from"../../utils/index.js";import{styled as L}from"../../styled-components.js";function P({schema:e,onOneOfChange:n,...i}){const{activeOneOf:d}=S(j(e?.operationPointer||"")),u=g();if(!e)return null;const{type:t,oneOf:o,discriminatorProp:f,isCircular:h}=e;if(h)return r(s,{schema:e});if(f!==void 0){if(!o||!o.length)return console.warn(`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${e.title}`),null;const c=o.findIndex((k,x)=>C(u,`d=${x}`)),l=c===-1?0:c,v=d[e.pointer]!==void 0?d[e.pointer]:l,a=o[v];return a?.isCircular?r(s,{schema:a}):r(p,{...i,schema:a,discriminator:{fieldName:f,parentSchema:e,activeOneOfIdx:l},onOneOfChange:n})}if(o!==void 0&&o.length>=1)return r(b,{...i,schema:e,onChange:n});const m=Array.isArray(t)?t:[t];if(m.includes("object")){if(e.fields?.length)return r(p,{...i,schema:e,onOneOfChange:n})}else if(m.includes("array"))return r(I,{...i,schema:e,onOneOfChange:n});const O={schema:e,name:"",description:i.oneOfLevel?"":e.description,required:!1,deprecated:!1};return r($,{$hideBorder:i.hideBottomBorder,children:r(A,{field:O,fieldParentsName:i.fieldParentsName})})}const G=y(P),$=L.div`
  width: 100%;
  padding: var(--spacing-xxs) 0;
  ${({$hideBorder:e})=>!e&&"border-bottom: 1px solid var(--border-color-primary)"};
`;export{G as Schema};
