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

export function buildDefaultLayout(modules: WorkbenchModuleMeta[]): WorkbenchLayout {
  const grid = modules
    .filter(m => m.defaultVisible)
    .map(m => ({
      i: m.key,
      x: m.defaultGrid.x,
      y: m.defaultGrid.y,
      w: m.defaultGrid.w,
      h: m.defaultGrid.h,
      minW: m.defaultGrid.minW,
      minH: m.defaultGrid.minH
    }));

  const hidden = modules.filter(m => !m.defaultVisible).map(m => m.key);

  return {
    version: WORKBENCH_LAYOUT_VERSION,
    grid,
    hidden,
    // 默认快捷入口（固化用户实拍选择）；已有用户的旧 settings 在 load 时优先迁移，此默认仅作用于全新用户
    settings: {
      shortcut: {
        menuKeys: [
          'product_list',
          'project_list',
          'ticket_my-submitted',
          'personal-center_my-weekly',
          'personal-center_my-monthly',
          'personal-center_my-performance',
          'personal-center_my-application',
          'infra_rd-code'
        ]
      }
    }
  };
}
