"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _reactEasyState = require("react-easy-state");

var _env = _interopRequireDefault(require("../env"));

var _emphasize = _interopRequireDefault(require("../utils/emphasize"));

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

const fg = _env.default.KTRM_UI_THEME_BG;

const lineNb = str => Math.ceil(str.length / (process.stdout.columns * 3 / 4 - 2));

class General extends _react.Component {
  render() {
    const env = (this.props.data.Config.Env || []).map(entry => entry.split('='));
    const cmd = this.props.data.Config.Cmd || this.props.data.Config.Entrypoint || ['nil'];
    let currentHeight = 0;
    return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("box", {
      width: "75%",
      shrink: true,
      left: "25%",
      top: "0%+3",
      label: " General ",
      border: {
        type: 'line'
      },
      style: {
        border: {
          fg
        }
      }
    }, _react.default.createElement("box", {
      shrink: true,
      tags: true,
      content: `${(0, _emphasize.default)('Id  :')} ${this.props.data.Id}`
    }), _react.default.createElement("box", {
      shrink: true,
      top: "0%+1",
      tags: true,
      content: `${(0, _emphasize.default)('Name:')} ${this.props.data.Name.slice(1)}`
    }), _react.default.createElement("box", {
      shrink: true,
      top: "0%+2",
      tags: true,
      content: `${(0, _emphasize.default)('Command:')} ${cmd.join(' ')}`
    })), _react.default.createElement("box", {
      width: "75%",
      shrink: true,
      left: "25%",
      top: "0%+8",
      height: "100%-9",
      alwaysScroll: true,
      scrollable: true,
      mouse: true,
      label: " Environment variables ",
      border: {
        type: 'line'
      },
      style: {
        border: {
          fg
        }
      }
    }, env.map((entry, i) => {
      const content = `${(0, _emphasize.default)(`${entry[0]}:`)} ${entry[1]}`;
      const envHeight = lineNb(content);
      currentHeight += envHeight;
      return _react.default.createElement("box", {
        shrink: true,
        key: i,
        top: `0%+${currentHeight - envHeight}`,
        height: `0%+${envHeight}`,
        tags: true,
        content: content
      });
    })));
  }

}

General.propTypes = {
  data: _propTypes.default.object
};

var _default = (0, _reactEasyState.view)(General);

exports.default = _default;