import stripIndent from './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.mjs';
import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.mjs';
import { bold, magenta, green, cyan, dim } from './node_modules/.pnpm/colorette@2.0.19/node_modules/colorette/index.mjs';

function printHelp({
  kind,
  options: customOptions,
  packageManager
} = {}) {
  const command = createCommand(packageManager);
  const usage = stripIndent`
    ${bold('Usage:')}   ${command} ${kind ? magenta(kind) : magenta('[kind]')} ${green('[name]')} ${cyan('[options]')}
  `;
  console.log(usage);
  const example = stripIndent`
    ${bold('Example:')} ${command} ${magenta(kind ?? 'app')} ${green(`my-${kind ?? 'app'}`)} ${cyan('--install')}
  `;
  console.log(dim(example));
  if (!kind) {
    const kindSection = stripIndent`
    ${bold(magenta('kind'))} can be one of the following project types:

     - ${magenta('app')}, a web application
     - ${magenta('service')}, a web server without a user interface
     - ${magenta('package')}, a shared library of code
     - ${magenta('module')}, a standalone JavaScript module for a browser

    You’ll be asked a few additional questions based on the kind you choose.
  `;
    console.log();
    console.log(kindSection);
  }
  const optionsSection = stripIndent`
    ${cyan('--name')}
    The name of the project. When creating a package, you should use the public name you
    want for the package, including any scope you want to use (example: ${bold('@my-org/my-package')}).
    If you don’t provide a name with this flag, this command will ask you for one later.

    ${cyan('--directory')}
    The directory to create the project in. If you don’t provide this flag, Quilt will pick
    a default directory based on the kind of the project and the name you provided.

    ${cyan(`--monorepo`)}, ${cyan(`--no-monorepo`)}
    If you aren’t already in a monorepo, this flag will create your new project with some
    additional structure that allows it to be a monorepo — that is, you will be able to add
    multiple projects to a single repository.

    ${cyan(`--install`)}, ${cyan(`--no-install`)}
    Whether to install dependencies in the newly created project. If you do not provide this
    flag, Quilt will ask you about it later.

    ${cyan('--package-manager')}
    The package manager to use for your new project. This choice will be used to populate
    some commands, and will be used to install dependencies if the ${cyan('--install')} flag is set.

    Must be one of the following: ${bold('pnpm')}, ${bold('npm')}, or ${bold('yarn')}.

    ${cyan(`--extras`)}, ${cyan(`--no-extras`)}
    Extra developer tools to configure when creating your new project. This option only
    applies when creating a brand new project, not when adding a project to an existing
    workspace. You can include this flag multiple times to add multiple tools. You can
    enable any of the following tools:

     - ${bold('github')}, which adds a continuous integration (CI) GitHub Action to your project.
     - ${bold('vscode')}, which adds some basic VSCode settings to your project.

    ${cyan('--yes')}, ${cyan('-y')}
    Answers “yes” to any question this command would have asked.

    ${cyan('--help')}, ${cyan('-h')}
    Prints this help documentation.
  `;
  console.log();
  console.log(`${bold(cyan('options'))} can include any of these flags:`);
  if (customOptions) {
    console.log();
    console.log(printOptionsSection(customOptions));
  }
  console.log();
  console.log(printOptionsSection(optionsSection));
}
function printOptionsSection(section) {
  return section.split('\n').map(line => line.length > 0 ? ` ${line}` : line).join('\n');
}
function createCommand(explicitPackageManager) {
  let packageManager;
  const npmUserAgent = process.env['npm_config_user_agent'] ?? 'npm';
  if (npmUserAgent.includes('pnpm') || explicitPackageManager === 'pnpm') {
    packageManager = 'pnpm';
  } else if (npmUserAgent.includes('yarn') || explicitPackageManager === 'yarn') {
    packageManager = 'yarn';
  } else {
    packageManager = 'npm';
  }
  return `${packageManager} create @quilted`;
}

export { printHelp };
