'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var React = require('react');
var neetoCist = require('@bigbinary/neeto-cist');
var constants = require('@bigbinary/neeto-commons-frontend/constants');
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
var NoData = require('@bigbinary/neetoui/NoData');
var Spinner = require('@bigbinary/neetoui/Spinner');
var Pagination = require('@bigbinary/neetoui/Pagination');
var reactI18next = require('react-i18next');
var Container = require('./Container.js');
var Header = require('./Header.js');
var classnames = require('classnames');
var utils = require('@bigbinary/neeto-commons-frontend/utils');
var Typography = require('@bigbinary/neetoui/Typography');
var User = require('@bigbinary/neeto-icons/User');
var UserAdd = require('@bigbinary/neeto-icons/UserAdd');
var UserCircle = require('@bigbinary/neeto-icons/UserCircle');
var UserRemove = require('@bigbinary/neeto-icons/UserRemove');
var UserSettings = require('@bigbinary/neeto-icons/UserSettings');
var CustomDomain = require('@bigbinary/neeto-icons/CustomDomain');
var ApiKeys = require('@bigbinary/neeto-icons/ApiKeys');
var Apple = require('@bigbinary/neeto-icons/misc/Apple');
var GoogleCalendar = require('@bigbinary/neeto-icons/misc/GoogleCalendar');
var GoogleMeet = require('@bigbinary/neeto-icons/misc/GoogleMeet');
var Outlook = require('@bigbinary/neeto-icons/misc/Outlook');
var Slack = require('@bigbinary/neeto-icons/misc/Slack');
var Stripe = require('@bigbinary/neeto-icons/misc/Stripe');
var StripeTypeface = require('@bigbinary/neeto-icons/misc/StripeTypeface');
var Teams = require('@bigbinary/neeto-icons/misc/Teams');
var Twilio = require('@bigbinary/neeto-icons/misc/Twilio');
var Zoom = require('@bigbinary/neeto-icons/misc/Zoom');
var ramda = require('ramda');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var initializers = require('@bigbinary/neeto-commons-frontend/initializers');
var jsxRuntime = require('react/jsx-runtime');
var reactQuery = require('@tanstack/react-query');
var axios = require('axios');
require('./index-JY2zVpnv.js');
require('./_commonjsHelpers-BJu3ubxk.js');
require('./inject-css-B6qYtOJe.js');
require('./Breadcrumbs.js');
require('@bigbinary/neeto-commons-frontend/utils/general');
require('react-router-dom');
require('./HelpPopover.js');
require('@bigbinary/neeto-icons/Help');
require('@bigbinary/neetoui/Button');
require('@bigbinary/neetoui/Popover');
require('./MoreDropdown.js');
require('@bigbinary/neeto-icons/MenuHorizontal');
require('@bigbinary/neeto-icons/MenuVertical');
require('@bigbinary/neetoui/Dropdown');
require('@bigbinary/neetoui/Tooltip');
require('./Search.js');
require('@babel/runtime/helpers/slicedToArray');
require('@bigbinary/neeto-commons-frontend/react-utils/useFuncDebounce');
require('@bigbinary/neeto-commons-frontend/react-utils/useQueryParams');
require('@bigbinary/neeto-commons-frontend/react-utils/useUpdateEffect');
require('@bigbinary/neeto-icons/Search');
require('@bigbinary/neetoui/Input');

var _AUDIT_ICON_MAP;
var AUDIT_LOGS_QUERY_KEY = "audit-logs";
var COUNTRIES_LIST_QUERY_KEY = "countries-list"; // Same key as that used in "neeto-team-members" for cache reuse.
var PERMISSIONS_LIST_QUERY_KEY = "neeto-team-members-permissions"; // Same key as that used in "neeto-team-members" for cache reuse.

