Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

25.9 KB
Raw Blame
'use client';

import {
  // oxlint-disable-next-line stylex-migration/no-emotion-styles -- Form.Group renders its body without a slot
  createStaticStyles,
  Flexbox,
} from '@lobehub/ui';
import { Form } from '@lobehub/ui/form';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
import type { ComponentType, ReactNode } from 'react';
import { useTranslation } from 'react-i18next';

import NavHeader from '@/features/NavHeader';
import SettingContainer from '@/features/Setting/SettingContainer';
import type { RouteSkeletonProps } from '@/spa/router/routeMeta';
import { useDensity } from '@/styles/density';
import { sx } from '@/styles/sx';

import SkeletonBar from '../Bar';

/** A static copy key: `[namespace, key]`. */
export type SettingsSkeletonTextKey = readonly [namespace: string, key: string];

/** Shared head options of every section rendered as a filled `Form.Group`. */
interface GroupHeadOptions {
  /** The real group shows a description line under its title. */
  desc?: boolean;
  /** The real description is static copy: render it instead of a bar. */
  descKey?: SettingsSkeletonTextKey;
  /**
   * The real group shows an action on the right of its head; `true` is a
   * 120×32 button, or pass the action's size.
   */
  extra?: boolean | { height: number; width: number };
  /** The real title is static copy: render it instead of a bar. */
  heading?: SettingsSkeletonTextKey;
  titleWidth?: number;
}

/** One captioned quota block: a two-column row of cells of `cellHeight`. */
interface QuotaBlockShape {
  caption?: SettingsSkeletonTextKey;
  cellHeight: number;
  /** Static label of each cell; the figures under it stay placeholders. */
  labels?: SettingsSkeletonTextKey[];
}

/**
 * One block of a settings page. Every variant except `cards` (ungrouped) and
 * `banner` is a filled `Form.Group`, so the skeleton reuses the real group
 * chrome and only the contents are placeholders.
 */
export type SettingsSectionSkeleton =
  | (GroupHeadOptions & {
      /**
       * One full-width control instead of labelled rows: `true` is a 38px input
       * with a trailing button, `input` a 32px input, `snippet` a 38px copyable
       * snippet (its copy button sits inside).
       */
      field?: boolean | 'input' | 'snippet';
      /** Label + description on the left, control on the right. */
      rows?: number;
      variant: 'form';
    })
  | (GroupHeadOptions & {
      /** Number of table columns (default 5). */
      columns?: number;
      /** Table rows below the header row. */
      rows?: number;
      /**
       * A row of this many compact label + figure columns above the table,
       * split from it by a divider.
       */
      stats?: number;
      /** A filter / search bar above the table. */
      toolbar?: boolean;
      /** A tab strip above the table. */
      tabs?: boolean;
      variant: 'table';
    })
  | (GroupHeadOptions & {
      columns?: number;
      /**
       * Borderless tiles 8px apart inside the padded group body, instead of
       * bordered tiles edge to edge.
       */
      inset?: boolean;
      /** Height of one tile; defaults to a two-line tile. */
      tileHeight?: number;
      /** Compact label + value tiles laid out edge to edge. */
      tiles?: number;
      variant: 'tiles';
    })
  | (GroupHeadOptions & {
      /** A media block on the right of the figures, e.g. an illustrated card. */
      aside?: { height: number; width: number };
      /** A second label/value pair plus a divider and a link row below the figure. */
      secondary?: boolean;
      /** A second column (label + link) right of a vertical rule. */
      split?: boolean;
      /** Label, one large figure and a caption line. */
      variant: 'summary';
    })
  | (GroupHeadOptions & {
      /** Checklist columns (default 1); `lines` are split across them. */
      columns?: number;
      /** The header starts with an icon tile (default true). */
      icon?: boolean;
      /** Icon + title header followed by a checklist. */
      lines?: number;
      variant: 'detail';
    })
  | (GroupHeadOptions & {
      /**
       * Captioned quota blocks edge to edge, each a two-column row of cells
       * of `cellHeight`.
       */
      blocks: QuotaBlockShape[];
      /** Setting rows (label + description, control) under the blocks. */
      rows?: number;
      variant: 'quota';
    })
  | (GroupHeadOptions & {
      /** A numbered list of rule lines. */
      lines: number;
      variant: 'rules';
    })
  | (GroupHeadOptions & {
      cards?: number;
      columns?: number;
      /** Key/value lines, a note block and a total + action row below the grid. */
      footer?: boolean;
      gap?: number;
      /** Wrap the grid in a titled filled group; otherwise the cards stand alone. */
      grouped?: boolean;
      /** `large` cards carry icon, title, figure, button and a checklist. */
      size?: 'large' | 'small';
      /** A centred segmented control above the grid, and its gap to the grid. */
      toolbar?: { gap: number; height: number; width: number };
      variant: 'cards';
    })
  | {
      /**
       * A filled lead block above the groups: a large title, a description, a
       * full-width input with a trailing button, and a short line under it.
       */
      variant: 'banner';
    };

