"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.paintDoc = exports.default = void 0;
function _chalk() {
  const data = _interopRequireDefault(require("chalk"));
  _chalk = function () {
    return data;
  };
  return data;
}
function _cliTable() {
  const data = _interopRequireDefault(require("cli-table"));
  _cliTable = function () {
    return data;
  };
  return data;
}
function _lodash() {
  const data = require("lodash");
  _lodash = function () {
    return data;
  };
  return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const paintExample = example => {
  return example.raw;
};
const paintHeader = value => {
  if (!value) return '';
  return `${_chalk().default.underline(value)}\n`;
};
const paintExamples = examples => {
  if ((0, _lodash().isEmpty)(examples) || (0, _lodash().isNil)(examples)) {
    return '';
  }
  return `\n${paintHeader('Examples')}\n${examples.map(paintExample).join('\n')}`;
};
const paintDoc = doc => {
  const {
    name,
    description,
    args,
    returns,
    properties
  } = doc;
  const table = new (_cliTable().default)({
    head: ['name', `${name}`],
    style: {
      head: ['cyan']
    }
  });
  const paintArg = arg => {
    if (!arg && !arg.type && !arg.name) {
      return '';
    }
    if (!arg.type) {
      return `${arg.name}`;
    }
    return `${arg.name}: ${arg.type}`;
  };
  const paintArgs = () => {
    if (!args || !args.length) return '';
    return `(${args.map(paintArg).join(', ')})`;
  };
  const paintDescription = arg => {
    if (!arg) return '';
    if (!arg.type) {
      return '';
    }
    if (arg && arg.type && !arg.description) {
      return arg.type;
    }
    return `${arg.type} -> ${arg.description}`;
  };
  const paintProperties = () => {
    if (!properties || !properties.length) return '';
    return `(${properties.map(paintArg).join(', ')})`;
  };
  const rows = [[_chalk().default.cyan('Description'), description], [_chalk().default.cyan('Args'), paintArgs()], [_chalk().default.cyan('Returns'), paintDescription(returns)], [_chalk().default.cyan('Properties'), paintProperties()]].filter(([, x]) => x);
  table.push(...rows);
  return table.toString() + paintExamples(doc.examples);
};
exports.paintDoc = paintDoc;
var _default = docs => {
  if ((0, _lodash().isEmpty)(docs) || (0, _lodash().isNil)(docs)) {
    return '\nNo documentation found';
  }
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
  return `\n${paintHeader('Documentation')}${docs.map(paintDoc).join('')}`;
};
exports.default = _default;

//# sourceMappingURL=docs-template.js.map