"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

exports.__esModule = true;
exports.AddressPreview = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _Common = require("../../../../../Common");

var _lib = require("@sentecacommerce-theme/lib");

var _templateObject, _templateObject2, _templateObject3, _templateObject4;

var AddressPreview = function AddressPreview() {
  var _mod$moduleData, _mod$moduleData2, _mod$moduleData4, _selectedStore$addres, _moduleAddress$office, _moduleAddress$office2, _moduleAddress$office3, _moduleAddress$office4, _moduleAddress$city, _moduleAddress$city$n, _moduleAddress$quarte, _moduleAddress$quarte2, _moduleAddress$street, _moduleAddress$street2, _invoice$company, _invoice$company2, _invoice$company3, _invoice$company4;

  var _useCheckoutFormShipp = (0, _lib.useCheckoutFormShippingState)(),
      address = _useCheckoutFormShipp.data;

  var _useCheckoutFormBilli = (0, _lib.useCheckoutFormBillingState)(),
      invoice = _useCheckoutFormBilli.data,
      withInvoice = _useCheckoutFormBilli.isWithBillingAddress;

  var _useCheckoutFormStep = (0, _lib.useCheckoutFormStep)(),
      updateStep = _useCheckoutFormStep.updateStep;

  var labels = (0, _lib.useLocalLabels)();

  var onEditClick = function onEditClick() {
    updateStep(_lib.CheckoutFormStepsEnum.Shipping);
  };

  var orderQuery = (0, _lib.useCheckoutFormOrder)();
  var mod = (0, _lib.useCheckoutShippingModule)(orderQuery);
  var isPickupFromStore = (mod == null ? void 0 : mod.moduleKey) === _lib.ShippingModulesTypeEnum.PickUpFromStore; // this should come from the config

  var isOffice = (mod == null ? void 0 : (_mod$moduleData = mod.moduleData) == null ? void 0 : _mod$moduleData.methodKey) === 'Office'; // this should come from the config

  var isAddress = (mod == null ? void 0 : (_mod$moduleData2 = mod.moduleData) == null ? void 0 : _mod$moduleData2.methodKey) === 'Address'; // this should come from the config

  var _useCheckoutPickupFro = (0, _lib.useCheckoutPickupFromStore)(),
      availableStores = _useCheckoutPickupFro.availableStores;

  var selectedStore = (0, _react.useMemo)(function () {
    if (!isPickupFromStore) return;
    return availableStores == null ? void 0 : availableStores.find(function (store) {
      var _mod$moduleData3;

      return store._id === (mod == null ? void 0 : (_mod$moduleData3 = mod.moduleData) == null ? void 0 : _mod$moduleData3.stockLocation);
    });
  }, [isPickupFromStore, availableStores, mod]);
  var moduleAddress = mod == null ? void 0 : (_mod$moduleData4 = mod.moduleData) == null ? void 0 : _mod$moduleData4.address;

  var getInfo = function getInfo(isQuarter) {
    if (isQuarter === void 0) {
      isQuarter = false;
    }

    var result = ' ';

    if (isQuarter && moduleAddress != null && moduleAddress.street) {
      if (address != null && address.building) {
        result += " \u2116" + address.building;
      }

      return result;
    }

    if (!isQuarter && address != null && address.building && !(moduleAddress != null && moduleAddress.quarter)) {
      result += " \u2116" + address.building;
    }

    if (address != null && address.streetNumber) {
      result += " \u2116" + address.streetNumber;
    }

    if (address != null && address.entrance) {
      result += address.entrance;
    }

    if (address != null && address.floor) {
      result += " " + labels.floorShortLabel + address.floor;
    }

    if (address != null && address.apartment) {
      result += " " + labels.apartmentShortLabel + address.apartment;
    }

    return result;
  };

  return /*#__PURE__*/_react["default"].createElement(Container, null, /*#__PURE__*/_react["default"].createElement(Box, null, /*#__PURE__*/_react["default"].createElement(Title, null, labels.personalInfo), /*#__PURE__*/_react["default"].createElement("p", null, address == null ? void 0 : address.firstName, " ", address == null ? void 0 : address.lastName), /*#__PURE__*/_react["default"].createElement("p", null, address == null ? void 0 : address.email), /*#__PURE__*/_react["default"].createElement(_Common.IconEdit, {
    onClick: onEditClick
  })), isPickupFromStore && /*#__PURE__*/_react["default"].createElement(Box, null, /*#__PURE__*/_react["default"].createElement(Title, null, /*#__PURE__*/_react["default"].createElement(_Common.IconStore, null), labels.store), /*#__PURE__*/_react["default"].createElement("p", null, selectedStore == null ? void 0 : selectedStore.name), /*#__PURE__*/_react["default"].createElement("p", null, selectedStore == null ? void 0 : (_selectedStore$addres = selectedStore.address) == null ? void 0 : _selectedStore$addres.additionalAddressInfo), /*#__PURE__*/_react["default"].createElement(_Common.IconEdit, {
    onClick: onEditClick
  })), isOffice && /*#__PURE__*/_react["default"].createElement(Box, null, /*#__PURE__*/_react["default"].createElement(Title, null, labels.shippingAddress), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(Cap, null, moduleAddress == null ? void 0 : (_moduleAddress$office = moduleAddress.office) == null ? void 0 : (_moduleAddress$office2 = _moduleAddress$office.nameEn) == null ? void 0 : _moduleAddress$office2.toLowerCase())), /*#__PURE__*/_react["default"].createElement("p", null, moduleAddress == null ? void 0 : (_moduleAddress$office3 = moduleAddress.office) == null ? void 0 : (_moduleAddress$office4 = _moduleAddress$office3.address) == null ? void 0 : _moduleAddress$office4.fullAddressString), /*#__PURE__*/_react["default"].createElement(_Common.IconEdit, {
    onClick: onEditClick
  })), isAddress && /*#__PURE__*/_react["default"].createElement(Box, null, /*#__PURE__*/_react["default"].createElement(Title, null, labels.shippingAddress), /*#__PURE__*/_react["default"].createElement("p", null, moduleAddress == null ? void 0 : moduleAddress.city.typeEn, ' ', /*#__PURE__*/_react["default"].createElement(Cap, null, moduleAddress == null ? void 0 : (_moduleAddress$city = moduleAddress.city) == null ? void 0 : (_moduleAddress$city$n = _moduleAddress$city.nameEn) == null ? void 0 : _moduleAddress$city$n.toLowerCase(), " ", address == null ? void 0 : address.postalCode)), Boolean(moduleAddress == null ? void 0 : moduleAddress.quarter) && /*#__PURE__*/_react["default"].createElement("p", null, moduleAddress == null ? void 0 : moduleAddress.quarter.typeEn, ' ', /*#__PURE__*/_react["default"].createElement(Cap, null, moduleAddress == null ? void 0 : (_moduleAddress$quarte = moduleAddress.quarter) == null ? void 0 : (_moduleAddress$quarte2 = _moduleAddress$quarte.nameEn) == null ? void 0 : _moduleAddress$quarte2.toLowerCase()), getInfo(true)), Boolean(moduleAddress == null ? void 0 : moduleAddress.street) && /*#__PURE__*/_react["default"].createElement("p", null, moduleAddress == null ? void 0 : moduleAddress.street.typeEn, ' ', /*#__PURE__*/_react["default"].createElement(Cap, null, moduleAddress == null ? void 0 : (_moduleAddress$street = moduleAddress.street) == null ? void 0 : (_moduleAddress$street2 = _moduleAddress$street.name) == null ? void 0 : _moduleAddress$street2.toLowerCase()), getInfo()), Boolean(address == null ? void 0 : address.additionalAddressInfo) && /*#__PURE__*/_react["default"].createElement("p", null, "* ", address == null ? void 0 : address.additionalAddressInfo), /*#__PURE__*/_react["default"].createElement(_Common.IconEdit, {
    onClick: onEditClick
  })), withInvoice && /*#__PURE__*/_react["default"].createElement(Box, null, /*#__PURE__*/_react["default"].createElement(Title, null, labels.invoiceDataLabel), /*#__PURE__*/_react["default"].createElement("p", null, invoice == null ? void 0 : (_invoice$company = invoice.company) == null ? void 0 : _invoice$company.companyPerson), /*#__PURE__*/_react["default"].createElement("p", null, invoice == null ? void 0 : (_invoice$company2 = invoice.company) == null ? void 0 : _invoice$company2.companyName), /*#__PURE__*/_react["default"].createElement("p", null, invoice == null ? void 0 : invoice.additionalAddressInfo), /*#__PURE__*/_react["default"].createElement("p", null, invoice == null ? void 0 : invoice.streetName), /*#__PURE__*/_react["default"].createElement("p", null, invoice == null ? void 0 : (_invoice$company3 = invoice.company) == null ? void 0 : _invoice$company3.companyId), /*#__PURE__*/_react["default"].createElement("p", null, invoice == null ? void 0 : (_invoice$company4 = invoice.company) == null ? void 0 : _invoice$company4.vatId), /*#__PURE__*/_react["default"].createElement(_Common.IconEdit, {
    onClick: onEditClick
  })));
};

