import{jsx as n,Fragment as b,jsxs as C}from"react/jsx-runtime";import{memo as T,useCallback as k}from"react";import{useAtomValue as F}from"jotai";import{TypeName as L}from"../common/index.js";import{Schema as j}from"./Schema.js";import{ObjectSchema as S}from"./ObjectSchema.js";import{humanizeConstraints as B}from"../../utils/index.js";import{SubSchema as D}from"./SubSchema.js";import{globalOptionsAtom as R}from"../../jotai/store.js";import{getExpandByDefault as W}from"./helpers.js";import{ArrayLabel as _,LabelValue as m,ArrayClosingLabel as q}from"../common/styled.js";function E({schema:r,schema:{minItems:c,maxItems:h,items:a},fieldParentsName:l,...e}){const{schemasExpansionLevel:u}=F(R),p=Array.isArray(e.parentType)?e.parentType:[e.parentType],o=p.includes("array")&&p.length===1,t=o?(e.level||0)+1:e.level,O=c===void 0&&h===void 0?"":`(${B(r)})`;let d=l&&[...l.slice(0,-1),l[l.length-1]+"[]"];const s=k(y=>e.skipReadOnly||e.skipWriteOnly?y?.filter(f=>!(e.skipReadOnly&&f.schema.readOnly||e.skipWriteOnly&&f.schema.writeOnly)):y,[e.skipReadOnly,e.skipWriteOnly]);if(r?.fields)return n(S,{...e,shouldCloseArray:o,level:t,schema:r,fieldParentsName:d,onOneOfChange:e.onOneOfChange});if(r.displayType&&!a&&!O.length)return n("div",{children:n(L,{children:r.displayType})});const g=s(a?.fields),A=s(a?.oneOf?.[0]?.fields),v=g?.length||A?.length,i=e.level===1,x=W({level:e.level,required:e.required,schemasExpansionLevel:u});return n(D,{...e,propertyLength:v,isNestedArray:o,level:t,isArray:!0,expandable:!i,expandByDefault:x,operationPointer:r.operationPointer,children:C(b,{children:[i&&n(_,{children:n(m,{children:"Array ["})}),n(j,{...e,parentType:i?void 0:r.type,level:t,schema:a,shouldCloseArray:o,fieldParentsName:d,expandable:!1,onOneOfChange:e.onOneOfChange}),i&&n(q,{className:"array-closing-label",children:n(m,{children:"]"})})]})})}const K=T(E);export{K as ArraySchema};