var ACTIONS = {
  INVITED_USERS: "invitedUsers",
  USER_SIGNED_UP: "userSignedUp",
  UPDATED_USER: "updatedUser",
  BULK_UPDATE_USERS: "bulkUpdateUsers",
  UPDATED_USER_PROFILE: "updatedUserProfile",
  CREATED_ROLE: "createdRole",
  UPDATED_ROLE: "updatedRole",
  DELETED_ROLE: "deletedRole",
  INTEGRATION_CONNECTED: "integration.connected",
  INTEGRATION_DISCONNECTED: "integration.disconnected",
  INTEGRATION_DISCONNECTED_BY_PROVIDER: "integration.disconnectedByProvider",
  CONNECTED_STRIPE_ACCOUNT: "connectedStripeAccount",
  DISCONNECTED_STRIPE_ACCOUNT: "disconnectedStripeAccount",
  CONNECTED_ZOOM_INTEGRATION: "connectedZoomIntegration",
  DISCONNECTED_ZOOM_INTEGRATION: "disconnectedZoomIntegration",
  CONNECTED_CUSTOM_DOMAIN: "connectedCustomDomain",
  CREATED_API_KEY: "createdApiKey",
  DELETED_API_KEY: "deletedApiKey",
  UPDATED_API_KEY: "updatedApiKey"
};
var AUDIT_ICON_MAP = (_AUDIT_ICON_MAP = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_AUDIT_ICON_MAP, ACTIONS.INVITED_USERS, UserCircle), ACTIONS.USER_SIGNED_UP, UserAdd), ACTIONS.UPDATED_USER, User), ACTIONS.BULK_UPDATE_USERS, User), ACTIONS.UPDATED_USER_PROFILE, UserSettings), ACTIONS.CREATED_ROLE, UserAdd), ACTIONS.UPDATED_ROLE, UserSettings), ACTIONS.DELETED_ROLE, UserRemove), ACTIONS.INTEGRATION_CONNECTED, UserSettings), ACTIONS.INTEGRATION_DISCONNECTED, UserSettings), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_AUDIT_ICON_MAP, ACTIONS.INTEGRATION_DISCONNECTED_BY_PROVIDER, UserSettings), ACTIONS.CONNECTED_STRIPE_ACCOUNT, StripeTypeface), ACTIONS.DISCONNECTED_STRIPE_ACCOUNT, Stripe), ACTIONS.CONNECTED_ZOOM_INTEGRATION, Zoom), ACTIONS.DISCONNECTED_ZOOM_INTEGRATION, Zoom), ACTIONS.CONNECTED_CUSTOM_DOMAIN, CustomDomain), ACTIONS.CREATED_API_KEY, ApiKeys), ACTIONS.DELETED_API_KEY, ApiKeys), ACTIONS.UPDATED_API_KEY, ApiKeys));
var AUDIT_LOGS_PAGE_SIZE = 12;
var LANGUAGE_OPTIONS_MAP = ramda.indexBy(ramda.prop("value"), constants.LANGUAGE_OPTIONS);
var DATE_FORMAT_OPTIONS_MAP = {
  "%m/%d/%Y": "MM/DD/YYYY",
  "%d/%m/%Y": "DD/MM/YYYY",
  "%Y/%m/%d": "YYYY/MM/DD"
};
var FIELD_NAME_MAP = {
  organizationRole: "role"
};
var INTEGRATION_ICON_MAP = {
  google_calendar: GoogleCalendar,
  google_meet: GoogleMeet,
  icloud_calendar: Apple,
  outlook: Outlook,
  slack: Slack,
  teams: Teams,
  twilio: Twilio,
  zoom: Zoom
};
var INTEGRATION_DISPLAY_NAME_MAP = {
  google_calendar: "Google Calendar",
  google_meet: "Google Meet",
  icloud_calendar: "iCloud Calendar",
  outlook: "Outlook",
  slack: "Slack",
  teams: "Microsoft Teams",
  twilio: "Twilio",
  zoom: "Zoom"
};

