import { coerceId as u, coerceBoolean as l, coerceFiniteNumber as m } from "../guards/guards.js";
import { isRecord as d } from "../../../../../isRecord.js";
const a = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
function b(e) {
  if (!d(e))
    return null;
  const o = u(e.id), n = typeof e.label == "string" ? e.label : void 0;
  if (o === void 0 || n === void 0)
    return null;
  const i = { id: o, label: n }, t = l(e.disabled);
  t !== void 0 && (i.disabled = t), typeof e.description == "string" && (i.description = e.description);
  const s = m(e.rowHeight);
  return s !== void 0 && (i.rowHeight = s), d(e.metadata) && (i.metadata = e.metadata), i;
}
function g(e) {
  if (!d(e))
    return null;
  const o = u(e.id), n = typeof e.label == "string" ? e.label : void 0;
  if (o === void 0 || n === void 0 || !Array.isArray(e.items))
    return null;
  const i = [];
  for (const p of e.items) {
    const f = b(p);
    f && i.push(f);
  }
  if (i.length === 0)
    return null;
  const t = { id: o, label: n, items: i }, s = l(e.disabled);
  s !== void 0 && (t.disabled = s);
  const c = l(e.collapsed);
  c !== void 0 && (t.collapsed = c), typeof e.description == "string" && (t.description = e.description), typeof e.color == "string" && a.test(e.color) && (t.color = e.color);
  const r = l(e.selected);
  return r !== void 0 && (t.selected = r), d(e.metadata) && (t.metadata = e.metadata), t;
}
function y(e) {
  if (!Array.isArray(e) || e.length === 0)
    return;
  const o = [];
  for (const n of e) {
    const i = g(n);
    i && o.push(i);
  }
  return o.length > 0 ? o : void 0;
}
export {
  g as normalizeCheckableListGroup,
  b as normalizeCheckableListItem,
  y as normalizeGroups
};
