'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var classnames = require('classnames');
var neetoCist = require('@bigbinary/neeto-cist');
var general = require('@bigbinary/neeto-commons-frontend/utils/general');
var Typography = require('@bigbinary/neetoui/Typography');
var Button = require('@bigbinary/neetoui/Button');
var Spinner = require('@bigbinary/neetoui/Spinner');
var Tooltip = require('@bigbinary/neetoui/Tooltip');
var ramda = require('ramda');
var reactI18next = require('react-i18next');
var MoreDropdown = require('./MoreDropdown.js');
var jsxRuntime = require('react/jsx-runtime');
var Check = require('@bigbinary/neeto-icons/Check');
var Warning = require('@bigbinary/neeto-icons/Warning');
var Tag = require('@bigbinary/neetoui/Tag');
require('@bigbinary/neeto-icons/MenuHorizontal');
require('@bigbinary/neeto-icons/MenuVertical');
require('@bigbinary/neetoui/Dropdown');
require('@bigbinary/neeto-commons-frontend/react-utils');
require('./inject-css-B6qYtOJe.js');

var Dropdown = function Dropdown(_ref) {
  var customDropdown = _ref.customDropdown,
    _ref$handleManage = _ref.handleManage,
    handleManage = _ref$handleManage === void 0 ? neetoCist.noop : _ref$handleManage,
    _ref$hideDisconnect = _ref.hideDisconnect,
    hideDisconnect = _ref$hideDisconnect === void 0 ? false : _ref$hideDisconnect,
    _ref$onDisconnect = _ref.onDisconnect,
    onDisconnect = _ref$onDisconnect === void 0 ? neetoCist.noop : _ref$onDisconnect;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  if (ramda.isNotNil(customDropdown)) {
    return /*#__PURE__*/jsxRuntime.jsx("div", {
      onClick: function onClick(e) {
        return e.stopPropagation();
      },
      children: customDropdown
    });
  }
  var isManageable = ramda.isNotNil(handleManage);
  if (!isManageable && hideDisconnect) {
    return null;
  }
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    onClick: function onClick(e) {
      return e.stopPropagation();
    },
    children: /*#__PURE__*/jsxRuntime.jsx(MoreDropdown, {
      menuItems: [{
        isVisible: isManageable,
        onClick: handleManage,
        label: t("neetoMolecules.integrationCard.manage"),
        key: "integration-card-manage-integration"
      }, {
        isVisible: !hideDisconnect,
        onClick: onDisconnect,
        label: t("neetoMolecules.integrationCard.disconnect"),
        key: "integration-card-manage-disconnection"
      }]
    })
  });
};

function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Status = function Status(_ref) {
  var isExpired = _ref.isExpired;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var tagProps = isExpired ? {
    icon: Warning,
    label: t("neetoMolecules.integrationCard.tags.expired"),
    style: "warning"
  } : {
    icon: Check,
    label: t("neetoMolecules.integrationCard.tags.connected"),
    style: "success"
  };
  return /*#__PURE__*/jsxRuntime.jsx(Tag, _objectSpread$1(_objectSpread$1({
    className: "flex-row-reverse"
  }, tagProps), {}, {
    "data-testid": "integration-status"
  }));
};

