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