// 工具箱

import { CHANGE_LOGS } from './toolbox-changelogs';

const MODULES = import.meta.glob('../../views/ToolboxView/**/*.vue');

/**
 * @desc 工具列表
 * @type {ToolboxCategory[]}
 */
export const toolList = [
  {
    id: 'calculation-tools',
    title: '计算',
    enabled: true,
    items: [
      {
        id: 'calc-ratio',
        component: 'Calculation/CalcRatio',
        title: '比例计算',
        iconClass: 'mdi mdi-calculator-variant-outline',
        desc: '按设定的比例计算给出的数值所对应的数值。',
        createdAt: '2024-09-08',
        updatedAt: '2024-09-08',
        version: '1',
        enabled: true,
      },
      {
        id: 'calc-download-time',
        component: 'Calculation/CalcDownloadTime',
        title: '下载用时计算',
        iconClass: 'mdi mdi-calculator-variant-outline',
        desc: '根据设定的文件大小和下载速度简单计算大约下载完成所需的时间。',
        createdAt: '2024-09-08',
        updatedAt: '2024-09-08',
        version: '1',
        enabled: true,
      },
    ]
  },
  {
    id: 'conversion-tools',
    title: '转换',
    enabled: true,
    items: [
      {
        id: 'base64-encode-decode',
        component: 'Conversion/Base64StringEncodeDecode',
        title: 'Base64 字符串编码 / 解码',
        iconClass: 'mdi mdi-swap-horizontal',
        desc: '处理 Base64 编码的字符串。',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'convert-timestamp',
        component: 'Conversion/ConvertTimestamp',
        title: 'Unix 时间戳转换',
        iconClass: 'mdi mdi-swap-horizontal',
        desc: '时间戳转时间字符串 / 时间字符串转时间戳',
        createdAt: '2025-02-05',
        updatedAt: '2025-02-05',
        version: '1',
        enabled: true,
      },
      {
        id: 'url-encode-decode',
        component: 'Conversion/UrlEncodeDecode',
        title: 'URL 编码 / 解码',
        iconClass: 'mdi mdi-swap-horizontal',
        desc: '处理 URL 编码的字符串。',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'qrcode-reader-and-generator',
        component: 'Conversion/QrcodeReaderAndGenerator',
        title: '二维码解析和生成',
        iconClass: 'mdi mdi-qrcode',
        desc: '解析二维码 / 生成二维码',
        createdAt: '2025-02-21',
        updatedAt: '2025-02-23',
        version: '2',
        enabled: true,
        changelogs: CHANGE_LOGS['qrcode-reader-and-generator'],
      },
      {
        id: 'convert-text-structure',
        component: 'Conversion/ConvertTextStructure',
        title: '文本结构转换',
        iconClass: 'mdi mdi-swap-horizontal',
        desc: '倒序、横竖互换等',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'convert-html-entities',
        component: 'Conversion/ConvertHtmlEntities',
        title: '转换 HTML 实体',
        iconClass: 'mdi mdi-swap-horizontal',
        desc: '',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
    ]
  },
  {
    id: 'edit-tools',
    title: '编辑',
    enabled: true,
    items: [
      {
        id: 'csv-editor',
        component: 'Edit/CsvEditor',
        title: 'CSV 编辑',
        iconClass: 'mdi mdi-table-edit',
        desc: '查看或编辑 CSV 文件',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'json-editor',
        component: 'Edit/JsonEditor',
        title: 'JSON 编辑器',
        iconClass: 'mdi mdi-code-json',
        desc: '基于 Monaco Editor 实现的 JSON 编辑器。',
        createdAt: '2025-10-26',
        updatedAt: '2025-10-26',
        version: '1',
        enabled: true,
      },
      {
        id: 'json-formatter',
        component: 'Edit/JsonFormatter',
        title: 'JSON 格式化',
        iconClass: 'mdi mdi-code-json',
        desc: '格式化 / 美化 JSON 字符串',
        createdAt: '2025-02-04',
        updatedAt: '2025-02-07',
        version: '2',
        enabled: true,
        changelogs: CHANGE_LOGS['json-formatter'],
      },
      {
        id: 'text-editor',
        component: 'Edit/TextEditor',
        title: '文本编辑器',
        iconClass: 'mdi mdi-text-long',
        desc: '基于 Monaco Editor 实现的文本编辑器。',
        createdAt: '2025-12-21',
        updatedAt: '2025-12-21',
        version: '1',
        enabled: true,
      },
    ],
  },
  {
    id: 'generator-tools',
    title: '生成',
    enabled: true,
    items: [
      {
        id: 'frp-config-generator',
        component: 'Generator/FrpConfigGenerator/FrpConfigGenerator',
        title: 'frp 配置文件生成',
        iconClass: 'mdi mdi-file-cog-outline',
        desc: '生成用于 frpc、frps 的配置文件。',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'uuid-generator',
        component: 'Generator/UuidGenerator',
        title: 'UUID 生成器',
        iconClass: 'mdi mdi-identifier',
        desc: '生成 UUID 列表。',
        createdAt: '2026-01-03',
        updatedAt: '2026-01-03',
        version: '1',
        enabled: true,
      },
      {
        id: 'generate-urls',
        component: 'Generator/GenerateUrls',
        title: '生成批量下载链接',
        iconClass: 'mdi mdi-link-variant',
        desc: '根据设置，生成有一定规律的用于批量下载的链接。',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'generate-random-string',
        component: 'Generator/GenerateRandomString',
        title: '生成随机字符串',
        iconClass: 'mdi mdi-format-text',
        desc: '生成随机组合的字符串，可用于密码。',
        createdAt: '2024-09-08',
        updatedAt: '2024-09-08',
        version: '1',
        enabled: true,
      },
    ]
  },
  {
    id: 'minecraft-tools',
    title: 'Minecraft',
    enabled: true,
    items: [
      {
        id: 'minecraft-uuid-converter',
        component: 'Minecraft/UuidConverter',
        title: 'Minecraft UUID 转换',
        iconClass: 'mdi mdi-identifier',
        desc: '随机生成或转换 Minecraft 的 UUID。',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'minecraft-chat-history-reader',
        component: 'Minecraft/ChatHistoryReader/ChatHistoryReader',
        title: 'Minecraft 聊天记录查看',
        iconClass: 'mdi mdi-format-list-text',
        desc: '读取并解析 latest.log 文件，显示聊天记录。',
        createdAt: '2025-02-03',
        updatedAt: '2025-02-03',
        version: '1',
        enabled: true,
      },
      {
        id: 'calc-minecraft-chunk-location',
        component: 'Minecraft/CalcChunkLocation',
        title: 'Minecraft 区块位置计算',
        iconClass: 'mdi mdi-calculator-variant-outline',
        desc: '',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'generate-minecraft-dynmap-renderdata',
        component: 'Minecraft/GenerateDynmapRenderdata',
        title: '生成 Dynmap renderdata',
        iconClass: 'mdi mdi-file-outline',
        desc: '生成用于 Minecraft Dynmap 插件或模组的 renderdata 数据。',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
    ]
  },
  {
    id: 'network-tools',
    title: '网络',
    enabled: true,
    items: [
      {
        id: 'websocket-test-tool',
        component: 'Network/WebSocketTestTool',
        title: 'WebSocket 测试',
        iconClass: 'mdi mdi-connection',
        desc: '连接 WebSocket 服务端，发送和接收消息。',
        createdAt: '2024-12-01',
        updatedAt: '2024-12-01',
        version: '1',
        enabled: true,
      },
    ],
  },
  {
    id: 'other-tools',
    title: '其他',
    enabled: true,
    items: [
      {
        id: 'keep-screen-on',
        component: 'Other/KeepScreenOn',
        title: '保持亮屏',
        iconClass: 'mdi mdi-monitor',
        desc: '保持屏幕开启，不息屏，不休眠。',
        createdAt: '2024-10-11',
        updatedAt: '2024-10-13',
        version: '2',
        enabled: true,
        changelogs: CHANGE_LOGS['keep-screen-on'],
      },
      {
        id: 'visualized-working-hours',
        component: 'Other/VisualizedWorkingHours/VisualizedWorkingHours',
        title: '工作时间可视化',
        iconClass: 'mdi mdi-clock-digital',
        desc: '用趣味化的方式呈现工作收益与时间进度，让薪资进度和下班期待看得见。',
        createdAt: '',
        updatedAt: '',
        version: '0',
        enabled: false,
      },
      {
        id: 'timer-tool',
        component: 'Other/TimerTool',
        title: '计时器',
        iconClass: 'mdi mdi-timer-outline',
        desc: '正计时、倒计时工具。',
        createdAt: '2025-12-29',
        updatedAt: '2025-12-29',
        version: '1',
        enabled: true,
      },
      {
        id: 'open-new-window',
        component: 'Other/OpenNewWindow',
        title: '新窗口中打开',
        iconClass: 'mdi mdi-window-maximize',
        desc: '从新的小窗口中打开指定的链接（仅支持 PC 端浏览器）。',
        createdAt: '2025-02-04',
        updatedAt: '2025-02-04',
        version: '1',
        enabled: true,
      },
      {
        id: 'run-javascript',
        component: 'Other/RunJavaScript',
        title: '执行 JavaScript',
        iconClass: 'mdi mdi-code-braces',
        desc: '执行简单的 JavaScript 代码片段。',
        createdAt: '2026-01-03',
        updatedAt: '2026-01-03',
        version: '1',
        enabled: true,
      },
      {
        id: 'genshin-impact-clock',
        component: 'Other/GenshinImpactClock/GenshinImpactClock',
        title: '《原神》时钟',
        iconClass: 'mdi mdi-clock-outline',
        desc: '在网页上实现的《原神》时钟效果。',
        createdAt: '2024-10-13',
        updatedAt: '2024-10-13',
        version: '1',
        enabled: true,
      },
    ],
  },
];

/**
 * @description 获取动态组件
 * @param {string} path 工具页面相对路径
 */
function getDynamicComponent(path) {

  let key = `../../views/ToolboxView/${path}.vue`;
  let component = MODULES[key];

  return component;

}

/** 生成工具箱页面路由 */
export function getToolboxRoutes() {

  /** @type {VueRouteRecordRaw[]} */
  let routes = [];

  toolList.forEach((categoryItem) => {
    categoryItem.items.forEach((toolItem) => {

      // // 跳过未启用的工具
      // if (!toolItem.enabled) {
      //   return;
      // }

      routes.push({
        path: `/toolbox-view/${toolItem.id}`,
        name: `Toolbox/${toolItem.component}`,
        component: getDynamicComponent(toolItem.component),
        meta: {
          isToolDetail: true,
          title: toolItem.title,
        },
      });

    });
  });

  return routes;

}
