"use strict";

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

function _cliTable() {
  const data = _interopRequireDefault(require("cli-table"));

  _cliTable = function () {
    return data;
  };

  return data;
}

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

function printTableJsonArray(headers, jsonArray, colWidths) {
  let table = new (_cliTable().default)({
    head: headers,
    colWidths
  });
  jsonArray.forEach(json => {
    table.push(headers.map(header => json[header] ? json[header] : ''));
  });
  return table.toString();
}

const VERTICAL_CELL_WIDTH = 80;

function printTableJson(json, header1, header2) {
  let table = new (_cliTable().default)();

  if (header1 || header2) {
    header1 = header1 ? header1 : '';
    header2 = header2 ? header2 : '';
    table.push({
      [header1]: header2
    });
  }

  Object.entries(json).forEach(([key, value]) => {
    // check if value is a JSON
    if (typeof value === 'object') {
      value = JSON.stringify(value);
    } else {
      value = String(value);
    } // Add newline every 80 chars


    key = key.replace(new RegExp('(.{' + VERTICAL_CELL_WIDTH + '})', 'g'), '$1\n');
    value = value.replace(new RegExp('(.{' + VERTICAL_CELL_WIDTH + '})', 'g'), '$1\n');
    table.push({
      [key]: value
    });
  });
  return table.toString();
}
//# sourceMappingURL=../../__sourcemaps__/commands/utils/cli-table.js.map