"use strict";

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

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

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

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

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

var _router = require("next/router");

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

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

var _Components = require("./Components");

var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19, _templateObject20, _templateObject21, _templateObject22, _templateObject23, _templateObject24;

var iconsMap = {
  Speedy: /*#__PURE__*/_react["default"].createElement(_Common.IconSpeedy, {
    style: {
      width: '6.8rem',
      height: '3.4rem'
    }
  }),
  Econt: /*#__PURE__*/_react["default"].createElement(_Common.IconEcont, {
    style: {
      width: '8.8rem',
      height: '5rem',
      marginTop: '-1rem',
      marginBottom: '-1.6rem',
      marginRight: '-1.6rem'
    }
  }),
  Evropat: /*#__PURE__*/_react["default"].createElement("img", {
    src: "https://production.hippoland-contents.com/platform/media/evroput-logo-13845.jpg",
    alt: "\u0415\u0432\u0440\u043E\u043F\u044A\u0442",
    style: {
      width: '6.8rem',
      height: 'auto'
    }
  })
};

var Order = function Order(_ref) {
  var _router$query, _router$query2, _data$shippings;

  var contactPhone = _ref.phone,
      labels = _ref.labels,
      helpMenu = _ref.helpMenu,
      thankYouMessageDescription = _ref.thankYouMessageDescription,
      thankYouMessageTitle = _ref.thankYouMessageTitle;
  var router = (0, _router.useRouter)();
  (0, _lib.useUpdateStrings)('order', labels);
  var orderId = (_router$query = router.query) == null ? void 0 : _router$query.orderId;
  var isSuccess = Boolean((_router$query2 = router.query) == null ? void 0 : _router$query2.success);

  var _myOrdersApi$useGetBy = _lib.myOrdersApi.useGetById(orderId),
      data = _myOrdersApi$useGetBy.data;

  var _useOrder = (0, _lib.useOrder)({
    data: data
  }),
      orderRefNumber = _useOrder.orderRefNumber,
      status = _useOrder.status,
      lineItems = _useOrder.lineItems,
      createdAt = _useOrder.createdAt,
      discountCodes = _useOrder.discountCodes;

  var price = (0, _lib.useOrderPrice)(data);
  var shippingPriceRaw = (0, _lib.useOrderShippingPrice)(data == null ? void 0 : (_data$shippings = data.shippings) == null ? void 0 : _data$shippings[0]);

  var _usePrice = (0, _lib.usePrice)({
    price: shippingPriceRaw.discountedPrice || shippingPriceRaw.originalPrice
  }),
      shippingPrice = _usePrice.price;

  var _usePrice2 = (0, _lib.usePrice)({
    price: price.discountedSubtotal || price.totalWithoutDiscount
  }),
      subtotal = _usePrice2.price;

  var _usePrice3 = (0, _lib.usePrice)({
    price: price.taxedPrice
  }),
      totalPrice = _usePrice3.price;

  var _usePrice4 = (0, _lib.usePrice)({
    price: price.discountCodesSum
  }),
      discountCodesSum = _usePrice4.price;

  var _useShippingAddress = (0, _lib.useShippingAddress)(data == null ? void 0 : data.shippingAddress),
      customer = _useShippingAddress.customer,
      city = _useShippingAddress.city,
      street = _useShippingAddress.street,
      quarter = _useShippingAddress.quarter,
      office = _useShippingAddress.office,
      streetNumber = _useShippingAddress.streetNumber,
      building = _useShippingAddress.building,
      postalCode = _useShippingAddress.postalCode,
      courier = _useShippingAddress.courier,
      entrance = _useShippingAddress.entrance,
      additionalAddressInfo = _useShippingAddress.additionalAddressInfo,
      floor = _useShippingAddress.floor,
      apartment = _useShippingAddress.apartment;

  var billingAddress = (0, _lib.useBillingAddress)(data == null ? void 0 : data.billingAddress);
  var courierIcon = iconsMap[courier];

  var getAddress = function getAddress() {
    if (!(street != null && street.toLowerCase())) return;

    if (entrance && (streetNumber || building)) {
      return "" + entrance + (building || streetNumber) + " " + (street == null ? void 0 : street.toLowerCase()) + " Street";
    }

    if (streetNumber || building) {
      return (building || streetNumber) + " " + (street == null ? void 0 : street.toLowerCase()) + " Street";
    }

    return street == null ? void 0 : street.toLowerCase();
  };

  var hasAddress = Boolean(office ? office : getAddress());

  var getQuarterInfo = function getQuarterInfo() {
    if (hasAddress) return '';
    var str = '';
    if (building || streetNumber) str += "\u2116" + (building || streetNumber);
    if (entrance) str += " " + entrance;
    return str;
  };

  var dateObject = new Date(createdAt || 0);
  var month = dateObject == null ? void 0 : dateObject.toLocaleString('default', {
    month: 'short'
  });
  return /*#__PURE__*/_react["default"].createElement(Container, null, /*#__PURE__*/_react["default"].createElement(Title, {
    isHint: true,
    className: "mb-4"
  }, labels.ordered, " ", dateObject == null ? void 0 : dateObject.getDate(), " ", month, ' ', dateObject == null ? void 0 : dateObject.getFullYear(), " \u2014 ", labels.order, " #", orderRefNumber), isSuccess && /*#__PURE__*/_react["default"].createElement(ThankyouContainer, null, /*#__PURE__*/_react["default"].createElement(Logo, null, /*#__PURE__*/_react["default"].createElement(_Common.IconDistrictLogoNew, null)), /*#__PURE__*/_react["default"].createElement(ThankyouTitle, null, labels.thanks, " ", customer == null ? void 0 : customer.firstName, " ", customer == null ? void 0 : customer.lastName, "!", ' ', thankYouMessageTitle), /*#__PURE__*/_react["default"].createElement(ThankyouDescription, null, thankYouMessageDescription)), /*#__PURE__*/_react["default"].createElement(Flex, null, /*#__PURE__*/_react["default"].createElement(ListContainer, null, status === 'Cancelled' && /*#__PURE__*/_react["default"].createElement(Notice, null, /*#__PURE__*/_react["default"].createElement("span", null, labels.canceledOrder)), status === 'Complete' && /*#__PURE__*/_react["default"].createElement(Notice, null, /*#__PURE__*/_react["default"].createElement("span", null, labels.completedOrder)), /*#__PURE__*/_react["default"].createElement(InfoBox, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "pt-4"
  }), /*#__PURE__*/_react["default"].createElement(List, null, lineItems == null ? void 0 : lineItems.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_Components.ProductPreview, {
      item: item,
      key: "Product__" + item._id
    });
  })))), /*#__PURE__*/_react["default"].createElement(OrderInfo, null, /*#__PURE__*/_react["default"].createElement(InfoBox, null, /*#__PURE__*/_react["default"].createElement(Title, {
    className: "pb-1"
  }, labels.address), /*#__PURE__*/_react["default"].createElement(BoxContent, null, /*#__PURE__*/_react["default"].createElement(Info, null, customer == null ? void 0 : customer.firstName, " ", customer == null ? void 0 : customer.lastName), /*#__PURE__*/_react["default"].createElement(Info, null, customer == null ? void 0 : customer.email), /*#__PURE__*/_react["default"].createElement(Info, null, customer == null ? void 0 : customer.phone), hasAddress && /*#__PURE__*/_react["default"].createElement(Info, null, /*#__PURE__*/_react["default"].createElement(Cap, null, office && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, labels.officeAddress, " \xA0", /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      textTransform: 'capitalize'
    }
  }, office == null ? void 0 : office.name.toLowerCase(), ' ', office && quarter && ', ')), Boolean(quarter) && /*#__PURE__*/_react["default"].createElement(Cap, null, quarter == null ? void 0 : quarter.name, " ", getQuarterInfo()))), street && /*#__PURE__*/_react["default"].createElement(Info, null, street, " ", streetNumber, building && ", " + building, floor && ", " + labels.floor + " " + floor, apartment && ", " + labels.apartment + " " + apartment), /*#__PURE__*/_react["default"].createElement(Info, null), /*#__PURE__*/_react["default"].createElement(Info, null, postalCode, " ", /*#__PURE__*/_react["default"].createElement(Cap, null, city == null ? void 0 : city.name)), Boolean(additionalAddressInfo) && /*#__PURE__*/_react["default"].createElement(Info, null, "* ", additionalAddressInfo), /*#__PURE__*/_react["default"].createElement(CourierIconContainer, null, courierIcon))), Boolean(billingAddress) && /*#__PURE__*/_react["default"].createElement(InfoBox, null, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(Title, {
    className: "mb-4"
  }, labels.invoice), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.companyPerson)), /*#__PURE__*/_react["default"].createElement(Info, null, billingAddress == null ? void 0 : billingAddress.companyPerson)), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.companyName)), /*#__PURE__*/_react["default"].createElement(Info, null, billingAddress == null ? void 0 : billingAddress.companyName)), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.companyCity)), /*#__PURE__*/_react["default"].createElement(Info, null, billingAddress == null ? void 0 : billingAddress.companyCity)), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.companyZip)), /*#__PURE__*/_react["default"].createElement(Info, null, billingAddress == null ? void 0 : billingAddress.companyZip)), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.companyStreet)), /*#__PURE__*/_react["default"].createElement(Info, null, billingAddress == null ? void 0 : billingAddress.companyStreet)), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.companyStreetNumber)), /*#__PURE__*/_react["default"].createElement(Info, null, billingAddress == null ? void 0 : billingAddress.companyStreetNumber)), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.companyId)), /*#__PURE__*/_react["default"].createElement(Info, null, billingAddress == null ? void 0 : billingAddress.companyId)), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(CompanyLabel, null, labels.vatId)), /*#__PURE__*/_react["default"].createElement(Info, null, "#", billingAddress == null ? void 0 : billingAddress.vatId)))), /*#__PURE__*/_react["default"].createElement(InfoBox, null, /*#__PURE__*/_react["default"].createElement(MaxWidth, null, /*#__PURE__*/_react["default"].createElement(Title, {
    className: "mb-4"
  }, labels.orderSummary), /*#__PURE__*/_react["default"].createElement(SummaryContainer, null, /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(SummaryLabel, null, labels.subtotal)), /*#__PURE__*/_react["default"].createElement("div", null, Boolean(subtotal) && /*#__PURE__*/_react["default"].createElement(_Common.Price, {
    currency: subtotal.currency,
    size: "tiny",
    price: subtotal.value
  }))), Boolean(discountCodes == null ? void 0 : discountCodes.length) && /*#__PURE__*/_react["default"].createElement(MultipleVouchers, null, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      display: 'table-cell',
      paddingTop: '1rem'
    }
  }, labels.usedVouchers, /*#__PURE__*/_react["default"].createElement("div", {
    className: "d-flex flex-wrap "
  }, discountCodes == null ? void 0 : discountCodes.map(function (code, i) {
    return /*#__PURE__*/_react["default"].createElement(Voucher, {
      key: "Voucher-" + code + "-" + i
    }, code, (discountCodes == null ? void 0 : discountCodes.length) - 1 !== i && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, ", \xA0"));
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      display: 'table-cell',
      paddingTop: '1rem'
    }
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "d-flex justify-content-end ",
    style: {
      minWidth: '7rem'
    }
  }, "-", discountCodesSum.displayValue))), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isHint: true
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(SummaryLabel, null, labels.delivery)), /*#__PURE__*/_react["default"].createElement("div", null, Boolean(shippingPrice.value) && /*#__PURE__*/_react["default"].createElement(_Common.Price, {
    currency: shippingPrice.currency,
    size: "tiny",
    price: shippingPrice.value
  }))), /*#__PURE__*/_react["default"].createElement(SummaryBox, {
    isTotal: true
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(SummaryLabel, null, labels.total)), /*#__PURE__*/_react["default"].createElement("div", null, totalPrice && /*#__PURE__*/_react["default"].createElement(_Common.Price, {
    currency: totalPrice.currency,
    size: "tiny",
    price: totalPrice.value
  })))))), /*#__PURE__*/_react["default"].createElement(InfoBox, null, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(Title, {
    big: true,
    className: "pb-3"
  }, helpMenu.title), helpMenu.items.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(Info, {
      key: "Item__" + item.url + "-" + item.label,
      className: "mb-1"
    }, /*#__PURE__*/_react["default"].createElement("a", {
      href: item.url
    }, item.label));
  }))), /*#__PURE__*/_react["default"].createElement(InfoBox, null, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(Title, {
    className: "pb-3"
  }, /*#__PURE__*/_react["default"].createElement(ContactUs, {
    href: "tel:" + contactPhone
  }, /*#__PURE__*/_react["default"].createElement(_Common.IconPhone, null), labels.contactUs)))))));
};