var _excluded = ["icon", "subIcons", "label", "description", "className", "onConnect", "onDisconnect", "onManage", "isLoading", "isConnected", "isFailed", "isExpired", "disabled", "hidden", "hideDisconnect", "onClick", "tooltipProps", "customDropdown", "dataCy", "connectPath", "connectUrl", "children"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var IntegrationCard = function IntegrationCard(_ref) {
  var Icon = _ref.icon,
    _ref$subIcons = _ref.subIcons,
    subIcons = _ref$subIcons === void 0 ? [] : _ref$subIcons,
    _ref$label = _ref.label,
    label = _ref$label === void 0 ? "" : _ref$label,
    _ref$description = _ref.description,
    description = _ref$description === void 0 ? "" : _ref$description,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$onConnect = _ref.onConnect,
    onConnect = _ref$onConnect === void 0 ? neetoCist.noop : _ref$onConnect,
    _ref$onDisconnect = _ref.onDisconnect,
    onDisconnect = _ref$onDisconnect === void 0 ? neetoCist.noop : _ref$onDisconnect,
    _ref$onManage = _ref.onManage,
    onManage = _ref$onManage === void 0 ? undefined : _ref$onManage,
    _ref$isLoading = _ref.isLoading,
    isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
    _ref$isConnected = _ref.isConnected,
    isConnected = _ref$isConnected === void 0 ? false : _ref$isConnected,
    _ref$isFailed = _ref.isFailed,
    isFailed = _ref$isFailed === void 0 ? false : _ref$isFailed,
    _ref$isExpired = _ref.isExpired,
    isExpired = _ref$isExpired === void 0 ? false : _ref$isExpired,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$hidden = _ref.hidden,
    hidden = _ref$hidden === void 0 ? false : _ref$hidden,
    _ref$hideDisconnect = _ref.hideDisconnect,
    hideDisconnect = _ref$hideDisconnect === void 0 ? false : _ref$hideDisconnect,
    _ref$onClick = _ref.onClick,
    onCardClick = _ref$onClick === void 0 ? undefined : _ref$onClick,
    _ref$tooltipProps = _ref.tooltipProps,
    tooltipProps = _ref$tooltipProps === void 0 ? {} : _ref$tooltipProps,
    _ref$customDropdown = _ref.customDropdown,
    customDropdown = _ref$customDropdown === void 0 ? null : _ref$customDropdown,
    _ref$dataCy = _ref.dataCy,
    dataCy = _ref$dataCy === void 0 ? "" : _ref$dataCy,
    _ref$connectPath = _ref.connectPath,
    connectPath = _ref$connectPath === void 0 ? "" : _ref$connectPath,
    _ref$connectUrl = _ref.connectUrl,
    connectUrl = _ref$connectUrl === void 0 ? "" : _ref$connectUrl,
    children = _ref.children,
    otherProps = _objectWithoutProperties(_ref, _excluded);
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  if (hidden) return null;
  var isCardClickable = isConnected && ramda.isNotNil(onCardClick);
  var cardProps = isCardClickable ? {
    onClick: onCardClick
  } : {};
  return /*#__PURE__*/jsxRuntime.jsx(Tooltip, _objectSpread(_objectSpread({
    disabled: !disabled,
    position: "top",
    content: disabled && t("neetoMolecules.integrationCard.tooltip.integrationNotAvailable")
  }, tooltipProps), {}, {
    children: /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread(_objectSpread({
      "data-cy": dataCy,
      "data-testid": "integration-card",
      className: classnames("neeto-ui-border-gray-300 neeto-ui-shadow-xs hover:neeto-ui-border-gray-500 focus:neeto-ui-border-gray-500 neeto-ui-rounded-lg flex flex-col border p-6 no-underline outline-none transition-colors", {
        "hover:neeto-ui-bg-100 cursor-not-allowed opacity-50": disabled,
        "cursor-pointer": isCardClickable
      }, className)
    }, cardProps), otherProps), {}, {
      children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "flex flex-grow justify-between",
        "data-cy": "integration-tabs",
        children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
          className: "flex min-w-0 flex-col justify-end",
          children: [/*#__PURE__*/jsxRuntime.jsx("div", {
            className: "relative mb-4 flex h-8",
            children: Icon && /*#__PURE__*/jsxRuntime.jsx(Icon, {
              size: 32
            })
          }), /*#__PURE__*/jsxRuntime.jsxs("div", {
            className: "my-auto",
            children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
              className: "mb-2",
              "data-cy": "integration-card-label",
              style: "h4",
              weight: "semibold",
              children: label
            }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
              className: "break-words",
              "data-cy": "".concat(general.joinHyphenCase(label), "-integration-description"),
              style: "body2",
              children: description
            }), children]
          })]
        }), neetoCist.isNotEmpty(subIcons) && /*#__PURE__*/jsxRuntime.jsx("div", {
          className: "flex h-24 flex-col gap-2",
          children: subIcons.map(function (Icon, index) {
            return /*#__PURE__*/jsxRuntime.jsx(Icon, {
              className: "neeto-ui-text-gray-600",
              size: 24
            }, index);
          })
        })]
      }), /*#__PURE__*/jsxRuntime.jsx("div", {
        className: "neeto-ui-border-gray-300 mt-4 w-full border-t pt-2",
        children: isLoading ? /*#__PURE__*/jsxRuntime.jsx("div", {
          className: "mt-3 flex items-center justify-start",
          children: /*#__PURE__*/jsxRuntime.jsx(Spinner, {})
        }) : /*#__PURE__*/jsxRuntime.jsxs("div", {
          className: "flex h-8 items-center justify-between",
          children: [isConnected && /*#__PURE__*/jsxRuntime.jsx(Status, {
            isExpired: isExpired
          }), isFailed && /*#__PURE__*/jsxRuntime.jsx(Button, {
            className: "neeto-ui-text-warning-500",
            "data-cy": "connect-button",
            disabled: disabled || isLoading,
            href: connectUrl,
            label: t("neetoMolecules.integrationCard.tryAgain"),
            style: "link",
            to: connectPath,
            onClick: onConnect
          }), !isConnected && !isFailed && /*#__PURE__*/jsxRuntime.jsx(Button, {
            "data-cy": "connect-button",
            "data-testid": "integraiton-card-connect-button",
            disabled: disabled || isLoading,
            href: connectUrl,
            label: t("neetoMolecules.integrationCard.connect"),
            style: "link",
            to: connectPath,
            onClick: onConnect
          }), (isConnected || isFailed) && /*#__PURE__*/jsxRuntime.jsx(Dropdown, {
            customDropdown: customDropdown,
            hideDisconnect: hideDisconnect,
            onDisconnect: onDisconnect,
            handleManage: onManage
          })]
        })
      })]
    }))
  }));
};

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