function ownKeys$4(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$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Trans = function Trans(_ref) {
  var i18nKey = _ref.i18nKey,
    _ref$additionalValues = _ref.additionalValues,
    additionalValues = _ref$additionalValues === void 0 ? {} : _ref$additionalValues,
    _ref$additionalCompon = _ref.additionalComponents,
    additionalComponents = _ref$additionalCompon === void 0 ? {} : _ref$additionalCompon;
  return /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
    i18nKey: i18nKey,
    components: _objectSpread$4({
      Code: /*#__PURE__*/jsxRuntime.jsx(Typography, {
        className: "neeto-ui-rounded-md neeto-ui-bg-gray-100 p-1",
        component: "code",
        style: "body3"
      }),
      Semibold: /*#__PURE__*/jsxRuntime.jsx(Typography, {
        className: "n inline-block text-sm font-medium",
        component: "p"
      })
    }, additionalComponents),
    values: _objectSpread$4({
      productSuffix: initializers.globalProps.appName
    }, additionalValues)
  });
};

var _excluded = ["countriesMap", "permissionsMap", "action", "performedBy", "emails", "firstName", "lastName", "organizationRole", "email", "changes", "status", "message", "errorMessage"];
function ownKeys$3(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$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var formatFieldName = function formatFieldName(field) {
  return FIELD_NAME_MAP[field] || neetoCist.humanize(field);
};
var createFieldValueFormatter = function createFieldValueFormatter(_ref) {
  var field = _ref.field,
    countriesMap = _ref.countriesMap;
  switch (field) {
    case "language":
      return function (value) {
        var _LANGUAGE_OPTIONS_MAP;
        return ((_LANGUAGE_OPTIONS_MAP = LANGUAGE_OPTIONS_MAP[value]) === null || _LANGUAGE_OPTIONS_MAP === void 0 ? void 0 : _LANGUAGE_OPTIONS_MAP.label) || value;
      };
    case "dateFormat":
      return function (value) {
        return DATE_FORMAT_OPTIONS_MAP[value] || value;
      };
    case "countryIdentifier":
      return function (value) {
        var _countriesMap$value;
        return ((_countriesMap$value = countriesMap[value]) === null || _countriesMap$value === void 0 ? void 0 : _countriesMap$value.name) || value;
      };
    default:
      return ramda.identity;
  }
};
var formatChangedFields = function formatChangedFields(_ref2) {
  var changes = _ref2.changes,
    countriesMap = _ref2.countriesMap;
  var fields = Object.keys(changes).map(function (field, index) {
    var change = changes[field];
    var valueFormatter = createFieldValueFormatter({
      field: field,
      countriesMap: countriesMap
    });
    var element;
    if (field === "profileImage") {
      element = /*#__PURE__*/jsxRuntime.jsx("span", {
        children: /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            field: formatFieldName(field)
          },
          i18nKey: "neetoMolecules.auditLogs.text.updatedFields"
        })
      }, field);
    } else if (change && neetoCist.isPresent(change.from)) {
      element = /*#__PURE__*/jsxRuntime.jsx("span", {
        children: /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: "neetoMolecules.auditLogs.text.updatedFieldsWithPreviousValue",
          additionalValues: {
            field: formatFieldName(field),
            from: valueFormatter(change.from),
            to: valueFormatter(change.to)
          }
        })
      }, field);
    } else {
      element = /*#__PURE__*/jsxRuntime.jsx("span", {
        children: /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: "neetoMolecules.auditLogs.text.updatedFieldsWithNewValue",
          additionalValues: {
            field: formatFieldName(field),
            to: valueFormatter(change.to)
          }
        })
      }, field);
    }
    return index > 0 ? [/*#__PURE__*/jsxRuntime.jsx("span", {
      children: ", "
    }, "sep-".concat(field)), element] : element;
  });
  return fields.flat();
};
var transformAction = function transformAction(action) {
  return neetoCist.snakeToCamelCase(action.replace("audit_logs.organization.", ""));
};
var constructAuditLogText = function constructAuditLogText(_ref3) {
  var _ref3$countriesMap = _ref3.countriesMap,
    countriesMap = _ref3$countriesMap === void 0 ? {} : _ref3$countriesMap,
    _ref3$permissionsMap = _ref3.permissionsMap,
    permissionsMap = _ref3$permissionsMap === void 0 ? {} : _ref3$permissionsMap,
    action = _ref3.action,
    performedBy = _ref3.performedBy,
    emailsProp = _ref3.emails,
    firstName = _ref3.firstName,
    lastName = _ref3.lastName,
    organizationRole = _ref3.organizationRole,
    email = _ref3.email,
    _ref3$changes = _ref3.changes,
    changes = _ref3$changes === void 0 ? {} : _ref3$changes,
    status = _ref3.status,
    message = _ref3.message,
    errorMessage = _ref3.errorMessage,
    rest = _objectWithoutProperties(_ref3, _excluded);
  var emails = emailsProp !== null && emailsProp !== void 0 ? emailsProp : [];
  switch (action) {
    case ACTIONS.INVITED_USERS:
      {
        if (status === "success" && neetoCist.isNotEmpty(emails)) {
          var emailList = emails.join(", ");
          return /*#__PURE__*/jsxRuntime.jsx(Trans, {
            additionalValues: {
              performedBy: performedBy,
              emailList: emailList
            },
            i18nKey: "neetoMolecules.auditLogs.text.invitedUsers"
          });
        }
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy,
            errorMessage: errorMessage
          },
          i18nKey: "neetoMolecules.auditLogs.text.invitedUsersFailed"
        });
      }
    case ACTIONS.USER_SIGNED_UP:
      {
        var name = [firstName, lastName].filter(Boolean).join(" ");
        var userIdentifier = name || organizationRole || email || "User";
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            userIdentifier: userIdentifier
          },
          i18nKey: "neetoMolecules.auditLogs.text.userSignedUp"
        });
      }
    case ACTIONS.UPDATED_USER:
      {
        var _changes$active;
        var affectedUser = email || "user";
        var isUserDeactivated = (changes === null || changes === void 0 || (_changes$active = changes.active) === null || _changes$active === void 0 ? void 0 : _changes$active.to) === false;
        var otherChanges = isUserDeactivated ? ramda.omit(["active"], changes) : changes;
        var removedText = isUserDeactivated ? /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy,
            affectedUser: affectedUser
          },
          i18nKey: "neetoMolecules.auditLogs.text.removedUser"
        }) : null;
        if (isUserDeactivated && ramda.isEmpty(otherChanges)) return removedText;
        var changedFields = formatChangedFields({
          changes: otherChanges,
          countriesMap: countriesMap
        });
        var updatedUserText = /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalComponents: {
            ChangedFields: /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
              children: changedFields
            })
          },
          additionalValues: {
            performedBy: performedBy,
            affectedUser: affectedUser
          },
          i18nKey: "neetoMolecules.auditLogs.text.updatedUser"
        });
        return removedText ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
          children: [removedText, " ", updatedUserText]
        }) : updatedUserText;
      }
    case ACTIONS.BULK_UPDATE_USERS:
      {
        if (status === "success" && neetoCist.isNotEmpty(emails)) {
          var _emailList = emails.join(", ");
          return /*#__PURE__*/jsxRuntime.jsx(Trans, {
            additionalValues: {
              performedBy: performedBy,
              emailList: _emailList,
              message: message
            },
            i18nKey: "neetoMolecules.auditLogs.text.bulkUpdateUsers"
          });
        }
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy,
            errorMessage: errorMessage
          },
          i18nKey: "neetoMolecules.auditLogs.text.bulkUpdateUsersFailed"
        });
      }
    case ACTIONS.UPDATED_USER_PROFILE:
      {
        var _changedFields = formatChangedFields({
          changes: changes,
          countriesMap: countriesMap
        });
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalComponents: {
            ChangedFields: /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
              children: _changedFields
            })
          },
          additionalValues: {
            performedBy: performedBy
          },
          i18nKey: "neetoMolecules.auditLogs.text.updatedUserProfile"
        });
      }
    case ACTIONS.CREATED_ROLE:
      {
        var roleName = organizationRole || "role";
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy,
            roleName: roleName
          },
          i18nKey: "neetoMolecules.auditLogs.text.createdRole"
        });
      }
    case ACTIONS.UPDATED_ROLE:
      {
        var _rest$addedPermission = rest.addedPermissions,
          addedPermissions = _rest$addedPermission === void 0 ? [] : _rest$addedPermission,
          _rest$removedPermissi = rest.removedPermissions,
          removedPermissions = _rest$removedPermissi === void 0 ? [] : _rest$removedPermissi,
          _name = rest.name;
        var permissionsToText = function permissionsToText(permissions) {
          return permissions.map(function (permission) {
            var _permissionsMap$permi;
            return ((_permissionsMap$permi = permissionsMap[permission]) === null || _permissionsMap$permi === void 0 ? void 0 : _permissionsMap$permi.description) || neetoCist.humanize(permission.split(".")[1]);
          }).join(", ");
        };
        var i18nKey = "neetoMolecules.auditLogs.text.updatedRole";
        if (_name) {
          i18nKey = "neetoMolecules.auditLogs.text.updatedRoleName";
        } else if (neetoCist.isPresent(addedPermissions) && neetoCist.isPresent(removedPermissions)) {
          i18nKey = "neetoMolecules.auditLogs.text.modifiedRolePermission";
        } else if (neetoCist.isPresent(addedPermissions)) {
          i18nKey = "neetoMolecules.auditLogs.text.addedRolePermission";
        } else if (neetoCist.isPresent(removedPermissions)) {
          i18nKey = "neetoMolecules.auditLogs.text.removedRolePermission";
        }
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: i18nKey,
          additionalValues: {
            performedBy: performedBy,
            roleName: organizationRole || "role",
            name: _name,
            addedPermissionsText: permissionsToText(addedPermissions),
            removedPermissionsText: permissionsToText(removedPermissions),
            addedPermissionsCount: addedPermissions.length,
            removedPermissionsCount: removedPermissions.length
          }
        });
      }
    case ACTIONS.INTEGRATION_CONNECTED:
      {
        var rawName = rest.integrationName,
          integrationOwner = rest.integrationOwner;
        var integrationName = INTEGRATION_DISPLAY_NAME_MAP[rawName] || neetoCist.humanize(rawName);
        var detail = changes === null || changes === void 0 ? void 0 : changes.detail;
        var _i18nKey;
        if (integrationOwner && detail) {
          _i18nKey = "neetoMolecules.auditLogs.text.integrationConnectedOnBehalf";
        } else if (integrationOwner) {
          _i18nKey = "neetoMolecules.auditLogs.text.integrationConnectedOnBehalfWithoutDetail";
        } else if (detail) {
          _i18nKey = "neetoMolecules.auditLogs.text.integrationConnected";
        } else {
          _i18nKey = "neetoMolecules.auditLogs.text.integrationConnectedWithoutDetail";
        }
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: _i18nKey,
          additionalValues: {
            performedBy: performedBy,
            integrationName: integrationName,
            detail: detail,
            integrationOwner: integrationOwner
          }
        });
      }
    case ACTIONS.INTEGRATION_DISCONNECTED:
      {
        var _rawName = rest.integrationName,
          _integrationOwner = rest.integrationOwner;
        var _integrationName = INTEGRATION_DISPLAY_NAME_MAP[_rawName] || neetoCist.humanize(_rawName);
        var _detail = changes === null || changes === void 0 ? void 0 : changes.detail;
        var _i18nKey2;
        if (_integrationOwner && _detail) {
          _i18nKey2 = "neetoMolecules.auditLogs.text.integrationDisconnectedOnBehalf";
        } else if (_integrationOwner) {
          _i18nKey2 = "neetoMolecules.auditLogs.text.integrationDisconnectedOnBehalfWithoutDetail";
        } else if (_detail) {
          _i18nKey2 = "neetoMolecules.auditLogs.text.integrationDisconnected";
        } else {
          _i18nKey2 = "neetoMolecules.auditLogs.text.integrationDisconnectedWithoutDetail";
        }
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: _i18nKey2,
          additionalValues: {
            performedBy: performedBy,
            integrationName: _integrationName,
            detail: _detail,
            integrationOwner: _integrationOwner
          }
        });
      }
    case ACTIONS.INTEGRATION_DISCONNECTED_BY_PROVIDER:
      {
        var _rawName2 = rest.integrationName;
        var _integrationName2 = INTEGRATION_DISPLAY_NAME_MAP[_rawName2] || neetoCist.humanize(_rawName2);
        var _detail2 = changes === null || changes === void 0 ? void 0 : changes.detail;
        var _i18nKey3 = _detail2 ? "neetoMolecules.auditLogs.text.integrationDisconnectedByProvider" : "neetoMolecules.auditLogs.text.integrationDisconnectedByProviderWithoutDetail";
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: _i18nKey3,
          additionalValues: {
            performedBy: performedBy,
            integrationName: _integrationName2,
            detail: _detail2
          }
        });
      }
    case ACTIONS.CONNECTED_STRIPE_ACCOUNT:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: "neetoMolecules.auditLogs.text.connectedStripeAccount",
          additionalValues: {
            performedBy: performedBy,
            stripeAccountId: changes.stripeAccountId
          }
        });
      }
    case ACTIONS.DISCONNECTED_STRIPE_ACCOUNT:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy
          },
          i18nKey: "neetoMolecules.auditLogs.text.disconnectedStripeAccount"
        });
      }
    case ACTIONS.CONNECTED_ZOOM_INTEGRATION:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          i18nKey: "neetoMolecules.auditLogs.text.connectedZoomAccount",
          additionalValues: {
            performedBy: performedBy,
            zoomAccountId: changes.zoomAccountId
          }
        });
      }
    case ACTIONS.DISCONNECTED_ZOOM_INTEGRATION:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy
          },
          i18nKey: "neetoMolecules.auditLogs.text.disconnectedZoomAccount"
        });
      }
    case ACTIONS.CONNECTED_CUSTOM_DOMAIN:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy,
            hostname: changes.hostname
          },
          i18nKey: "neetoMolecules.auditLogs.text.connectedCustomDomain"
        });
      }
    case ACTIONS.DELETED_ROLE:
      {
        var _roleName = organizationRole || "role";
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy,
            roleName: _roleName
          },
          i18nKey: "neetoMolecules.auditLogs.text.deletedRole"
        });
      }
    case ACTIONS.CREATED_API_KEY:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: _objectSpread$3({
            performedBy: performedBy
          }, rest),
          i18nKey: "neetoMolecules.auditLogs.text.createdApiKey"
        });
      }
    case ACTIONS.DELETED_API_KEY:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: _objectSpread$3({
            performedBy: performedBy
          }, rest),
          i18nKey: "neetoMolecules.auditLogs.text.deletedApiKey"
        });
      }
    case ACTIONS.UPDATED_API_KEY:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: _objectSpread$3({
            performedBy: performedBy
          }, rest),
          i18nKey: "neetoMolecules.auditLogs.text.updatedApiKey"
        });
      }
    default:
      {
        return /*#__PURE__*/jsxRuntime.jsx(Trans, {
          additionalValues: {
            performedBy: performedBy
          },
          i18nKey: "neetoMolecules.auditLogs.text.performedAction"
        });
      }
  }
};
var indexById = ramda.indexBy(ramda.prop("id"));
var indexByPermissionName = ramda.indexBy(ramda.prop("name"));

