import type { WorkbenchModuleMeta } from './use-workbench-modules';
import { WORKBENCH_LAYOUT_VERSION, type WorkbenchLayout } from './workbench-layout-types';

export function buildDefaultLayout(modules: WorkbenchModuleMeta[]): WorkbenchLayout {
  const left = modules
    .filter(m => m.defaultVisible && m.defaultColumn === 'left')
    .sort((a, b) => a.defaultOrder - b.defaultOrder)
    .map(m => m.key);

  const right = modules
    .filter(m => m.defaultVisible && m.defaultColumn === 'right')
    .sort((a, b) => a.defaultOrder - b.defaultOrder)
    .map(m => m.key);

  const hidden = modules
    .filter(m => !m.defaultVisible)
    .sort((a, b) => a.defaultOrder - b.defaultOrder)
    .map(m => m.key);

  return {
    version: WORKBENCH_LAYOUT_VERSION,
    columns: [
      { id: 'left', modules: left },
      { id: 'right', modules: right }
    ],
    hidden,
    collapsed: [],
    settings: {}
  };
}
