import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/taggedTemplateLiteralLoose";

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

import React, { useMemo } from 'react';
import { useCheckoutPickupFromStore, useGlobalLabels, ShippingModulesTypeEnum } from '@sentecacommerce-theme/lib';
import { IconStore } from '../Icons';
import styled, { css } from 'styled-components';
export var 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,
    setStatus,
    handleRemove,
    isSelectable,
    onSelect,
    isSelected
  } = _ref;
  var {
    isDefaultShippingAddress,
    isDefaultBillingAddress,
    firstName,
    lastName
  } = data;
  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) === ShippingModulesTypeEnum.PickUpFromStore; // this should come from the config

  var isOffice = !isPickupFromStore && Boolean(office);
  var isAddress = !isPickupFromStore && !isOffice;
  var {
    buttons,
    infoMessages,
    commonMessages
  } = useGlobalLabels(); // TODO: this should not be in the checkout context

  var {
    availableStores
  } = useCheckoutPickupFromStore();
  var selectedStore = useMemo(() => {
    if (!isPickupFromStore) return;
    return availableStores == null ? void 0 : availableStores.find(store => 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.createElement(ProfileElementContainer, {
    onClick: onSelect ? () => onSelect(data) : undefined,
    isSelected: isSelected,
    isSelectable: isSelectable
  }, /*#__PURE__*/React.createElement(ProfileElementWrapper, null, /*#__PURE__*/React.createElement(ProfileElementContentContainer, null, /*#__PURE__*/React.createElement(ProfileContainer, null, isSelectable && /*#__PURE__*/React.createElement(Check, {
    isChecked: isSelected
  }), firstName, " ", lastName), /*#__PURE__*/React.createElement(DeliveryInformation, null, isPickupFromStore && /*#__PURE__*/React.createElement(StoreContainer, null, /*#__PURE__*/React.createElement(Label, null, /*#__PURE__*/React.createElement(IconStore, null), commonMessages.store, " ", selectedStore == null ? void 0 : selectedStore.name), /*#__PURE__*/React.createElement("p", null, selectedStore == null ? void 0 : (_selectedStore$addres = selectedStore.address) == null ? void 0 : _selectedStore$addres.additionalAddressInfo)), isOffice && /*#__PURE__*/React.createElement(OfficeContainer, null, /*#__PURE__*/React.createElement(Cap, null, office == null ? void 0 : (_office$name = office.name) == null ? void 0 : _office$name.toLowerCase()), /*#__PURE__*/React.createElement("p", null, office == null ? void 0 : (_office$address = office.address) == null ? void 0 : _office$address.fullAddressString)), isAddress && /*#__PURE__*/React.createElement(AddressContainer, null, /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.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.createElement("p", null, /*#__PURE__*/React.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.createElement("p", null, /*#__PURE__*/React.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.createElement("p", null, "* ", data == null ? void 0 : data.additionalAddressInfo))))), isDefaultShippingAddress && /*#__PURE__*/React.createElement(DefaultAddressLabel, null, commonMessages.defaultShippingAddr), isDefaultBillingAddress && /*#__PURE__*/React.createElement(DefaultAddressLabel, null, commonMessages.defaultBillingAddr));
};
var DeliveryInformation = styled.div.attrs({
  className: 'd-flex'
})(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n  padding-left: 2rem;\n  width: 100%;\n  flex-wrap: wrap;\n  align-content: center;\n"])));
var AddressContainer = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose([""])));
var StoreContainer = styled.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose([""])));
var OfficeContainer = styled.div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose([""])));
var ProfileContainer = styled.p.attrs({
  className: 'd-flex col-sm-5 col-md-3 col-lg-3'
})(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\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 = styled.span(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["\n  text-transform: capitalize;\n"])));
var Check = styled.span.attrs({
  className: 'd-flex align-items-center justify-content-center'
})(_templateObject7 || (_templateObject7 = _taggedTemplateLiteralLoose(["\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"])), (_ref2) => {
  var {
    theme
  } = _ref2;
  return theme.palette.grey;
}, props => props.isChecked ? css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteralLoose(["\n          &:after {\n            content: '';\n            display: block;\n            width: 0.6rem;\n            height: 0.6rem;\n            background: ", ";\n            border-radius: 50%;\n          }\n        "])), (_ref3) => {
  var {
    theme
  } = _ref3;
  return theme.palette.primary;
}) : '');
var ProfileElementContainer = styled.div.attrs({
  className: 'mb-2'
})(_templateObject9 || (_templateObject9 = _taggedTemplateLiteralLoose(["\n  border: 1px solid ", ";\n  border-radius: 4px;\n  ", "\n  ", "\n"])), (_ref4) => {
  var {
    theme
  } = _ref4;
  return theme.palette.light;
}, props => props.isSelectable ? css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteralLoose(["\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        "])), (_ref5) => {
  var {
    theme
  } = _ref5;
  return theme.palette.primary;
}) : '', props => props.isSelected ? css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteralLoose(["\n          opacity: 1 !important;\n          border: 1px solid ", ";\n        "])), (_ref6) => {
  var {
    theme
  } = _ref6;
  return theme.palette.primary;
}) : '');
var ProfileElementWrapper = styled.div.attrs({
  className: 'pb-3 pt-3'
})(_templateObject12 || (_templateObject12 = _taggedTemplateLiteralLoose(["\n  margin-left: -0.8rem;\n  margin-right: -0.8rem;\n  width: 100%;\n"])));
var ProfileElementContentContainer = styled.div.attrs({
  className: 'pl-2 pr-2 d-flex flex-column flex-lg-row align-center'
})(_templateObject13 || (_templateObject13 = _taggedTemplateLiteralLoose(["\n  line-height: 1.75;\n  display: inline-block;\n  color: ", ";\n"])), (_ref7) => {
  var {
    theme
  } = _ref7;
  return theme.palette.primary;
});
var Label = styled.span.attrs({
  className: 'd-inline-flex align-items-center pr-1'
})(_templateObject14 || (_templateObject14 = _taggedTemplateLiteralLoose(["\n  color: ", ";\n  font-weight: 700;\n  & svg {\n    width: 2rem;\n    margin-right: 0.4rem;\n  }\n"])), (_ref8) => {
  var {
    theme
  } = _ref8;
  return theme.palette.primary;
});
var DefaultAddressLabel = styled.span.attrs({
  className: 'd-flex '
})(_templateObject15 || (_templateObject15 = _taggedTemplateLiteralLoose(["\n  font-weight: 700;\n  margin-left: 1.8rem;\n"])));
//# sourceMappingURL=index.js.map