function ownKeys$2(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$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Card = function Card(_ref) {
  var auditLog = _ref.auditLog,
    countriesMap = _ref.countriesMap,
    index = _ref.index,
    permissionsMap = _ref.permissionsMap,
    totalCount = _ref.totalCount;
  var key = auditLog.key,
    metadata = auditLog.metadata,
    performer = auditLog.performer,
    updatedAt = auditLog.updatedAt;
  var action = transformAction(key);
  var performedBy = (performer === null || performer === void 0 ? void 0 : performer.name) || "";
  var performedAt = utils.dateFormat.dateTime(updatedAt);
  var auditText = constructAuditLogText(_objectSpread$2({
    countriesMap: countriesMap,
    action: action,
    performedBy: performedBy,
    permissionsMap: permissionsMap
  }, metadata));
  var isIntegrationAction = action === ACTIONS.INTEGRATION_CONNECTED || action === ACTIONS.INTEGRATION_DISCONNECTED || action === ACTIONS.INTEGRATION_DISCONNECTED_BY_PROVIDER;
  var Icon = isIntegrationAction ? INTEGRATION_ICON_MAP[metadata === null || metadata === void 0 ? void 0 : metadata.integrationName] || AUDIT_ICON_MAP[action] : AUDIT_ICON_MAP[action];
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    "data-testid": "audit-log-card",
    className: classnames("align-items-center neeto-ui-border-gray-200 flex w-full gap-x-4 border-b border-l border-r p-3", {
      "rounded-t-md border-t": index === 0,
      "rounded-b-md": index === totalCount - 1
    }),
    children: [/*#__PURE__*/jsxRuntime.jsx("div", {
      className: "neeto-ui-rounded-full neeto-ui-bg-gray-100 flex size-10 flex-shrink-0 items-center justify-center",
      children: /*#__PURE__*/jsxRuntime.jsx(Icon, {
        className: "neeto-ui-text-gray-600 flex-shrink-0",
        size: 22
      })
    }), /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "flex flex-col gap-y-2",
      "data-testid": "audit-log-content",
      children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
        component: "span",
        "data-testid": "audit-log-text",
        lineHeight: "normal",
        style: "body2",
        children: auditText
      }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
        className: "neeto-ui-text-gray-500 m-0",
        "data-testid": "audit-log-timestamp",
        style: "body3",
        children: performedAt
      })]
    })]
  });
};

