#!/usr/bin/env node
import { createRequire as createRequire_BATI_CLI } from 'module';
const require = createRequire_BATI_CLI(import.meta.url);

import {
  bir,
  txs
} from "../../../../chunk-L3HFTASV.js";
import "../../../../chunk-IAWYWZSL.js";
import "../../../../chunk-DHZ7AZKP.js";

// ../../boilerplates/shadcn-ui/dist/files/$vite.config.ts.js
async function getViteConfig(props) {
  const mod = await txs(props);
  const replacement = `new URL("./", import.meta.url).pathname`;
  addResolveAlias(mod, "@", replacement);
  return mod.generate().code.replace(`"{{PLACEHOLDER_ALIAS}}"`, replacement);
}
function addResolveAlias(mod, find, replacement) {
  const alias = mod.exports.default.$args[0]?.resolve?.alias ?? {};
  const warnMsg = `${bir("WARN")}: new resolve.alias: \`"${find}":${replacement}\` replaced existing in vite.config.ts.`;
  if (alias?.length === void 0) {
    if (alias[find]) {
      console.warn(warnMsg);
    }
    alias[find] = "{{PLACEHOLDER_ALIAS}}";
  } else {
    const newAlias = {
      find,
      replacement: "{{PLACEHOLDER_ALIAS}}"
    };
    const index = alias.findIndex((a) => a?.find === find);
    if (index >= 0) {
      console.warn(warnMsg);
      alias.splice(index, 1);
    }
    alias.push(newAlias);
  }
  if (!mod.exports.default.$args[0]?.resolve) mod.exports.default.$args[0].resolve = {};
  mod.exports.default.$args[0].resolve.alias = alias;
}
export {
  getViteConfig as default
};
