import * as fs from 'node:fs';
import { dim, bold } from '../node_modules/.pnpm/colorette@2.0.19/node_modules/colorette/index.mjs';
import { prompt } from '../packages/cli-kit/build/esnext/prompt.esnext.mjs';
import { getPackageManager as getPackageManager$1, createPackageManagerRunner } from '../packages/cli-kit/build/esnext/package-manager.esnext.mjs';

async function getInWorkspace(argv) {
  if (argv['--in-workspace']) return true;
  if (argv['--not-in-workspace']) return false;
  return fs.existsSync('pnpm-workspace.yaml');
}
async function getCreateAsMonorepo(argv, {
  type,
  default: defaultCreateAsMonorepo = true
}) {
  let createAsMonorepo;
  if (argv['--monorepo' ]) {
    createAsMonorepo = true;
  } else if (argv['--no-monorepo']) {
    createAsMonorepo = false;
  } else {
    createAsMonorepo = await prompt({
      type: 'confirm',
      message: `Do you want to create this ${type} as a monorepo, with room for more projects?`,
      initial: defaultCreateAsMonorepo
    });
  }
  return createAsMonorepo;
}
async function getShouldInstall(argv) {
  return !argv['--no-install'];
}
async function getPackageManager(argv, options) {
  const packageManager = await getPackageManager$1(argv['--package-manager']);
  return createPackageManagerRunner(packageManager ?? 'pnpm', options);
}
const VALID_EXTRAS = new Set(['github', 'vscode']);
async function getExtrasToSetup(argv, {
  inWorkspace
}) {
  if (inWorkspace || argv['--no-extras']) return new Set();
  if (argv['--extras']) {
    return new Set(argv['--extras'].filter(extra => VALID_EXTRAS.has(extra)));
  }
  const setupExtras = await prompt({
    type: 'multiselect',
    message: 'Which additional tools would you like to configure?',
    instructions: dim(`\n  Use ${bold('space')} to select, ${bold('a')} to select all, ${bold('return')} to submit`),
    choices: [{
      title: 'VSCode',
      value: 'vscode'
    }, {
      title: 'GitHub',
      value: 'github'
    }]
  });
  const extrasToSetup = new Set(setupExtras);
  return extrasToSetup;
}

export { getCreateAsMonorepo, getExtrasToSetup, getInWorkspace, getPackageManager, getShouldInstall, prompt };
