'use strict';

var neetoCist = require('@bigbinary/neeto-cist');
var utils = require('@bigbinary/neeto-commons-frontend/utils');
var Callout = require('@bigbinary/neetoui/Callout');
var Typography = require('@bigbinary/neetoui/Typography');
var Button = require('@bigbinary/neetoui/Button');
var reactI18next = require('react-i18next');
var injectCss = require('./inject-css-B6qYtOJe.js');
var reactQuery = require('@tanstack/react-query');
var axios = require('axios');
var jsxRuntime = require('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}";
injectCss.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 reactQuery.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 = neetoCist.filterBy({
    status: SUBSCRIPTION_STATUS.past_due
  }, clientAppSubscriptions);
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
    children: visibleNotifications.map(function (_ref, index) {
      var downgradeScheduledAt = _ref.downgradeScheduledAt,
        customerPortalUrl = _ref.customerPortalUrl;
      return /*#__PURE__*/jsxRuntime.jsx(Callout, {
        className: "neeto-molecules-subscription-notifications w-full p-2.5",
        "data-testid": "subscription-notifications",
        style: "warning",
        children: /*#__PURE__*/jsxRuntime.jsx(Typography, {
          style: "body2",
          children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
            i18nKey: "neetoMolecules.subscription.paymentFailedNotification",
            components: {
              a: /*#__PURE__*/jsxRuntime.jsx(Button, {
                href: customerPortalUrl,
                rel: "noreferrer",
                style: "link",
                target: "_blank"
              })
            },
            values: {
              downgradeScheduledAt: utils.dateFormat.date(downgradeScheduledAt)
            }
          })
        })
      }, index);
    })
  });
};

module.exports = SubscriptionNotificationsContainer;
//# sourceMappingURL=SubscriptionNotificationsContainer.js.map
