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

var _templateObject;

import React from 'react';
import styled from 'styled-components';
import { useToasts } from 'react-toast-notifications';
import { useVouchers, vouchersApi, useLocalLabels } from '@sentecacommerce-theme/lib';
import { Element } from './Element';
import { NavigationSkeleton } from '../NavigationSkeleton';
import { Spinner } from '../../../Common';
export var Vouchers = () => {
  var {
    addToast
  } = useToasts();
  var {
    data,
    isFetching
  } = vouchersApi.useGet();
  var vouchers = useVouchers(data);
  var isEmpty = (data == null ? void 0 : data.results.length) === 0;
  var labels = useLocalLabels();
  return /*#__PURE__*/React.createElement(NavigationSkeleton, {
    url: "vouchers",
    header: "Vouchers"
  }, isFetching ? /*#__PURE__*/React.createElement(Spinner, null) : /*#__PURE__*/React.createElement(Container, null, isEmpty && /*#__PURE__*/React.createElement("p", null, labels.noVouchers), vouchers.map((voucher, index) => {
    if (voucher.isUsed) return null;
    return /*#__PURE__*/React.createElement(Element, {
      key: "Voucher__" + voucher.voucherCode + "--" + index,
      data: voucher,
      handleToast: () => addToast(labels.voucherCopied, {
        appearance: 'success',
        autoDismiss: true
      })
    });
  })));
};
var Container = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n  display: flex;\n  flex-direction: column;\n"])));
//# sourceMappingURL=index.js.map