text: "use strict";
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.getWidthLimitedColumnsArray = exports.createHeaderAsRow = exports.renderTableHorizontalBorders = exports.findMaxLenOfColumn = exports.createRow = exports.createColumFromComputedColumn = exports.createColumFromOnlyName = exports.createTableHorizontalBorders = exports.convertRawRowOptionsToStandard = exports.cellText = void 0;
  const input_converter_1 = require("../internalTable/input-converter");
  const console_utils_1 = __importDefault(require("./console-utils"));
  const string_utils_1 = require("./string-utils");
  const table_constants_1 = require("./table-constants");
  // takes any input that is given by user and converts to string
  const cellText = (text) => text === undefined || text === null ? '' : `${text}`;
  exports.cellText = cellText;
  const convertRawRowOptionsToStandard = (options) => {
      if (options) {
          return {
              color: options.color,
          };
      }
      return undefined;
  };
  exports.convertRawRowOptionsToStandard = convertRawRowOptionsToStandard;
  const createTableHorizontalBorders = ({ left, mid, right, other, }, column_lengths) => {
      // ╚
      let ret = left;
      // ╚═══════╩═══════════════════════════════════════╩════════╩
      column_lengths.forEach((len) => {
          ret += other.repeat(len + 2);
          ret += mid;
      });
      // ╚═══════╩═══════════════════════════════════════╩════════
      ret = ret.slice(0, -mid.length);
      // ╚═══════╩═══════════════════════════════════════╩════════╝
      ret += right;
      return ret;
  };
  exports.createTableHorizontalBorders = createTableHorizontalBorders;
  const createColumFromOnlyName = (name) => ({
      name,
      title: name,
  });
  exports.createColumFromOnlyName = createColumFromOnlyName;
  const createColumFromComputedColumn = (column) => (Object.assign(Object.assign(Object.assign({ name: column.name, title: column.title || column.name }, input_converter_1.objIfExists('color', column.color)), input_converter_1.objIfExists('maxLen', column.maxLen)), { alignment: column.alignment || table_constants_1.defaultRowAlignment }));
  exports.createColumFromComputedColumn = createColumFromComputedColumn;
  const createRow = (color, text) => ({
      color,
      text,
  });
  exports.createRow = createRow;
  const findMaxLenOfColumn = (column, rows) => {
      const columnId = column.name;
      const columnTitle = column.title;
      if (column.maxLen) {
          // if customer input is mentioned a max width, lets see if all other can fit here
          // if others cant fit find the max word length so that at least the table can be printed
          const ret = Math.max(column.maxLen, string_utils_1.biggestWordInSentence(columnTitle));
          return rows.reduce((acc, row) => Math.max(acc, string_utils_1.biggestWordInSentence(exports.cellText(row.text[columnId]))), ret);
      }
      let maxLen = console_utils_1.default(columnTitle);
      rows.forEach((row) => {
          maxLen = Math.max(maxLen, console_utils_1.default(exports.cellText(row.text[columnId])));
      });
      return maxLen;
  };
  exports.findMaxLenOfColumn = findMaxLenOfColumn;
  const renderTableHorizontalBorders = (style, column_lengths) => {
      const str = exports.createTableHorizontalBorders(style, column_lengths);
      return str;
  };
  exports.renderTableHorizontalBorders = renderTableHorizontalBorders;
  const createHeaderAsRow = (createRowFn, columns) => {
      const headerColor = 'white_bold';
      const row = createRowFn(headerColor, {});
      columns.forEach((column) => {
          row.text[column.name] = column.title;
      });
      return row;
  };
  exports.createHeaderAsRow = createHeaderAsRow;
  // { col1: ['How', 'Is', 'Going'], col2: ['I am', 'Tom'],  }
  const getWidthLimitedColumnsArray = (columns, row) => {
      const ret = {};
      columns.forEach((column) => {
          ret[column.name] = string_utils_1.limitWidth(exports.cellText(row.text[column.name]), column.maxLen || 20);
      });
      return ret;
  };
  exports.getWidthLimitedColumnsArray = getWidthLimitedColumnsArray;
  