"use strict";var __rest=this&&this.__rest||function(e,r){var t={};for(var l in e)Object.prototype.hasOwnProperty.call(e,l)&&r.indexOf(l)<0&&(t[l]=e[l]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(l=Object.getOwnPropertySymbols(e);s<l.length;s++)r.indexOf(l[s])<0&&Object.prototype.propertyIsEnumerable.call(e,l[s])&&(t[l[s]]=e[l[s]])}return t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ArraySchema=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),jotai_1=require("jotai"),common_1=require("../common"),Schema_1=require("./Schema"),ObjectSchema_1=require("./ObjectSchema"),utils_1=require("../../utils"),SubSchema_1=require("./SubSchema"),store_1=require("../../jotai/store"),helpers_1=require("./helpers"),styled_1=require("../common/styled");function ArraySchemaComponent(e){var r,t,{schema:l,schema:{minItems:s,maxItems:a,items:i},fieldParentsName:n}=e,o=__rest(e,["schema","schema","fieldParentsName"]);const{schemasExpansionLevel:c}=(0,jotai_1.useAtomValue)(store_1.globalOptionsAtom),m=Array.isArray(o.parentType)?o.parentType:[o.parentType],u=m.includes("array")&&1===m.length,d=u?(o.level||0)+1:o.level,_=void 0===s&&void 0===a?"":`(${(0,utils_1.humanizeConstraints)(l)})`;let y=n?[...n.slice(0,-1),n[n.length-1]+"[]"]:n;const h=(0,react_1.useCallback)((e=>o.skipReadOnly||o.skipWriteOnly?null==e?void 0:e.filter((e=>!(o.skipReadOnly&&e.schema.readOnly||o.skipWriteOnly&&e.schema.writeOnly))):e),[o.skipReadOnly,o.skipWriteOnly]);if(null==l?void 0:l.fields)return(0,jsx_runtime_1.jsx)(ObjectSchema_1.ObjectSchema,Object.assign({},o,{shouldCloseArray:u,level:d,schema:l,fieldParentsName:y}));if(l.displayType&&!i&&!_.length)return(0,jsx_runtime_1.jsx)("div",{children:(0,jsx_runtime_1.jsx)(common_1.TypeName,{children:l.displayType})});const p=h(null==i?void 0:i.fields),j=h(null===(t=null===(r=null==i?void 0:i.oneOf)||void 0===r?void 0:r[0])||void 0===t?void 0:t.fields),x=(null==p?void 0:p.length)||(null==j?void 0:j.length),v=1===o.level,b=(0,helpers_1.getExpandByDefault)({level:o.level,required:o.required,schemasExpansionLevel:c});return(0,jsx_runtime_1.jsx)(SubSchema_1.SubSchema,Object.assign({},o,{propertyLength:x,isNestedArray:u,level:d,isArray:!0,expandable:!v,expandByDefault:b,operationPointer:l.operationPointer,children:(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[v&&(0,jsx_runtime_1.jsx)(styled_1.ArrayLabel,{children:(0,jsx_runtime_1.jsx)(styled_1.LabelValue,{children:"Array ["})}),(0,jsx_runtime_1.jsx)(Schema_1.Schema,Object.assign({},o,{parentType:v?void 0:l.type,level:d,schema:i,shouldCloseArray:u,fieldParentsName:y,expandable:!1})),v&&(0,jsx_runtime_1.jsx)(styled_1.ArrayClosingLabel,{className:"array-closing-label",children:(0,jsx_runtime_1.jsx)(styled_1.LabelValue,{children:"]"})})]})}))}exports.ArraySchema=(0,react_1.memo)(ArraySchemaComponent);
//# sourceMappingURL=ArraySchema.js.map