"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getDevBanner = getDevBanner;
var _address = _interopRequireDefault(require("../compiled/address"));
var _chalk = _interopRequireDefault(require("../compiled/chalk"));
var _stripAnsi = _interopRequireDefault(require("../compiled/strip-ansi"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const BORDERS = {
  TL: _chalk.default.gray.dim('╔'),
  TR: _chalk.default.gray.dim('╗'),
  BL: _chalk.default.gray.dim('╚'),
  BR: _chalk.default.gray.dim('╝'),
  V: _chalk.default.gray.dim('║'),
  H_PURE: '═'
};
function getDevBanner(protocol, host = '0.0.0.0', port, offset = 8) {
  // prepare all source lines
  const header = ' App listening at:';
  const footer = _chalk.default.bold(' Now you can open browser with the above addresses↑ ');
  const local = `  ${_chalk.default.gray('>')}   Local: ${_chalk.default.green(`${protocol}//${host === '0.0.0.0' ? 'localhost' : host}:${port}`)} `;
  const network = `  ${_chalk.default.gray('>')} Network: ${_chalk.default.green(`${protocol}//${_address.default.ip()}:${port}`)} `;
  const maxLen = Math.max(...[header, footer, local, network].map(x => (0, _stripAnsi.default)(x).length));

  // prepare all output lines
  const beforeLines = [`${BORDERS.TL}${_chalk.default.gray.dim(''.padStart(maxLen, BORDERS.H_PURE))}${BORDERS.TR}`, `${BORDERS.V}${header}${''.padStart(maxLen - header.length)}${BORDERS.V}`, `${BORDERS.V}${local}${''.padStart(maxLen - (0, _stripAnsi.default)(local).length)}${BORDERS.V}`];
  const mainLine = `${BORDERS.V}${network}${''.padStart(maxLen - (0, _stripAnsi.default)(network).length)}${BORDERS.V}`;
  const afterLines = [`${BORDERS.V}${''.padStart(maxLen)}${BORDERS.V}`, `${BORDERS.V}${footer}${''.padStart(maxLen - (0, _stripAnsi.default)(footer).length)}${BORDERS.V}`, `${BORDERS.BL}${_chalk.default.gray.dim(''.padStart(maxLen, BORDERS.H_PURE))}${BORDERS.BR}`];

  // join lines as 3 parts for vertical middle output with logger
  return {
    before: beforeLines.map(l => l.padStart(l.length + offset)).join('\n'),
    main: mainLine,
    after: afterLines.map(l => l.padStart(l.length + offset)).join('\n')
  };
}