"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; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
// eslint-disable-next-line react/prop-types
const Variables = _ref => {
  let _ref$values = _ref.values,
    values = _ref$values === void 0 ? {} : _ref$values,
    text = _ref.text;
  const availableValues = Object.entries(values).filter(_ref2 => {
    let _ref3 = _slicedToArray(_ref2, 2),
      value = _ref3[1];
    return value !== false && value !== null && value !== 0;
  });
  return availableValues.length ? /*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
    pressable: true,
    text: availableValues.map((_ref4, index) => {
      let _ref5 = _slicedToArray(_ref4, 2),
        key = _ref5[0],
        value = _ref5[1];
      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 = _ref6 => {
  let confidence = _ref6.confidence,
    _ref6$environment = _ref6.environment,
    _ref6$environment2 = _ref6$environment === void 0 ? {} : _ref6$environment,
    _ref6$environment2$en = _ref6$environment2.entities,
    entities = _ref6$environment2$en === void 0 ? {} : _ref6$environment2$en,
    _ref6$environment2$se = _ref6$environment2.sentence,
    sentence = _ref6$environment2$se === void 0 ? {} : _ref6$environment2$se,
    _ref6$environment2$te = _ref6$environment2.terms,
    terms = _ref6$environment2$te === void 0 ? {} : _ref6$environment2$te,
    intent = _ref6.intent,
    locale = _ref6.locale,
    _ref6$response = _ref6.response,
    _ref6$response2 = _ref6$response === void 0 ? {} : _ref6$response,
    _ref6$response2$error = _ref6$response2.error,
    error = _ref6$response2$error === void 0 ? false : _ref6$response2$error,
    others = _objectWithoutProperties(_ref6, _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