exports.AddressPreview = AddressPreview;

var Container = _styledComponents["default"].div.attrs({
  className: 'mt-4 pt-4'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  border-top: 0.1rem solid ", ";\n"])), function (_ref) {
  var theme = _ref.theme;
  return theme.palette.primary;
});

var Cap = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  text-transform: capitalize;\n"])));

var Box = _styledComponents["default"].div.attrs({
  className: 'mb-3'
})(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  position: relative;\n\n  & > svg {\n    width: 2.4rem;\n    position: absolute;\n    top: 0;\n    right: 0;\n    cursor: pointer;\n  }\n\n  &:last-of-type {\n    margin-bottom: 0 !important;\n  }\n\n  & p {\n    display: -webkit-box;\n    -webkit-line-clamp: 1;\n    overflow: hidden;\n    -webkit-box-orient: vertical;\n    line-height: 2.3rem;\n  }\n"])));

var Title = (0, _styledComponents["default"])(_Common.Typography).attrs({
  as: 'h5',
  variant: 5,
  className: 'pb-2 d-flex align-items-center'
})(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  font-weight: bold;\n  line-height: 1.1;\n  text-transform: uppercase;\n\n  & > svg {\n    width: 2rem;\n    margin-right: 0.6rem;\n  }\n"])));
//# sourceMappingURL=index.js.map