export interface SettingsSectionsShape {
  /** Vertical gap between sections, as set by the real page's stack. */
  gap?: number;
  sections: SettingsSectionSkeleton[];
  /** Number of tabs in a strip above the sections, 16px above the first one. */
  tabs?: number;
  /** The page draws its own large title + divider above the sections. */
  title?: boolean;
}

/**
 * Where the skeleton sits when the route has no layout chrome around it
 * (`chrome='page'`). Under `chrome='body'` the host layout already draws its
 * header and padded container, so only the sections render.
 *
 * - `header`: navigation header above a padded, centred 1024px container.
 * - `container`: padded, centred container only (the page draws its own title).
 * - `none`: the sections alone.
 */
export type SettingsSectionsFrame = 'container' | 'header' | 'none';

const styles = stylex.create({
  banner: {
    backgroundColor: cssVar.colorFillQuaternary,
    borderRadius: cssVar.borderRadiusLG,
  },
  card: {
    overflow: 'hidden',
    borderWidth: '1px',
    borderStyle: 'solid',
    borderColor: cssVar.colorBorderSecondary,
    borderRadius: cssVar.borderRadiusLG,
  },
  divider: {
    width: '100%',
    height: '1px',
    backgroundColor: cssVar.colorBorderSecondary,
    backgroundImage: 'none',
  },
  grid: { display: 'grid' },
  quotaBlock: {
    borderBlockStartWidth: { 'default': '1px', ':first-child': '0' },
    borderBlockStartStyle: 'solid',
    borderBlockStartColor: cssVar.colorBorderSecondary,
  },
  rule: {
    flexShrink: 0,
    width: '1px',
    borderInlineStartWidth: '1px',
    borderInlineStartStyle: 'dashed',
    borderInlineStartColor: cssVar.colorBorderSecondary,
  },
  tile: {
    borderBlockEndWidth: '1px',
    borderBlockEndStyle: 'solid',
    borderBlockEndColor: cssVar.colorBorderSecondary,
    borderInlineEndWidth: '1px',
    borderInlineEndStyle: 'solid',
    borderInlineEndColor: cssVar.colorBorderSecondary,
  },
});

const fallback = createStaticStyles(({ css }) => ({
  flush: css`
    overflow: hidden;

    [data-form-group-body] {
      padding: 0;
    }
  `,
}));

const widthAt = (index: number, widths: number[]) => widths[index % widths.length];

/** Matches the 16px/25px title line of a filled group head. */
const GroupTitle = ({ width = 104 }: { width?: number }) => (
  <Flexbox height={25} justify={'center'}>
    <SkeletonBar height={16} width={width} />
  </Flexbox>
);

/** Matches the 12px/19px description line of a group head. */
const GroupDesc = () => (
  <Flexbox height={19} justify={'center'}>
    <SkeletonBar height={12} width={220} />
  </Flexbox>
);

