var __rest=this&&this.__rest||function(e,r){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&r.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)r.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(t[o[i]]=e[o[i]])}return t};import{jsx as _jsx}from"react/jsx-runtime";import{memo}from"react";import{useAtomValue}from"jotai";import{useLocation}from"react-router-dom";import styled from"styled-components";import{ArraySchema}from"./ArraySchema";import{ObjectSchema}from"./ObjectSchema";import{OneOfSchema}from"./OneOfSchema";import{RecursiveSchema}from"./RecursiveSchema";import{operationStore}from"../../jotai/operation";import{FieldDetails}from"../PropertyDetails";import{pathIncludesLink}from"../../utils";function SchemaComponent(e){var r,{schema:t,onDiscriminatorChange:o}=e,i=__rest(e,["schema","onDiscriminatorChange"]);const{activeOneOf:n}=useAtomValue(operationStore((null==t?void 0:t.operationPointer)||"")),a=useLocation();if(!t)return null;const{type:s,oneOf:c,discriminatorProp:m,isCircular:l}=t;if(l)return _jsx(RecursiveSchema,{schema:t});if(void 0!==m){if(!c||!c.length)return console.warn(`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${t.title}`),null;const e=c.findIndex(((e,r)=>pathIncludesLink(a,`d=${r}`))),r=-1===e?0:e,s=c[void 0!==n[t.pointer]?n[t.pointer]:r];return(null==s?void 0:s.isCircular)?_jsx(RecursiveSchema,{schema:s}):_jsx(ObjectSchema,Object.assign({},i,{schema:s,discriminator:{fieldName:m,parentSchema:t,activeOneOfIdx:r,onChange:o}}))}if(void 0!==c)return _jsx(OneOfSchema,Object.assign({},i,{schema:t}));const p=Array.isArray(s)?s:[s];if(p.includes("object")){if(null===(r=t.fields)||void 0===r?void 0:r.length)return _jsx(ObjectSchema,Object.assign({},i,{schema:t}))}else if(p.includes("array"))return _jsx(ArraySchema,Object.assign({},i,{schema:t}));const d={schema:t,name:"",description:t.description,required:!1,deprecated:!1};return _jsx(Wrapper,{children:_jsx(FieldDetails,{field:d,fieldParentsName:i.fieldParentsName})})}export const Schema=memo(SchemaComponent);const Wrapper=styled.div`
  width: 100%;
  padding: var(--spacing-xxs) 0;
  border-bottom: 1px solid var(--border-color-primary);
`;
//# sourceMappingURL=Schema.js.map