import{jsx as r}from"react/jsx-runtime";import{memo as S}from"react";import{useAtomValue as g}from"jotai";import{useLocation as I}from"react-router-dom";import{ArraySchema as b}from"./ArraySchema.js";import{ObjectSchema as p}from"./ObjectSchema.js";import{OneOfSchema as C}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 L}from"../../utils/index.js";import{styled as P}from"../../styled-components.js";function k({schema:e,onDiscriminatorChange:u,onOneOfChange:n,...i}){const{activeOneOf:d}=g(j(e?.operationPointer||"")),h=I();if(!e)return null;const{type:t,oneOf:o,discriminatorProp:f,isCircular:O}=e;if(O)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 m=o.findIndex((N,y)=>L(h,`d=${y}`)),l=m===-1?0:m,x=d[e.pointer]!==void 0?d[e.pointer]:l,a=o[x];return a?.isCircular?r(s,{schema:a}):r(p,{...i,schema:a,discriminator:{fieldName:f,parentSchema:e,activeOneOfIdx:l,onChange:u},onOneOfChange:n})}if(o!==void 0&&o.length>1)return r(C,{...i,schema:e,onChange:n});const c=Array.isArray(t)?t:[t];if(c.includes("object")){if(e.fields?.length)return r(p,{...i,schema:e,onOneOfChange:n})}else if(c.includes("array"))return r(b,{...i,schema:e,onOneOfChange:n});const v={schema:e,name:"",description:i.oneOfLevel?"":e.description,required:!1,deprecated:!1};return r(w,{children:r(A,{field:v,fieldParentsName:i.fieldParentsName})})}const H=S(k),w=P.div`
  width: 100%;
  padding: var(--spacing-xxs) 0;
  border-bottom: 1px solid var(--border-color-primary);
`;export{H as Schema};
