import { filterBy } from '@bigbinary/neeto-cist';
import { dateFormat } from '@bigbinary/neeto-commons-frontend/utils';
import Callout from '@bigbinary/neetoui/Callout';
import Typography from '@bigbinary/neetoui/Typography';
import Button from '@bigbinary/neetoui/Button';
import { Trans } from 'react-i18next';
import { n } from './inject-css-C2dztUxs.js';
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { jsx, Fragment } from 'react/jsx-runtime';

var QUERY_KEYS = {
  SUBSCRIPTIONS_LIST: "SUBSCRIPTIONS_LIST"
};
var SUBSCRIPTION_STATUS = {
  past_due: "past_due"
};

var css = ".neeto-molecules-subscription-notifications{border-radius:0}";
n(css,{});

var fetchSubscriptions = function fetchSubscriptions() {
  return axios.get("neeto_sso/api/v1/server/subscriptions");
};
var subscriptionsApi = {
  fetchSubscriptions: fetchSubscriptions
};

var SUBSCRIPTIONS_LIST = QUERY_KEYS.SUBSCRIPTIONS_LIST;
var useFetchSubscriptions = function useFetchSubscriptions() {
  return useQuery({
    queryKey: [SUBSCRIPTIONS_LIST],
    queryFn: subscriptionsApi.fetchSubscriptions
  });
};

var SubscriptionNotificationsContainer = function SubscriptionNotificationsContainer() {
  var _data$clientAppSubscr;
  var _useFetchSubscription = useFetchSubscriptions(),
    data = _useFetchSubscription.data;
  var clientAppSubscriptions = (_data$clientAppSubscr = data === null || data === void 0 ? void 0 : data.clientAppSubscriptions) !== null && _data$clientAppSubscr !== void 0 ? _data$clientAppSubscr : [];
  var visibleNotifications = filterBy({
    status: SUBSCRIPTION_STATUS.past_due
  }, clientAppSubscriptions);
  return /*#__PURE__*/jsx(Fragment, {
    children: visibleNotifications.map(function (_ref, index) {
      var downgradeScheduledAt = _ref.downgradeScheduledAt,
        customerPortalUrl = _ref.customerPortalUrl;
      return /*#__PURE__*/jsx(Callout, {
        className: "neeto-molecules-subscription-notifications w-full p-2.5",
        "data-testid": "subscription-notifications",
        style: "warning",
        children: /*#__PURE__*/jsx(Typography, {
          style: "body2",
          children: /*#__PURE__*/jsx(Trans, {
            i18nKey: "neetoMolecules.subscription.paymentFailedNotification",
            components: {
              a: /*#__PURE__*/jsx(Button, {
                href: customerPortalUrl,
                rel: "noreferrer",
                style: "link",
                target: "_blank"
              })
            },
            values: {
              downgradeScheduledAt: dateFormat.date(downgradeScheduledAt)
            }
          })
        })
      }, index);
    })
  });
};

export { SubscriptionNotificationsContainer as default };
//# sourceMappingURL=SubscriptionNotificationsContainer.js.map
