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