import { getThemeVariables } from 'ant-design-vue/dist/theme';
import lessToJs from 'less-vars-to-js';
import fs from 'fs';

function getVariablesByPath(paths: string[]) {
  let modifyVars = {};
  paths.forEach((path) => {
    const paletteLess = fs.readFileSync(path, 'utf8');
    modifyVars = Object.assign(
      modifyVars,
      lessToJs(paletteLess, { stripPrefix: true, resolveVariables: false })
    );
  });
  return modifyVars;
}
export function generateModifyVars({
  dark = false,
  paths = [],
}: {
  dark: boolean;
  paths: string[];
}) {
  const modifyVars = getThemeVariables({ dark });
  return {
    ...modifyVars,
    ...getVariablesByPath(paths),
  };
}