"use strict";var __rest=this&&this.__rest||function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)r.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(t[i[n]]=e[i[n]])}return t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Schema=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),jotai_1=require("jotai"),react_router_dom_1=require("react-router-dom"),styled_components_1=__importDefault(require("styled-components")),ArraySchema_1=require("./ArraySchema"),ObjectSchema_1=require("./ObjectSchema"),OneOfSchema_1=require("./OneOfSchema"),RecursiveSchema_1=require("./RecursiveSchema"),operation_1=require("../../jotai/operation"),PropertyDetails_1=require("../PropertyDetails"),utils_1=require("../../utils");function SchemaComponent(e){var r,{schema:t,onDiscriminatorChange:i}=e,n=__rest(e,["schema","onDiscriminatorChange"]);const{activeOneOf:a}=(0,jotai_1.useAtomValue)((0,operation_1.operationStore)((null==t?void 0:t.operationPointer)||"")),o=(0,react_router_dom_1.useLocation)();if(!t)return null;const{type:s,oneOf:c,discriminatorProp:u,isCircular:m}=t;if(m)return(0,jsx_runtime_1.jsx)(RecursiveSchema_1.RecursiveSchema,{schema:t});if(void 0!==u){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)=>(0,utils_1.pathIncludesLink)(o,`d=${r}`))),r=-1===e?0:e,s=c[void 0!==a[t.pointer]?a[t.pointer]:r];return(null==s?void 0:s.isCircular)?(0,jsx_runtime_1.jsx)(RecursiveSchema_1.RecursiveSchema,{schema:s}):(0,jsx_runtime_1.jsx)(ObjectSchema_1.ObjectSchema,Object.assign({},n,{schema:s,discriminator:{fieldName:u,parentSchema:t,activeOneOfIdx:r,onChange:i}}))}if(void 0!==c)return(0,jsx_runtime_1.jsx)(OneOfSchema_1.OneOfSchema,Object.assign({},n,{schema:t}));const _=Array.isArray(s)?s:[s];if(_.includes("object")){if(null===(r=t.fields)||void 0===r?void 0:r.length)return(0,jsx_runtime_1.jsx)(ObjectSchema_1.ObjectSchema,Object.assign({},n,{schema:t}))}else if(_.includes("array"))return(0,jsx_runtime_1.jsx)(ArraySchema_1.ArraySchema,Object.assign({},n,{schema:t}));const l={schema:t,name:"",description:t.description,required:!1,deprecated:!1};return(0,jsx_runtime_1.jsx)(Wrapper,{children:(0,jsx_runtime_1.jsx)(PropertyDetails_1.FieldDetails,{field:l,fieldParentsName:n.fieldParentsName})})}exports.Schema=(0,react_1.memo)(SchemaComponent);const Wrapper=styled_components_1.default.div`
  width: 100%;
  padding: var(--spacing-xxs) 0;
  border-bottom: 1px solid var(--border-color-primary);
`;
//# sourceMappingURL=Schema.js.map