"use strict";

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

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

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

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

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

var _reactToastNotifications = require("react-toast-notifications");

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

var _Element = require("./Element");

var _NavigationSkeleton = require("../NavigationSkeleton");

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

var _templateObject;

var Vouchers = function Vouchers() {
  var _useToasts = (0, _reactToastNotifications.useToasts)(),
      addToast = _useToasts.addToast;

  var _vouchersApi$useGet = _lib.vouchersApi.useGet(),
      data = _vouchersApi$useGet.data,
      isFetching = _vouchersApi$useGet.isFetching;

  var vouchers = (0, _lib.useVouchers)(data);
  var isEmpty = (data == null ? void 0 : data.results.length) === 0;
  var labels = (0, _lib.useLocalLabels)();
  return /*#__PURE__*/_react["default"].createElement(_NavigationSkeleton.NavigationSkeleton, {
    url: "vouchers",
    header: "Vouchers"
  }, isFetching ? /*#__PURE__*/_react["default"].createElement(_Common.Spinner, null) : /*#__PURE__*/_react["default"].createElement(Container, null, isEmpty && /*#__PURE__*/_react["default"].createElement("p", null, labels.noVouchers), vouchers.map(function (voucher, index) {
    if (voucher.isUsed) return null;
    return /*#__PURE__*/_react["default"].createElement(_Element.Element, {
      key: "Voucher__" + voucher.voucherCode + "--" + index,
      data: voucher,
      handleToast: function handleToast() {
        return addToast(labels.voucherCopied, {
          appearance: 'success',
          autoDismiss: true
        });
      }
    });
  })));
};

exports.Vouchers = Vouchers;

var Container = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: flex;\n  flex-direction: column;\n"])));
//# sourceMappingURL=index.js.map