"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.printCreateHeader = printCreateHeader;
exports.printCreateCustomizationHelp = printCreateCustomizationHelp;

var _boxen = _interopRequireDefault(require("boxen"));

var _chalk = _interopRequireDefault(require("chalk"));

var _wrapAnsi = _interopRequireDefault(require("wrap-ansi"));

var _jsonColorizer = _interopRequireDefault(require("json-colorizer"));

var _centerText = require("../ui/center-text");

var _getUsableTerminalSize = require("../ui/get-usable-terminal-size");

var _fillLastLine = require("../ui/fill-last-line");

var _createCoatLogo = require("../ui/create-coat-logo");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Prints the coat logo, description and the website url in
 * a pretty box.
 * On tiny terminal sizes, a shorter version is printed.
 */
function printCreateHeader() {
  const usableTerminalSize = (0, _getUsableTerminalSize.getUsableTerminalSize)(process.stdout);

  if (usableTerminalSize.size === _getUsableTerminalSize.TerminalSize.Tiny) {
    const tinyLogo = `🚀 ${_chalk.default.cyan("coat")} 🚀`;
    console.log(`\n${tinyLogo}`);
  } else {
    console.log((0, _createCoatLogo.createCoatLogo)());
  }
}
/**
 * Prints getting started guidance for the customization of the generated
 * coat files.
 *
 * On tiny terminal sizes, no help text is printed since it would overwhelm
 * the terminal log.
 */


function printCreateCustomizationHelp() {
  const usableTerminalSize = (0, _getUsableTerminalSize.getUsableTerminalSize)(process.stdout); // Don't print any customization help if the terminal window is tiny

  if (usableTerminalSize.size === _getUsableTerminalSize.TerminalSize.Tiny) {
    return;
  } // prettier-ignore


  const customizationExplanation = [`Files that are generated by ${_chalk.default.cyan("coat")} will be continuously kept up to date via your ${_chalk.default.cyan("coat")} template.`, `This means that you can't edit these files directly, because they will be overwritten when running ${_chalk.default.cyan("coat sync")}.`, "", `However, ${_chalk.default.cyan("coat")} allows you to customize the final file by creating a ${_chalk.default.green("<filename>-custom.js")} file next to the file you want to customize.`, "", `As an example, a configuration file named ${_chalk.default.green("config.json")} can be customized by placing a ${_chalk.default.green("config.json-custom.js")} file next to it.`, "The export will be merged into the file provided by coat:"].join('\n');
  const maxWidth = usableTerminalSize.width;
  const borderConfig = {
    dimBorder: true,
    padding: 1
  }; // Colorize JSON examples and put them into boxes

  const exampleConfigs = [// config.json from coat
  (0, _jsonColorizer.default)(JSON.stringify({
    coatConfig: "value from your coat template"
  }), {
    pretty: true
  }), // config.json-custom.js
  `module.exports = ${(0, _jsonColorizer.default)(JSON.stringify({
    customConfig: "value specified by you"
  }), {
    pretty: true
  })}`, // Resulting config.json
  (0, _jsonColorizer.default)(JSON.stringify({
    coatConfig: "value from your coat template",
    customConfig: "value specified by you"
  }), {
    pretty: true
  })].map(exampleConfig => // place example config in a box and fill
  // the last line of the string to have
  // equally sized boxes
  (0, _boxen.default)((0, _fillLastLine.fillLastLine)(exampleConfig, maxWidth), borderConfig));
  const text = [(0, _centerText.centerText)("💡 Before you get started 💡", maxWidth), "", (0, _wrapAnsi.default)(customizationExplanation, maxWidth), "", _chalk.default.dim("// config.json from coat"), exampleConfigs[0], "", `${_chalk.default.dim("// config.json-custom.js")}`, exampleConfigs[1], "", `${_chalk.default.dim("// config.json that will be placed")}`, exampleConfigs[2]].join("\n"); // TODO: See #52
  // Add link to customization documentation once it exists
  // Place customization help into a box

  const customizationTextBox = (0, _boxen.default)(text, { ...borderConfig,
    float: "center"
  });
  console.log(customizationTextBox);
}