"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Environment = void 0;
var _ui = require("@mirai/ui");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var style = _interopRequireWildcard(require("./Environment.module.css"));
const _excluded = ["confidence", "environment", "intent", "locale", "response"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
// eslint-disable-next-line react/prop-types
const Variables = _ref => {
  let {
    values = {},
    text
  } = _ref;
  const availableValues = Object.entries(values).filter(_ref2 => {
    let [, value] = _ref2;
    return value !== false && value !== null && value !== 0;
  });
  return availableValues.length ? /*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
    pressable: true,
    text: availableValues.map((_ref3, index) => {
      let [key, value] = _ref3;
      return /*#__PURE__*/_react.default.createElement(_ui.Text, {
        key: "".concat(text, ":").concat(index),
        markdown: false,
        tiny: true,
        className: style.variable
      }, "".concat(key, ": ").concat(JSON.stringify(value)));
    })
  }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
    tiny: true
  }, text)) : null;
};
const Environment = _ref4 => {
  let {
      confidence,
      environment: {
        entities = {},
        sentence = {},
        terms = {}
      } = {},
      intent,
      locale,
      response: {
        error = false
      } = {}
    } = _ref4,
    others = _objectWithoutProperties(_ref4, _excluded);
  return /*#__PURE__*/_react.default.createElement(_ui.View, _extends({}, others, {
    row: true,
    className: (0, _ui.styles)(style.environment, error && style.error, others.className)
  }), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    tiny: true
  }, "".concat(intent, ": ").concat(confidence)), locale && /*#__PURE__*/_react.default.createElement(_ui.Text, {
    tiny: true
  }, locale), /*#__PURE__*/_react.default.createElement(Variables, {
    text: "Entities",
    values: entities
  }), /*#__PURE__*/_react.default.createElement(Variables, {
    text: "Sentence",
    values: sentence
  }), /*#__PURE__*/_react.default.createElement(Variables, {
    text: "Terms",
    values: terms
  }));
};
exports.Environment = Environment;
Environment.propTypes = {
  classifications: _propTypes.default.any,
  confidence: _propTypes.default.number,
  environment: _propTypes.default.shape({}),
  intent: _propTypes.default.string,
  locale: _propTypes.default.string,
  response: _propTypes.default.shape({
    error: _propTypes.default.bool
  })
};
//# sourceMappingURL=Environment.js.map