"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Information = void 0;
var _locale = require("@mirai/locale");
var _services = require("@mirai/services");
var _ui = require("@mirai/ui");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _Booking = require("./Booking.ModalAgency");
var _Booking2 = require("../Booking.l10n");
var style = _interopRequireWildcard(require("../Booking.module.css"));
var _components = require("../components");
const _excluded = ["dataSource"];
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; }
const Information = _ref => {
  let {
      dataSource: {
        agency = {},
        contact = [],
        id,
        preferences
      } = {}
    } = _ref,
    others = _objectWithoutProperties(_ref, _excluded);
  const {
    isDesktop
  } = (0, _ui.useDevice)();
  const {
    locale,
    translate
  } = (0, _locale.useLocale)();
  const [countries, setCountries] = (0, _react.useState)({});
  const [modalAgency, setModalAgency] = (0, _react.useState)(false);
  (0, _react.useEffect)(() => {
    (async () => {
      setCountries((await _services.ServiceCountry.list(locale)) || {});
    })();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [locale]);
  const handleModalAgency = () => {
    setModalAgency(true);
  };
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ui.View, _extends({}, others, {
    className: (0, _ui.styles)(style.box, others.className)
  }), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    headline: isDesktop
  }, translate(_Booking2.L10N.LABEL_BOOKING_INFO)), /*#__PURE__*/_react.default.createElement(_ui.View, null, /*#__PURE__*/_react.default.createElement(_components.Field, {
    label: translate(_Booking2.L10N.LABEL_PROMO_CODE),
    value: id
  }), contact.map(value => Object.entries(value).flat()).map(function () {
    let [field, value] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    const key = _Booking2.L10N["LABEL_".concat(field.toUpperCase())];
    return /*#__PURE__*/_react.default.createElement(_components.Field, {
      key: field,
      label: key ? translate(key) : field,
      value: field !== 'country' ? value : countries[value]
    });
  }), preferences && /*#__PURE__*/_react.default.createElement(_components.Field, {
    label: translate(_Booking2.L10N.LABEL_COMMENTS),
    value: preferences
  }), agency.name && /*#__PURE__*/_react.default.createElement(_components.Field, {
    label: translate(_Booking2.L10N.LABEL_AGENCY, {}),
    value: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, agency.name, /*#__PURE__*/_react.default.createElement(_ui.Action, {
      underline: true,
      onPress: handleModalAgency,
      className: (0, _ui.styles)(style.linkAgency, style.noPrint)
    }, translate(_Booking2.L10N.ACTION_MORE_INFO)))
  }))), (agency === null || agency === void 0 ? void 0 : agency.name) && /*#__PURE__*/_react.default.createElement(_Booking.ModalAgency, _extends({}, agency, {
    visible: modalAgency,
    onClose: () => setModalAgency(false)
  })));
};
exports.Information = Information;
Information.displayName = 'Mirai:Core:Booking:Information';
Information.propTypes = {
  dataSource: _propTypes.default.shape({
    agency: _propTypes.default.shape({
      address: _propTypes.default.string,
      email: _propTypes.default.string,
      id: _propTypes.default.string,
      name: _propTypes.default.string,
      phone: _propTypes.default.string
    }),
    contact: _propTypes.default.array,
    id: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
  })
};
//# sourceMappingURL=Booking.Information.js.map