"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 _lib = require("@sentecacommerce-theme/lib");

var _Icons = require("../Icons");

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

var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15;

var AddressPreview = function AddressPreview(_ref) {
  var _data$moduleData, _mod$moduleData, _mod$moduleData2, _mod$moduleData2$addr, _selectedStore$addres, _office$name, _office$address, _moduleAddress$city, _moduleAddress$city2, _moduleAddress$city2$, _moduleAddress$quarte, _moduleAddress$quarte2, _moduleAddress$street;

  var data = _ref.data,
      setStatus = _ref.setStatus,
      handleRemove = _ref.handleRemove,
      isSelectable = _ref.isSelectable,
      onSelect = _ref.onSelect,
      isSelected = _ref.isSelected;
  var isDefaultShippingAddress = data.isDefaultShippingAddress,
      isDefaultBillingAddress = data.isDefaultBillingAddress,
      firstName = data.firstName,
      lastName = data.lastName;
  var mod = (_data$moduleData = data.moduleData) == null ? void 0 : _data$moduleData[0];
  var moduleAddress = mod == null ? void 0 : (_mod$moduleData = mod.moduleData) == null ? void 0 : _mod$moduleData.address;
  var office = mod == null ? void 0 : (_mod$moduleData2 = mod.moduleData) == null ? void 0 : (_mod$moduleData2$addr = _mod$moduleData2.address) == null ? void 0 : _mod$moduleData2$addr.office;
  var isPickupFromStore = (mod == null ? void 0 : mod.moduleKey) === _lib.ShippingModulesTypeEnum.PickUpFromStore; // this should come from the config

  var isOffice = !isPickupFromStore && Boolean(office);
  var isAddress = !isPickupFromStore && !isOffice;

  var _useGlobalLabels = (0, _lib.useGlobalLabels)(),
      buttons = _useGlobalLabels.buttons,
      infoMessages = _useGlobalLabels.infoMessages,
      commonMessages = _useGlobalLabels.commonMessages; // TODO: this should not be in the checkout context


  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) {
      return store._id === (mod == null ? void 0 : mod.moduleData.stockLocation);
    });
  }, [isPickupFromStore, availableStores]);

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

    var result = ' ';

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

      return result;
    }

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

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

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

    if (data != null && data.floor) {
      result += "" + data.floor;
    }

    if (data != null && data.apartment) {
      result += "" + data.apartment;
    }

    return result;
  };

  return /*#__PURE__*/_react["default"].createElement(ProfileElementContainer, {
    onClick: onSelect ? function () {
      return onSelect(data);
    } : undefined,
    isSelected: isSelected,
    isSelectable: isSelectable
  }, /*#__PURE__*/_react["default"].createElement(ProfileElementWrapper, null, /*#__PURE__*/_react["default"].createElement(ProfileElementContentContainer, null, /*#__PURE__*/_react["default"].createElement(ProfileContainer, null, isSelectable && /*#__PURE__*/_react["default"].createElement(Check, {
    isChecked: isSelected
  }), firstName, " ", lastName), /*#__PURE__*/_react["default"].createElement(DeliveryInformation, null, isPickupFromStore && /*#__PURE__*/_react["default"].createElement(StoreContainer, null, /*#__PURE__*/_react["default"].createElement(Label, null, /*#__PURE__*/_react["default"].createElement(_Icons.IconStore, null), commonMessages.store, " ", 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)), isOffice && /*#__PURE__*/_react["default"].createElement(OfficeContainer, null, /*#__PURE__*/_react["default"].createElement(Cap, null, office == null ? void 0 : (_office$name = office.name) == null ? void 0 : _office$name.toLowerCase()), /*#__PURE__*/_react["default"].createElement("p", null, office == null ? void 0 : (_office$address = office.address) == null ? void 0 : _office$address.fullAddressString)), isAddress && /*#__PURE__*/_react["default"].createElement(AddressContainer, null, /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(Cap, null, (moduleAddress == null ? void 0 : (_moduleAddress$city = moduleAddress.city) == null ? void 0 : _moduleAddress$city.name) && (moduleAddress == null ? void 0 : (_moduleAddress$city2 = moduleAddress.city) == null ? void 0 : (_moduleAddress$city2$ = _moduleAddress$city2.name) == null ? void 0 : _moduleAddress$city2$.toLowerCase()) + ' ', data == null ? void 0 : data.postalCode)), Boolean(moduleAddress == null ? void 0 : moduleAddress.quarter) && /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(Cap, null, moduleAddress == null ? void 0 : (_moduleAddress$quarte = moduleAddress.quarter) == null ? void 0 : (_moduleAddress$quarte2 = _moduleAddress$quarte.name) == null ? void 0 : _moduleAddress$quarte2.toLowerCase()), getInfo(true)), Boolean(moduleAddress == null ? void 0 : moduleAddress.street) && /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(Cap, null, moduleAddress == null ? void 0 : (_moduleAddress$street = moduleAddress.street) == null ? void 0 : _moduleAddress$street.name.toLowerCase()), getInfo()), Boolean(data == null ? void 0 : data.additionalAddressInfo) && /*#__PURE__*/_react["default"].createElement("p", null, "* ", data == null ? void 0 : data.additionalAddressInfo))))), isDefaultShippingAddress && /*#__PURE__*/_react["default"].createElement(DefaultAddressLabel, null, commonMessages.defaultShippingAddr), isDefaultBillingAddress && /*#__PURE__*/_react["default"].createElement(DefaultAddressLabel, null, commonMessages.defaultBillingAddr));
};