exports.Order = Order;

var OrderInfo = _styledComponents["default"].div.attrs({
  className: 'col-12 col-md-6 col-lg-4'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  & a:hover {\n    opacity: 0.6;\n  }\n"])));

var Logo = _styledComponents["default"].div.attrs({
  className: 'mb-3'
})(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var ThankyouContainer = _styledComponents["default"].div.attrs({
  className: 'd-flex flex-column align-items-center justify-content-center mx-auto'
})(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  text-align: center;\n\n  @media (min-width: ", ") {\n    max-width: 44rem;\n  }\n"])), function (_ref2) {
  var theme = _ref2.theme;
  return theme.breakpoints.md.min;
});

var ThankyouTitle = _styledComponents["default"].div.attrs({
  className: ''
})(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  font-weight: bold;\n  text-transform: uppercase;\n  letter-spacing: -0.05rem;\n"])));

var ThankyouDescription = (0, _styledComponents["default"])(_Common.Typography).attrs({
  variant: 6,
  color: 'hint',
  className: 'mt-2 mb-4'
})(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var ListContainer = _styledComponents["default"].div.attrs({
  className: 'col-12 col-md-6 col-lg-8'
})(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var List = (0, _styledComponents["default"])(_Common.Typography).attrs({
  className: 'row gy-4 gx-0',
  as: 'ul',
  variant: 6
})(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  line-height: 1.3;\n  list-style: none;\n  width: 100%;\n"])));

var Flex = _styledComponents["default"].div.attrs({
  className: 'row gx-5 pt-4 align-items-start'
})(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var Container = (0, _styledComponents["default"])(_Common.Typography).attrs({
  as: 'div',
  variant: 4,
  className: 'container pt-5'
})(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  max-width: min(133.4rem, 100%);\n  overflow: hidden;\n"])));

var ContactUs = _styledComponents["default"].a.attrs({
  className: 'd-flex align-items-center'
})(_templateObject10 || (_templateObject10 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  & svg {\n    width: 1rem;\n    margin-right: 1rem;\n  }\n"])));

var Notice = _styledComponents["default"].p.attrs({
  className: 'mb-4 py-3 px-4'
})(_templateObject11 || (_templateObject11 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  color: ", ";\n  background: ", ";\n"])), function (_ref3) {
  var theme = _ref3.theme;
  return theme.palette.hint;
}, function (_ref4) {
  var theme = _ref4.theme;
  return theme.palette.disabled;
});

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

var InfoBox = _styledComponents["default"].div.attrs({
  className: 'mb-3 pt-4 d-flex justify-content-between'
})(_templateObject13 || (_templateObject13 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  border-top: 0.1rem solid ", ";\n\n  position: relative;\n"])), function (_ref5) {
  var theme = _ref5.theme;
  return theme.palette.light;
});

var BoxContent = (0, _styledComponents["default"])(_Common.Typography).attrs({
  as: 'div',
  variant: 6,
  color: 'hint'
})(_templateObject14 || (_templateObject14 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  text-align: right;\n"])));

var Info = _styledComponents["default"].p(_templateObject15 || (_templateObject15 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  line-height: 1.5;\n"])));

var CourierIconContainer = _styledComponents["default"].div(_templateObject16 || (_templateObject16 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  top: 0.5rem;\n  right: 1rem;\n"])));

var SummaryContainer = _styledComponents["default"].div(_templateObject17 || (_templateObject17 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: table;\n  width: 100%;\n"])));

var SummaryBox = _styledComponents["default"].div(_templateObject18 || (_templateObject18 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: table-row;\n\n  ", ";\n\n  & p,\n  span {\n    color: ", " !important;\n  }\n\n  & > div {\n    display: table-cell;\n    padding-top: 1rem;\n\n    & > div {\n      justify-content: flex-end;\n    }\n  }\n\n  & span {\n    font-size: 1.6rem;\n  }\n\n  &:first-of-type {\n    & > div {\n      padding-top: 0;\n    }\n  }\n"])), function (props) {
  return props.isTotal && "\n    font-size: 1.7rem;\n    font-weight: 700;\n  ";
}, function (props) {
  return props.isHint ? props.theme.palette.hint : props.theme.palette.primary;
});

var SummaryLabel = (0, _styledComponents["default"])(_Common.Typography).attrs({
  as: 'p',
  variant: 5,
  className: 'd-block mr-3'
})(_templateObject19 || (_templateObject19 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  min-width: 9rem;\n"])));
var CompanyLabel = (0, _styledComponents["default"])(_Common.Typography).attrs({
  as: 'p',
  variant: 5,
  className: 'd-block mr-5'
})(_templateObject20 || (_templateObject20 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  min-width: 9rem;\n"])));
var Title = (0, _styledComponents["default"])(_Common.Typography).attrs(function (props) {
  return {
    as: props.big ? 'h3' : 'h4',
    variant: props.big ? 4 : 5,
    color: props.isHint ? 'hint' : 'primary'
  };
})(_templateObject21 || (_templateObject21 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  line-height: 1;\n"])));

var MultipleVouchers = _styledComponents["default"].div.attrs({
  className: 'pt-3'
})(_templateObject22 || (_templateObject22 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: table-row;\n\n  color: ", ";\n  font-size: 1.6rem;\n"])), function (_ref6) {
  var theme = _ref6.theme;
  return theme.palette.hint;
});

var Voucher = _styledComponents["default"].span.attrs({
  className: 'd-flex mt-1'
})(_templateObject23 || (_templateObject23 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  font-size: 1.5rem;\n"])));

var MaxWidth = _styledComponents["default"].div(_templateObject24 || (_templateObject24 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  width: 100%;\n"])));
//# sourceMappingURL=order.component.js.map