/** Static copy as text once its namespace has loaded; `undefined` until then. */
const useStaticText = (key?: SettingsSkeletonTextKey) => {
  // Keys come from shape data, so they are untyped against the i18n resources.
  const { t, ready } = useTranslation((key?.[0] ?? 'common') as any);
  return key && ready ? (t(key[1] as any, { ns: key[0] as any }) as string) : undefined;
};

const Group = ({
  children,
  desc,
  descKey,
  extra,
  flush,
  heading,
  titleWidth,
}: GroupHeadOptions & { children: ReactNode; flush?: boolean }) => {
  const title = useStaticText(heading);
  const description = useStaticText(descKey);
  const extraSize = extra === true ? { height: 32, width: 120 } : extra || undefined;

  return (
    <Form.Group
      className={flush ? fallback.flush : undefined}
      collapsible={false}
      desc={description ?? (desc || descKey ? <GroupDesc /> : undefined)}
      extra={extraSize ? <SkeletonBar {...extraSize} /> : undefined}
      title={title ?? <GroupTitle width={titleWidth} />}
      variant={'filled'}
    >
      {children}
    </Form.Group>
  );
};

const FormRows = ({ rows }: { rows: number }) => (
  <Flexbox>
    {Array.from({ length: rows }).map((_, index) => (
      <Flexbox key={index}>
        {index > 0 && <div {...stylex.props(styles.divider)} />}
        <Flexbox
          horizontal
          align={'center'}
          gap={24}
          justify={'space-between'}
          style={{ minHeight: 64, paddingBlock: 16 }}
        >
          <Flexbox gap={8}>
            <SkeletonBar height={16} width={widthAt(index, [112, 152])} />
            <SkeletonBar height={12} width={widthAt(index, [224, 260, 296])} />
          </Flexbox>
          <SkeletonBar height={32} width={widthAt(index, [88, 152])} />
        </Flexbox>
      </Flexbox>
    ))}
  </Flexbox>
);

const TABLE_COLUMNS = [18, 12, 14, 16, 12];

const tableColumns = (count = TABLE_COLUMNS.length) =>
  Array.from({ length: count }, (_, index) => TABLE_COLUMNS[index % TABLE_COLUMNS.length]);

const TableBody = ({
  columns,
  rows,
  tabs,
  toolbar,
}: {
  columns?: number;
  rows: number;
  tabs?: boolean;
  toolbar?: boolean;
}) => {
  const flexes = tableColumns(columns);

  return (
    <Flexbox>
      {tabs && (
        <Flexbox horizontal align={'center'} gap={24} height={48} paddingInline={16}>
          <SkeletonBar height={14} width={64} />
          <SkeletonBar height={14} width={72} />
          <SkeletonBar height={14} width={64} />
        </Flexbox>
      )}
      {toolbar && (
        <Flexbox horizontal align={'center'} gap={8} height={61} paddingInline={16}>
          <Flexbox flex={2}>
            <SkeletonBar height={32} />
          </Flexbox>
          <Flexbox flex={1}>
            <SkeletonBar height={32} />
          </Flexbox>
          <Flexbox flex={1.5}>
            <SkeletonBar height={32} />
          </Flexbox>
          <SkeletonBar height={32} width={72} />
        </Flexbox>
      )}
      <Flexbox horizontal align={'center'} gap={24} height={40} paddingInline={16}>
        {flexes.map((flex, index) => (
          <Flexbox flex={flex} key={index}>
            <SkeletonBar height={12} width={'48%'} />
          </Flexbox>
        ))}
      </Flexbox>
      {Array.from({ length: rows }).map((_, row) => (
        <Flexbox key={row}>
          <div {...stylex.props(styles.divider)} />
          <Flexbox horizontal align={'center'} gap={24} height={52} paddingInline={16}>
            {flexes.map((flex, index) => (
              <Flexbox flex={flex} key={index}>
                <SkeletonBar height={14} width={`${56 + ((row + index) % 3) * 14}%`} />
              </Flexbox>
            ))}
          </Flexbox>
        </Flexbox>
      ))}
    </Flexbox>
  );
};

