"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FormEditBoard = void 0;
var _locale = require("@mirai/locale");
var _ui = require("@mirai/ui");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _Booking = require("./Booking.RoomCard");
var _hooks = require("./hooks");
var _helpers = require("../../helpers");
var _Booking2 = require("../Booking.l10n");
var style = _interopRequireWildcard(require("../Booking.module.css"));
const _excluded = ["dataSource", "responseBoard", "onChange"];
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 FormEditBoard = _ref => {
  var _responseBoard$option, _responseBoard$option2, _responseBoard$option3;
  let {
      dataSource = {},
      responseBoard = {},
      onChange = () => {}
    } = _ref,
    others = _objectWithoutProperties(_ref, _excluded);
  const {
    isDesktop
  } = (0, _ui.useDevice)();
  const {
    currencyFormat,
    translate
  } = (0, _locale.useLocale)();
  const {
    currency,
    details = [],
    modify: {
      board: {
        rooms = []
      } = {}
    } = {},
    price = {}
  } = dataSource;
  const {
    selectedRoomData: {
      image,
      occupation,
      plan,
      rate,
      title
    } = {},
    showSelectedRoom
  } = (0, _hooks.useSelectedRoomData)({
    details,
    room: responseBoard.room,
    rooms
  });
  (0, _react.useEffect)(() => {
    const {
      id: roomId,
      option: {
        boardId: option,
        price: {
          value: price
        } = {}
      } = {}
    } = responseBoard || {};
    onChange({
      option,
      price,
      roomId
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [responseBoard.id, responseBoard.option]);
  return /*#__PURE__*/_react.default.createElement(_ui.View, _extends({}, others, {
    wide: true,
    className: (0, _ui.styles)(showSelectedRoom && style.formEditBoard, others.className)
  }), showSelectedRoom && /*#__PURE__*/_react.default.createElement(_Booking.RoomCard, {
    image,
    occupation,
    plan,
    rate,
    title,
    className: style.selectedRoomCard,
    testId: "booking-edit-board-room-card"
  }), /*#__PURE__*/_react.default.createElement(_ui.View, {
    wide: true,
    className: (0, _ui.styles)(style.summaryContainer, style.occupationComparison)
  }, /*#__PURE__*/_react.default.createElement(_ui.View, {
    className: (0, _ui.styles)(style.column, style.current),
    testId: "booking-current-board-summary"
  }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    headline: isDesktop
  }, translate(_Booking2.L10N.LABEL_CURRENT_BOARD)), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    action: true
  }, plan), /*#__PURE__*/_react.default.createElement(_ui.View, {
    wide: true
  }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true
  }, translate(_Booking2.L10N.LABEL_TOTAL)), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    headline: true
  }, currencyFormat({
    currency: responseBoard.currency || currency,
    value: price.value
  })), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    small: true
  }, translate(_Booking2.L10N.LABEL_INCLUDES_TAXES)))), /*#__PURE__*/_react.default.createElement(_ui.View, {
    className: style.column,
    testId: "booking-new-board-summary"
  }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    headline: isDesktop
  }, translate(_Booking2.L10N.LABEL_NEW_BOARD)), /*#__PURE__*/_react.default.createElement(_ui.View, {
    row: true,
    className: style.highlights
  }, /*#__PURE__*/_react.default.createElement(_ui.View, {
    row: true,
    className: style.highlight
  }, /*#__PURE__*/_react.default.createElement(_ui.Icon, {
    success: true,
    value: _helpers.ICON.SUCCESS
  }), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    success: true
  }, (_responseBoard$option = responseBoard.option) === null || _responseBoard$option === void 0 ? void 0 : _responseBoard$option.name))), /*#__PURE__*/_react.default.createElement(_ui.View, {
    wide: true
  }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true
  }, translate(_Booking2.L10N.LABEL_TOTAL)), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    headline: true
  }, currencyFormat({
    currency: responseBoard.currency || currency,
    value: (_responseBoard$option2 = responseBoard.option) === null || _responseBoard$option2 === void 0 ? void 0 : (_responseBoard$option3 = _responseBoard$option2.price) === null || _responseBoard$option3 === void 0 ? void 0 : _responseBoard$option3.value
  })), /*#__PURE__*/_react.default.createElement(_ui.Text, {
    small: true
  }, translate(_Booking2.L10N.LABEL_INCLUDES_TAXES))))));
};
exports.FormEditBoard = FormEditBoard;
FormEditBoard.displayName = 'Mirai:Core:Booking:FormEditBoard';
FormEditBoard.propTypes = {
  dataSource: _propTypes.default.shape({
    currency: _propTypes.default.string,
    details: _propTypes.default.arrayOf(_propTypes.default.shape({})),
    modify: _propTypes.default.shape({
      board: _propTypes.default.shape({
        rooms: _propTypes.default.arrayOf(_propTypes.default.shape({
          id: _propTypes.default.string,
          options: _propTypes.default.arrayOf(_propTypes.default.shape({}))
        }))
      })
    }),
    price: _propTypes.default.shape({
      value: _propTypes.default.number
    })
  }),
  responseBoard: _propTypes.default.shape({
    currency: _propTypes.default.string,
    id: _propTypes.default.string,
    option: _propTypes.default.shape({
      boardId: _propTypes.default.number,
      name: _propTypes.default.string,
      price: _propTypes.default.shape({
        value: _propTypes.default.number
      })
    }),
    room: _propTypes.default.shape({
      id: _propTypes.default.string,
      index: _propTypes.default.number
    })
  }),
  onChange: _propTypes.default.func
};
//# sourceMappingURL=Booking.FormEditBoard.js.map