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

var _templateObject, _templateObject2, _templateObject3, _templateObject4;

import React, { useMemo } from 'react';
import styled from 'styled-components';
import { Typography, IconEdit, IconStore } from '../../../../../Common';
import { useCheckoutFormBillingState, useCheckoutPickupFromStore, useCheckoutShippingModule, useLocalLabels, useCheckoutFormShippingState, useCheckoutFormStep, CheckoutFormStepsEnum, useCheckoutFormOrder, ShippingModulesTypeEnum } from '@sentecacommerce-theme/lib';
export var 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 {
    data: address
  } = useCheckoutFormShippingState();
  var {
    data: invoice,
    isWithBillingAddress: withInvoice
  } = useCheckoutFormBillingState();
  var {
    updateStep
  } = useCheckoutFormStep();
  var labels = useLocalLabels();

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

  var orderQuery = useCheckoutFormOrder();
  var mod = useCheckoutShippingModule(orderQuery);
  var isPickupFromStore = (mod == null ? void 0 : mod.moduleKey) === 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 {
    availableStores
  } = useCheckoutPickupFromStore();
  var selectedStore = useMemo(() => {
    if (!isPickupFromStore) return;
    return availableStores == null ? void 0 : availableStores.find(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.createElement(Container, null, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Title, null, labels.personalInfo), /*#__PURE__*/React.createElement("p", null, address == null ? void 0 : address.firstName, " ", address == null ? void 0 : address.lastName), /*#__PURE__*/React.createElement("p", null, address == null ? void 0 : address.email), /*#__PURE__*/React.createElement(IconEdit, {
    onClick: onEditClick
  })), isPickupFromStore && /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Title, null, /*#__PURE__*/React.createElement(IconStore, null), labels.store), /*#__PURE__*/React.createElement("p", null, 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), /*#__PURE__*/React.createElement(IconEdit, {
    onClick: onEditClick
  })), isOffice && /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Title, null, labels.shippingAddress), /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.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.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.createElement(IconEdit, {
    onClick: onEditClick
  })), isAddress && /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Title, null, labels.shippingAddress), /*#__PURE__*/React.createElement("p", null, moduleAddress == null ? void 0 : moduleAddress.city.typeEn, ' ', /*#__PURE__*/React.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.createElement("p", null, moduleAddress == null ? void 0 : moduleAddress.quarter.typeEn, ' ', /*#__PURE__*/React.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.createElement("p", null, moduleAddress == null ? void 0 : moduleAddress.street.typeEn, ' ', /*#__PURE__*/React.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.createElement("p", null, "* ", address == null ? void 0 : address.additionalAddressInfo), /*#__PURE__*/React.createElement(IconEdit, {
    onClick: onEditClick
  })), withInvoice && /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Title, null, labels.invoiceDataLabel), /*#__PURE__*/React.createElement("p", null, invoice == null ? void 0 : (_invoice$company = invoice.company) == null ? void 0 : _invoice$company.companyPerson), /*#__PURE__*/React.createElement("p", null, invoice == null ? void 0 : (_invoice$company2 = invoice.company) == null ? void 0 : _invoice$company2.companyName), /*#__PURE__*/React.createElement("p", null, invoice == null ? void 0 : invoice.additionalAddressInfo), /*#__PURE__*/React.createElement("p", null, invoice == null ? void 0 : invoice.streetName), /*#__PURE__*/React.createElement("p", null, invoice == null ? void 0 : (_invoice$company3 = invoice.company) == null ? void 0 : _invoice$company3.companyId), /*#__PURE__*/React.createElement("p", null, invoice == null ? void 0 : (_invoice$company4 = invoice.company) == null ? void 0 : _invoice$company4.vatId), /*#__PURE__*/React.createElement(IconEdit, {
    onClick: onEditClick
  })));
};
var Container = styled.div.attrs({
  className: 'mt-4 pt-4'
})(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n  border-top: 0.1rem solid ", ";\n"])), (_ref) => {
  var {
    theme
  } = _ref;
  return theme.palette.primary;
});
var Cap = styled.span(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n  text-transform: capitalize;\n"])));
var Box = styled.div.attrs({
  className: 'mb-3'
})(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\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 = styled(Typography).attrs({
  as: 'h5',
  variant: 5,
  className: 'pb-2 d-flex align-items-center'
})(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\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