← back to Norma

components/email-analyzer/panelLayoutDefaults.ts

84 lines

import type { LayoutState, PanelLayoutEntry } from './LayoutGrid';

export type PanelId =
  | 'original'
  | 'stats'
  | 'generated'
  | 'proscons'
  | 'chat'
  | 'score'
  | 'controls'
  | 'suggestions'
  | 'references'
  | 'versions'
  | 'saved'
  | 'search'
  | 'sdccEmails'
  | 'subjects';

export const PANEL_LABELS: Record<PanelId, string> = {
  original:    'Original Email',
  stats:       'Analysis Stats',
  generated:   'Generated Version',
  proscons:    'Version Comparison',
  chat:        'Rewrite Chat',
  score:       'Score & Feedback',
  controls:    'Rewrite Controls',
  suggestions: 'Auto-Suggested References',
  references:  'Reference Library',
  versions:    'Version Timeline',
  saved:       'Saved Analyses',
  search:      'Search Saved Emails',
  sdccEmails:  'Old Emails from SDC',
  subjects:    'Subject Line Maker',
};

/**
 * Defaults for a fresh first-load (no layout saved from a previous session):
 *  - Panels ordered ALPHABETICALLY by their label
 *  - Flowed row-major: fill across the row first, then wrap down to the next row
 *  - 3 columns by default
 *  - All panels start collapsed so the whole tool fits on one screen
 *  - User can drag panels to reposition — saved layout takes precedence on next load
 */
const DEFAULT_COLUMNS = 3;
const ALPHA_ORDER: PanelId[] = (Object.entries(PANEL_LABELS) as [PanelId, string][])
  .sort((a, b) => a[1].localeCompare(b[1]))
  .map(([id]) => id);

// Per-panel default expanded height (in row units, ~40px each).
// Sized to the actual content density so an expand doesn't open a giant void.
// Anything not listed defaults to 3 rows (~120px).
const PANEL_DEFAULT_H: Record<PanelId, number> = {
  original:    5,   // pasted email body
  generated:   5,   // generated rewrite body
  chat:        5,   // chat history
  versions:    5,   // version timeline list
  references:  4,   // reference cards
  suggestions: 3,   // small chip list
  search:      4,   // result list
  sdccEmails:  4,   // result list
  saved:       3,   // brief list
  subjects:    4,   // generated subject options
  controls:    3,   // sliders + checkboxes
  score:       2,   // small thermometer + numbers
  proscons:    3,   // two short columns
  stats:       2,   // a few numbers
};

export const DEFAULT_LAYOUT_STATE: LayoutState = {
  columns: DEFAULT_COLUMNS,
  panels: ALPHA_ORDER.map((id, i) => ({
    i: id,
    x: i % DEFAULT_COLUMNS,             // fill across first
    y: Math.floor(i / DEFAULT_COLUMNS), // then wrap down
    w: 1,
    h: PANEL_DEFAULT_H[id] ?? 3,
    collapsed: true,
  })) satisfies PanelLayoutEntry[],
};

// Bumped v7 → v8 to roll out the per-panel-density default heights.
// Old saved layouts with uniform h=5 would still feel oversized on expand.
export const LAYOUT_PREF_KEY = 'email-analyzer-layout-v8';