var fetchAuditLogs = function fetchAuditLogs(params) {
  return axios.get("api/v1/audit_logs", {
    params: params
  });
};
var fetchCountries = function fetchCountries() {
  return axios.get("neeto_team_members/profile/countries");
};
var fetchPermissions = function fetchPermissions() {
  return axios.get("neeto_team_members/permissions");
};
var auditLogsApi = {
  fetchAuditLogs: fetchAuditLogs,
  fetchCountries: fetchCountries,
  fetchPermissions: fetchPermissions
};

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 useFetchAuditLogs = function useFetchAuditLogs(_ref) {
  var params = _ref.params,
    _ref$options = _ref.options,
    options = _ref$options === void 0 ? {} : _ref$options;
  return reactQuery.useQuery(_objectSpread$1({
    queryKey: [AUDIT_LOGS_QUERY_KEY, params],
    queryFn: function queryFn() {
      return auditLogsApi.fetchAuditLogs(params);
    }
  }, options));
};

var useFetchCountries = function useFetchCountries() {
  return reactQuery.useQuery({
    queryKey: [COUNTRIES_LIST_QUERY_KEY],
    queryFn: auditLogsApi.fetchCountries,
    staleTime: constants.DEFAULT_STALE_TIME
  });
};

var useFetchPermissions = function useFetchPermissions() {
  return reactQuery.useQuery({
    queryKey: [PERMISSIONS_LIST_QUERY_KEY],
    queryFn: auditLogsApi.fetchPermissions,
    staleTime: constants.DEFAULT_STALE_TIME
  });
};

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 AuditLogs = function AuditLogs(_ref) {
  var headerProps = _ref.headerProps,
    noDataHelpText = _ref.noDataHelpText,
    noDataTitle = _ref.noDataTitle;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useQueryParams = reactUtils.useQueryParams(),
    _useQueryParams$page = _useQueryParams.page,
    page = _useQueryParams$page === void 0 ? constants.DEFAULT_PAGE_INDEX : _useQueryParams$page;
  var _useFetchAuditLogs = useFetchAuditLogs({
      params: {
        page: page,
        pageSize: AUDIT_LOGS_PAGE_SIZE
      }
    }),
    _useFetchAuditLogs$da = _useFetchAuditLogs.data,
    _useFetchAuditLogs$da2 = _useFetchAuditLogs$da === void 0 ? {} : _useFetchAuditLogs$da,
    _useFetchAuditLogs$da3 = _useFetchAuditLogs$da2.auditLogs,
    auditLogs = _useFetchAuditLogs$da3 === void 0 ? [] : _useFetchAuditLogs$da3,
    _useFetchAuditLogs$da4 = _useFetchAuditLogs$da2.totalCount,
    totalCount = _useFetchAuditLogs$da4 === void 0 ? 0 : _useFetchAuditLogs$da4,
    isLoading = _useFetchAuditLogs.isLoading,
    isFetching = _useFetchAuditLogs.isFetching;
  var _useFetchCountries = useFetchCountries(),
    countriesData = _useFetchCountries.data;
  var _useFetchPermissions = useFetchPermissions(),
    permissionsData = _useFetchPermissions.data;
  var countriesList = countriesData === null || countriesData === void 0 ? void 0 : countriesData.countries;
  var permissionsList = permissionsData === null || permissionsData === void 0 ? void 0 : permissionsData.permissions;
  var permissionsMap = React.useMemo(function () {
    return permissionsList ? indexByPermissionName(permissionsList) : {};
  }, [permissionsList]);
  var countriesMap = React.useMemo(function () {
    return countriesList ? indexById(countriesList) : {};
  }, [countriesList]);
  if (isLoading || isFetching) {
    return /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "flex h-full w-full items-center justify-center",
      children: /*#__PURE__*/jsxRuntime.jsx(Spinner, {})
    });
  }
  return /*#__PURE__*/jsxRuntime.jsxs(Container, {
    isHeaderFixed: true,
    className: "overflow-hidden",
    children: [/*#__PURE__*/jsxRuntime.jsx(Header, _objectSpread({
      className: "px-5 md:px-10",
      title: t("neetoMolecules.auditLogs.title")
    }, headerProps)), neetoCist.isPresent(auditLogs) ? /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "w-full grow overflow-y-auto px-5 md:px-10",
      children: auditLogs.map(function (auditLog, index) {
        return /*#__PURE__*/React.createElement(Card, {
          auditLog: auditLog,
          countriesMap: countriesMap,
          index: index,
          permissionsMap: permissionsMap,
          key: auditLog.id,
          totalCount: auditLogs.length
        });
      })
    }) : /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "flex h-full w-full items-center justify-center",
      children: /*#__PURE__*/jsxRuntime.jsx(NoData, {
        helpText: noDataHelpText,
        title: noDataTitle || t("neetoMolecules.auditLogs.noData")
      })
    }), totalCount > 0 && /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "flex w-full justify-end px-5 py-4 md:px-10",
      children: /*#__PURE__*/jsxRuntime.jsx(Pagination, {
        count: totalCount,
        pageNo: parseInt(page),
        pageSize: AUDIT_LOGS_PAGE_SIZE
      })
    })]
  });
};

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