exports.AddressPreview = AddressPreview;

var DeliveryInformation = _styledComponents["default"].div.attrs({
  className: 'd-flex'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  padding-left: 2rem;\n  width: 100%;\n  flex-wrap: wrap;\n  align-content: center;\n"])));

var AddressContainer = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var StoreContainer = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var OfficeContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var ProfileContainer = _styledComponents["default"].p.attrs({
  className: 'd-flex col-sm-5 col-md-3 col-lg-3'
})(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  white-space: nowrap;\n  flex-wrap: wrap;\n  align-content: center;\n  font-weight: 700;\n  margin-left: 2rem;\n  margin-right: 2rem;\n"])));

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

var Check = _styledComponents["default"].span.attrs({
  className: 'd-flex align-items-center justify-content-center'
})(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  width: 1.6rem;\n  height: 1.6rem;\n  border: 0.2rem solid ", ";\n  border-radius: 50%;\n  margin-right: 1rem;\n  margin-left: -2.8rem;\n  margin-top: 0.4rem;\n  ", ";\n"])), function (_ref2) {
  var theme = _ref2.theme;
  return theme.palette.grey;
}, function (props) {
  return props.isChecked ? (0, _styledComponents.css)(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteralLoose2["default"])(["\n          &:after {\n            content: '';\n            display: block;\n            width: 0.6rem;\n            height: 0.6rem;\n            background: ", ";\n            border-radius: 50%;\n          }\n        "])), function (_ref3) {
    var theme = _ref3.theme;
    return theme.palette.primary;
  }) : '';
});

var ProfileElementContainer = _styledComponents["default"].div.attrs({
  className: 'mb-2'
})(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  border: 1px solid ", ";\n  border-radius: 4px;\n  ", "\n  ", "\n"])), function (_ref4) {
  var theme = _ref4.theme;
  return theme.palette.light;
}, function (props) {
  return props.isSelectable ? (0, _styledComponents.css)(_templateObject10 || (_templateObject10 = (0, _taggedTemplateLiteralLoose2["default"])(["\n          cursor: pointer;\n          padding: 1rem 1rem 1rem 3.2rem;\n          position: relative;\n          @media (hover: hover) {\n            &:hover {\n              border: 1px solid ", ";\n            }\n          }\n        "])), function (_ref5) {
    var theme = _ref5.theme;
    return theme.palette.primary;
  }) : '';
}, function (props) {
  return props.isSelected ? (0, _styledComponents.css)(_templateObject11 || (_templateObject11 = (0, _taggedTemplateLiteralLoose2["default"])(["\n          opacity: 1 !important;\n          border: 1px solid ", ";\n        "])), function (_ref6) {
    var theme = _ref6.theme;
    return theme.palette.primary;
  }) : '';
});

var ProfileElementWrapper = _styledComponents["default"].div.attrs({
  className: 'pb-3 pt-3'
})(_templateObject12 || (_templateObject12 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  margin-left: -0.8rem;\n  margin-right: -0.8rem;\n  width: 100%;\n"])));

var ProfileElementContentContainer = _styledComponents["default"].div.attrs({
  className: 'pl-2 pr-2 d-flex flex-column flex-lg-row align-center'
})(_templateObject13 || (_templateObject13 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  line-height: 1.75;\n  display: inline-block;\n  color: ", ";\n"])), function (_ref7) {
  var theme = _ref7.theme;
  return theme.palette.primary;
});

var Label = _styledComponents["default"].span.attrs({
  className: 'd-inline-flex align-items-center pr-1'
})(_templateObject14 || (_templateObject14 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  color: ", ";\n  font-weight: 700;\n  & svg {\n    width: 2rem;\n    margin-right: 0.4rem;\n  }\n"])), function (_ref8) {
  var theme = _ref8.theme;
  return theme.palette.primary;
});

var DefaultAddressLabel = _styledComponents["default"].span.attrs({
  className: 'd-flex '
})(_templateObject15 || (_templateObject15 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  font-weight: 700;\n  margin-left: 1.8rem;\n"])));
//# sourceMappingURL=index.js.map