const Field = ({ kind }: { kind: true | 'input' | 'snippet' }) =>
  kind === true ? (
    <Flexbox horizontal align={'center'} gap={8}>
      <Flexbox flex={1}>
        <SkeletonBar height={38} />
      </Flexbox>
      <SkeletonBar height={38} width={88} />
    </Flexbox>
  ) : (
    <SkeletonBar height={kind === 'input' ? 32 : 38} />
  );

const InsetTiles = ({
  columns,
  tileHeight,
  tiles,
}: {
  columns: number;
  tileHeight: number;
  tiles: number;
}) => (
  <div
    {...sx(styles.grid, {
      gap: 8,
      gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
    })}
  >
    {Array.from({ length: tiles }).map((_, index) => (
      <Flexbox gap={12} height={tileHeight} justify={'center'} key={index}>
        <SkeletonBar height={14} width={widthAt(index, [56, 72, 64])} />
        <SkeletonBar height={24} width={widthAt(index, [32, 40, 72])} />
      </Flexbox>
    ))}
  </div>
);

const Tiles = ({
  columns,
  tileHeight,
  tiles,
}: {
  columns: number;
  tileHeight: number;
  tiles: number;
}) => (
  <div {...sx(styles.grid, { gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` })}>
    {Array.from({ length: tiles }).map((_, index) => (
      <Flexbox
        horizontal
        align={'center'}
        className={stylex.props(styles.tile).className}
        gap={12}
        height={tileHeight}
        justify={'space-between'}
        key={index}
        paddingInline={12}
      >
        <Flexbox gap={8}>
          <SkeletonBar height={14} width={widthAt(index, [56, 72, 64])} />
          <SkeletonBar height={14} width={widthAt(index, [160, 96, 136])} />
        </Flexbox>
        <SkeletonBar height={26} radius={'50%'} width={26} />
      </Flexbox>
    ))}
  </div>
);

const Summary = ({
  aside,
  secondary,
  split,
}: {
  aside?: { height: number; width: number };
  secondary?: boolean;
  split?: boolean;
}) => {
  const figures = secondary ? (
    <Flexbox flex={1} gap={16}>
      <SkeletonBar height={16} width={96} />
      <SkeletonBar height={28} width={48} />
      <SkeletonBar height={16} width={72} />
      <SkeletonBar height={20} width={'56%'} />
      <div {...stylex.props(styles.divider)} />
      <SkeletonBar height={20} width={200} />
    </Flexbox>
  ) : (
    <Flexbox flex={1} gap={19}>
      <SkeletonBar height={16} width={120} />
      <SkeletonBar height={36} width={200} />
      <SkeletonBar height={12} width={'42%'} />
    </Flexbox>
  );

  if (split)
    return (
      <Flexbox horizontal gap={16}>
        {figures}
        <div {...stylex.props(styles.rule)} />
        <Flexbox flex={1} gap={19}>
          <SkeletonBar height={16} width={64} />
          <SkeletonBar height={14} width={72} />
        </Flexbox>
      </Flexbox>
    );
  if (!aside) return figures;
  return (
    <Flexbox horizontal gap={16}>
      {figures}
      <SkeletonBar height={aside.height} radius={cssVar.borderRadiusLG} width={aside.width} />
    </Flexbox>
  );
};

const Checklist = ({ lines }: { lines: number }) => (
  <Flexbox>
    {Array.from({ length: lines }).map((_, index) => (
      <Flexbox horizontal align={'center'} gap={10} height={25} key={index}>
        <SkeletonBar height={12} width={12} />
        <SkeletonBar height={14} width={widthAt(index, [180, 132, 220, 156])} />
      </Flexbox>
    ))}
  </Flexbox>
);

const Detail = ({
  columns = 1,
  icon = true,
  lines,
}: {
  columns?: number;
  icon?: boolean;
  lines: number;
}) => (
  <Flexbox gap={19}>
    <Flexbox horizontal align={'center'} gap={12}>
      {icon && <SkeletonBar height={40} radius={cssVar.borderRadiusLG} width={40} />}
      <Flexbox gap={6}>
        <SkeletonBar height={16} width={96} />
        <SkeletonBar height={12} width={icon ? 200 : 96} />
      </Flexbox>
    </Flexbox>
    <div {...stylex.props(styles.divider)} />
    <div
      {...sx(styles.grid, {
        columnGap: 24,
        gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
      })}
    >
      {Array.from({ length: columns }).map((_, column) => (
        <Checklist key={column} lines={Math.ceil(lines / columns)} />
      ))}
    </div>
  </Flexbox>
);

const QuotaCaption = ({ caption }: { caption?: SettingsSkeletonTextKey }) => {
  const text = useStaticText(caption);
  return (
    <Flexbox
      height={31}
      justify={'flex-end'}
      paddingInline={16}
      style={{ color: cssVar.colorTextSecondary, fontSize: 12, fontWeight: 500 }}
    >
      {text ?? (caption && <SkeletonBar height={12} width={48} />)}
    </Flexbox>
  );
};

const QuotaCellLabel = ({ index, label }: { index: number; label?: SettingsSkeletonTextKey }) => {
  const text = useStaticText(label);
  return text ? (
    <Flexbox height={22} justify={'center'}>
      {text}
    </Flexbox>
  ) : (
    <SkeletonBar height={14} width={widthAt(index, [48, 72])} />
  );
};

const Quota = ({ blocks }: { blocks: QuotaBlockShape[] }) => (
  <Flexbox>
    {blocks.map(({ caption, cellHeight, labels }, index) => (
      <div key={index} {...stylex.props(styles.quotaBlock)}>
        <QuotaCaption caption={caption} />
        <div {...sx(styles.grid, { gridTemplateColumns: 'repeat(2, minmax(0, 1fr))' })}>
          {[0, 1].map((cell) => (
            <Flexbox gap={10} height={cellHeight} justify={'center'} key={cell} paddingInline={16}>
              <QuotaCellLabel index={cell} label={labels?.[cell]} />
              <SkeletonBar height={18} width={widthAt(cell + index, [120, 96])} />
            </Flexbox>
          ))}
        </div>
      </div>
    ))}
  </Flexbox>
);

const Rules = ({ lines }: { lines: number }) => (
  <Flexbox gap={14}>
    {Array.from({ length: lines }).map((_, index) => (
      <Flexbox horizontal align={'center'} gap={12} height={22} key={index}>
        <SkeletonBar height={20} radius={'50%'} width={20} />
        <SkeletonBar height={14} width={`${52 + (index % 4) * 11}%`} />
      </Flexbox>
    ))}
  </Flexbox>
);

const Card = ({ size }: { size: 'large' | 'small' }) =>
  size === 'large' ? (
    <Flexbox className={stylex.props(styles.card).className} gap={16} height={720} padding={16}>
      <SkeletonBar height={36} radius={cssVar.borderRadiusLG} width={36} />
      <Flexbox gap={10}>
        <SkeletonBar height={18} width={72} />
        <SkeletonBar height={14} width={'72%'} />
      </Flexbox>
      {/* Large figure then the full-width action, spaced like the loaded card. */}
      <Flexbox gap={19} paddingBlock={'20px 15px'}>
        <SkeletonBar height={32} width={128} />
        <SkeletonBar height={32} />
      </Flexbox>
      <Checklist lines={12} />
    </Flexbox>
  ) : (
    <Flexbox
      className={stylex.props(styles.card).className}
      gap={8}
      height={65}
      justify={'center'}
      paddingInline={12}
    >
      <SkeletonBar height={18} width={48} />
      <SkeletonBar height={12} width={64} />
    </Flexbox>
  );

const CardsFooter = () => (
  <Flexbox gap={16}>
    <Flexbox>
      {[96, 72, 64].map((width, index) => (
        <Flexbox horizontal align={'center'} height={25} justify={'space-between'} key={index}>
          <SkeletonBar height={12} width={width} />
          <SkeletonBar height={12} width={56} />
        </Flexbox>
      ))}
    </Flexbox>
    <SkeletonBar height={56} radius={cssVar.borderRadiusLG} />
    <div {...stylex.props(styles.divider)} />
    <Flexbox horizontal align={'center'} justify={'space-between'}>
      <SkeletonBar height={28} width={120} />
      <SkeletonBar height={38} width={128} />
    </Flexbox>
  </Flexbox>
);

const CardGrid = ({
  cards,
  columns,
  gap,
  size,
}: {
  cards: number;
  columns: number;
  gap: number;
  size: 'large' | 'small';
}) => (
  <div
    {...sx(styles.grid, {
      gap,
      gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
    })}
  >
    {Array.from({ length: cards }).map((_, index) => (
      <Card key={index} size={size} />
    ))}
  </div>
);

const Section = ({ section }: { section: SettingsSectionSkeleton }) => {
  switch (section.variant) {
    case 'banner': {
      return (
        <Flexbox className={stylex.props(styles.banner).className} gap={20} padding={24}>
          <Flexbox gap={16}>
            <SkeletonBar height={24} width={320} />
            <SkeletonBar height={14} width={440} />
          </Flexbox>
          <Flexbox gap={12}>
            <Flexbox horizontal align={'center'} gap={8}>
              <Flexbox flex={1}>
                <SkeletonBar height={40} />
              </Flexbox>
              <SkeletonBar height={40} width={136} />
            </Flexbox>
            <SkeletonBar height={22} width={176} />
          </Flexbox>
        </Flexbox>
      );
    }
    case 'cards': {
      const {
        cards = 3,
        columns = 3,
        footer,
        gap = 12,
        grouped,
        size = 'large',
        toolbar,
      } = section;
      const grid = <CardGrid cards={cards} columns={columns} gap={gap} size={size} />;
      if (grouped)
        return (
          <Group {...section}>
            <Flexbox gap={16}>
              {grid}
              {footer && <CardsFooter />}
            </Flexbox>
          </Group>
        );
      return (
        <Flexbox gap={toolbar?.gap ?? 0}>
          {toolbar && (
            <Flexbox align={'center'}>
              <SkeletonBar
                height={toolbar.height}
                radius={cssVar.borderRadiusLG}
                width={toolbar.width}
              />
            </Flexbox>
          )}
          {grid}
        </Flexbox>
      );
    }
    case 'detail': {
      return (
        <Group {...section}>
          <Detail columns={section.columns} icon={section.icon} lines={section.lines ?? 8} />
        </Group>
      );
    }
    case 'quota': {
      return (
        <Group {...section} flush>
          <Quota blocks={section.blocks} />
          {section.rows && (
            <Flexbox paddingInline={16}>
              <div {...stylex.props(styles.divider)} />
              <FormRows rows={section.rows} />
            </Flexbox>
          )}
        </Group>
      );
    }
    case 'rules': {
      return (
        <Group {...section}>
          <Rules lines={section.lines} />
        </Group>
      );
    }
    case 'form': {
      return (
        <Group {...section}>
          {section.field ? <Field kind={section.field} /> : <FormRows rows={section.rows ?? 2} />}
        </Group>
      );
    }
    case 'summary': {
      return (
        <Group {...section}>
          <Summary aside={section.aside} secondary={section.secondary} split={section.split} />
        </Group>
      );
    }
    case 'table': {
      return (
        <Group {...section} flush>
          {section.stats && (
            <>
              <Flexbox padding={16}>
                <InsetTiles columns={section.stats} tileHeight={50} tiles={section.stats} />
              </Flexbox>
              <div {...stylex.props(styles.divider)} />
            </>
          )}
          <TableBody
            columns={section.columns}
            rows={section.rows ?? 3}
            tabs={section.tabs}
            toolbar={section.toolbar}
          />
        </Group>
      );
    }
    case 'tiles': {
      if (section.inset)
        return (
          <Group {...section}>
            <InsetTiles
              columns={section.columns ?? 2}
              tileHeight={section.tileHeight ?? 61}
              tiles={section.tiles ?? 4}
            />
          </Group>
        );
      return (
        <Group {...section} flush>
          <Tiles
            columns={section.columns ?? 2}
            tileHeight={section.tileHeight ?? 63}
            tiles={section.tiles ?? 4}
          />
        </Group>
      );
    }
  }
};

/** A page-level tab strip above the sections. */
const PageTabs = ({ count }: { count: number }) => (
  <Flexbox horizontal align={'center'} gap={32} height={44}>
    {Array.from({ length: count }, (_, index) => (
      <SkeletonBar height={14} key={index} width={widthAt(index, [40, 56, 64])} />
    ))}
  </Flexbox>
);

/**
 * Large page title + divider, matching `SettingHeader`: a 24px title (38px line,
 * compact 20px / 31px) 24px (compact 16px) above the divider.
 */
const PageTitle = () => {
  const { compact, tokens } = useDensity();

  return (
    <Flexbox gap={compact ? 16 : 24} style={{ paddingTop: 12 }}>
      <Flexbox height={compact ? 31 : 38} justify={'center'}>
        <SkeletonBar height={tokens.iconBox} width={96} />
      </Flexbox>
      <div {...stylex.props(styles.divider)} />
    </Flexbox>
  );
};

/**
 * The sections of a settings page without any surrounding chrome. Use it
 * directly where a layout already draws the header and padded container.
 */
export const SettingsSectionsBody = ({ shape }: { shape: SettingsSectionsShape }) => {
  const { compact } = useDensity();
  const sections = (
    <Flexbox
      aria-busy
      data-testid={'settings-sections-skeleton'}
      gap={shape.gap ?? (compact ? 24 : 36)}
    >
      {shape.title && <PageTitle />}
      {shape.sections.map((section, index) => (
        <Section key={index} section={section} />
      ))}
    </Flexbox>
  );
  if (!shape.tabs) return sections;

  return (
    <Flexbox gap={16}>
      <PageTabs count={shape.tabs} />
      {sections}
    </Flexbox>
  );
};

/**
 * Route skeleton for a settings-style page made of stacked filled groups.
 * Under `chrome='page'` it draws the frame named by `frame`; under
 * `chrome='body'` the host layout owns that frame, so only the sections render.
 */
export const SettingsSectionsSkeleton = ({
  chrome = 'page',
  frame = 'header',
  shape,
}: RouteSkeletonProps & { frame?: SettingsSectionsFrame; shape: SettingsSectionsShape }) => {
  const body = <SettingsSectionsBody shape={shape} />;
  if (chrome === 'body' || frame === 'none') return body;

  return (
    <Flexbox aria-busy flex={1} height={'100%'} style={{ minHeight: 0, overflow: 'hidden' }}>
      {frame === 'header' && (
        <NavHeader styles={{ center: { alignItems: 'center' } }}>
          <SkeletonBar height={16} width={88} />
        </NavHeader>
      )}
      <SettingContainer maxWidth={1024} paddingBlock={'24px 128px'} paddingInline={24}>
        {body}
      </SettingContainer>
    </Flexbox>
  );
};

/**
 * Binds a shape and frame into a route `Skeleton` component. Call it once per
 * route definition (module scope) so the component identity stays stable.
 */
export const createSettingsSectionsSkeleton = (
  shape: SettingsSectionsShape,
  frame: SettingsSectionsFrame = 'header',
): ComponentType<RouteSkeletonProps> => {
  const Component = ({ chrome }: RouteSkeletonProps) => (
    <SettingsSectionsSkeleton chrome={chrome} frame={frame} shape={shape} />
  );
  Component.displayName = `SettingsSectionsSkeleton(${frame})`;
  return Component;
};

export default SettingsSectionsSkeleton;