'use strict';

var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _regeneratorRuntime = require('@babel/runtime/regenerator');
var React = require('react');
var classnames = require('classnames');
var initializers = require('@bigbinary/neeto-commons-frontend/initializers');
var utils$2 = require('@bigbinary/neeto-commons-frontend/utils');
var Info = require('@bigbinary/neeto-icons/Info');
var LeftArrow = require('@bigbinary/neeto-icons/LeftArrow');
var hooks = require('@bigbinary/neeto-image-uploader-frontend/hooks');
var Button = require('@bigbinary/neetoui/Button');
var Typography = require('@bigbinary/neetoui/Typography');
var Toastr = require('@bigbinary/neetoui/Toastr');
var Callout = require('@bigbinary/neetoui/Callout');
var Spinner = require('@bigbinary/neetoui/Spinner');
var ActionBlock = require('@bigbinary/neetoui/formik/ActionBlock');
var Form = require('@bigbinary/neetoui/formik/Form');
var ramda = require('ramda');
var reactI18next = require('react-i18next');
var index = require('../index-4wQ9Y7v9.js');
var ProfileImage = require('../ProfileImage-DN5IzFz7.js');
var useRolesApi = require('../useRolesApi-DuL4eCuF.js');
var useTeamsApi = require('../useTeamsApi-ClWGPxNW.js');
var injectCss = require('../inject-css-B6qYtOJe.js');
var formik = require('formik');
var neetoCist = require('@bigbinary/neeto-cist');
var Checkbox = require('@bigbinary/neetoui/Checkbox');
var Tooltip = require('@bigbinary/neetoui/Tooltip');
var Select = require('@bigbinary/neetoui/formik/Select');
var Switch = require('@bigbinary/neetoui/formik/Switch');
var RolesRadioGroup = require('../RolesRadioGroup-DsIpgIDf.js');
var jsxRuntime = require('react/jsx-runtime');
var constants = require('@bigbinary/neeto-commons-frontend/constants');
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
var MenuHorizontal = require('@bigbinary/neeto-icons/MenuHorizontal');
var CopyToClipboardButton = require('@bigbinary/neeto-molecules/CopyToClipboardButton');
var Dropdown = require('@bigbinary/neetoui/Dropdown');
var useInviteLinksApi = require('../useInviteLinksApi-COVfmZiQ.js');
var Label = require('@bigbinary/neetoui/Label');
var MultiEmailInput = require('@bigbinary/neetoui/formik/MultiEmailInput');
var Input = require('@bigbinary/neetoui/formik/Input');
var utils = require('./utils.js');
var neetoTimeZones = require('@bigbinary/neeto-time-zones');
var PhoneNumber = require('@bigbinary/neeto-molecules/PhoneNumber');
var constants$1 = require('../constants-D_H6M1Pm.js');
var utils$1 = require('../utils-CgwJI9pk.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../useCountriesApi-CjhrbnjK.js');
require('@tanstack/react-query');
require('axios');
require('@bigbinary/neeto-icons/Edit');
require('@bigbinary/neetoui/Avatar');
require('i18next');
require('yup');
require('@babel/runtime/helpers/objectWithoutProperties');
require('qs');
require('../queryClient-4vAFE3bx.js');
require('@bigbinary/neetoui/formik/Radio');
require('@bigbinary/neetoui/Pane');
require('@bigbinary/neetoui/Modal');
require('../_commonjsHelpers-BJu3ubxk.js');
require('@bigbinary/neeto-molecules/MoreDropdown');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _asyncToGenerator__default = /*#__PURE__*/_interopDefault(_asyncToGenerator);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var Info__default = /*#__PURE__*/_interopDefault(Info);
var LeftArrow__default = /*#__PURE__*/_interopDefault(LeftArrow);
var Button__default = /*#__PURE__*/_interopDefault(Button);
var Typography__default = /*#__PURE__*/_interopDefault(Typography);
var Toastr__default = /*#__PURE__*/_interopDefault(Toastr);
var Callout__default = /*#__PURE__*/_interopDefault(Callout);
var Spinner__default = /*#__PURE__*/_interopDefault(Spinner);
var ActionBlock__default = /*#__PURE__*/_interopDefault(ActionBlock);
var Form__default = /*#__PURE__*/_interopDefault(Form);
var Checkbox__default = /*#__PURE__*/_interopDefault(Checkbox);
var Tooltip__default = /*#__PURE__*/_interopDefault(Tooltip);
var Select__default = /*#__PURE__*/_interopDefault(Select);
var Switch__default = /*#__PURE__*/_interopDefault(Switch);
var MenuHorizontal__default = /*#__PURE__*/_interopDefault(MenuHorizontal);
var CopyToClipboardButton__default = /*#__PURE__*/_interopDefault(CopyToClipboardButton);
var Dropdown__default = /*#__PURE__*/_interopDefault(Dropdown);
var Label__default = /*#__PURE__*/_interopDefault(Label);
var MultiEmailInput__default = /*#__PURE__*/_interopDefault(MultiEmailInput);
var Input__default = /*#__PURE__*/_interopDefault(Input);

var css = ".ntm-manage-members__header{align-items:flex-start;display:flex}.ntm-manage-members__header>*+*{margin-inline-start:.5rem}.ntm-product-roles-table th{color:rgb(var(--neeto-ui-gray-700));font-size:var(--neeto-ui-text-xs);font-weight:var(--neeto-ui-font-bold);text-transform:uppercase;vertical-align:middle}.ntm-product-roles-table td,.ntm-product-roles-table th{border:1px solid rgb(var(--neeto-ui-gray-200));padding:.5rem;text-align:start}.ntm-manage-members__app-roles{align-items:center;display:flex;justify-content:space-between;padding:.5rem 0;width:100%}.ntm-manage-members-app-roles__select-wrapper{max-width:250px;width:50%}.ntm-manage-members-effective-app-roles{align-items:center;display:flex;justify-content:space-between;padding:.25rem 0}.ntm-manage-members-effective-app-roles__role-name{max-width:300px;width:67%}.ntm-manage-members__checkbox-align-start.neeto-ui-checkbox__wrapper .neeto-ui-checkbox__container{align-items:flex-start}.ntm-manage-members__checkbox-align-start.neeto-ui-checkbox__wrapper .neeto-ui-checkbox[type=checkbox]{margin-top:.25rem}\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImFwcC9qYXZhc2NyaXB0L3NyYy9zdHlsZXNoZWV0cy9jb21wb25lbnRzL21hbmFnZS1tZW1iZXJzLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSw0QkFFRSxzQkFBdUIsQ0FEdkIsWUFFRixDQUVBLGdDQUNFLHlCQUNGLENBRUEsNEJBQ0UsbUNBQW9DLENBQ3BDLGlDQUFrQyxDQUVsQyxxQ0FBc0MsQ0FDdEMsd0JBQXlCLENBRnpCLHFCQUdGLENBRUEsd0RBRUUsOENBQStDLENBRS9DLGFBQWUsQ0FEZixnQkFFRixDQUVBLCtCQUVFLGtCQUFtQixDQURuQixZQUFhLENBRWIsNkJBQThCLENBRTlCLGVBQWlCLENBRGpCLFVBRUYsQ0FFQSw4Q0FFRSxlQUFnQixDQURoQixTQUVGLENBRUEsd0NBRUUsa0JBQW1CLENBRG5CLFlBQWEsQ0FFYiw2QkFBOEIsQ0FDOUIsZ0JBQ0YsQ0FFQSxtREFFRSxlQUFnQixDQURoQixTQUVGLENBRUEsbUdBQ0Usc0JBQ0YsQ0FFQSx1R0FDRSxpQkFDRiIsInNvdXJjZXNDb250ZW50IjpbIi5udG0tbWFuYWdlLW1lbWJlcnNfX2hlYWRlciB7XG4gIGRpc3BsYXk6IGZsZXg7XG4gIGFsaWduLWl0ZW1zOiBmbGV4LXN0YXJ0O1xufVxuXG4ubnRtLW1hbmFnZS1tZW1iZXJzX19oZWFkZXIgPiAqICsgKiB7XG4gIG1hcmdpbi1pbmxpbmUtc3RhcnQ6IDAuNXJlbTtcbn1cblxuLm50bS1wcm9kdWN0LXJvbGVzLXRhYmxlIHRoIHtcbiAgY29sb3I6IHJnYih2YXIoLS1uZWV0by11aS1ncmF5LTcwMCkpO1xuICBmb250LXNpemU6IHZhcigtLW5lZXRvLXVpLXRleHQteHMpO1xuICB2ZXJ0aWNhbC1hbGlnbjogbWlkZGxlO1xuICBmb250LXdlaWdodDogdmFyKC0tbmVldG8tdWktZm9udC1ib2xkKTtcbiAgdGV4dC10cmFuc2Zvcm06IHVwcGVyY2FzZTtcbn1cblxuLm50bS1wcm9kdWN0LXJvbGVzLXRhYmxlIHRkLFxuLm50bS1wcm9kdWN0LXJvbGVzLXRhYmxlIHRoIHtcbiAgYm9yZGVyOiAxcHggc29saWQgcmdiKHZhcigtLW5lZXRvLXVpLWdyYXktMjAwKSk7XG4gIHRleHQtYWxpZ246IHN0YXJ0O1xuICBwYWRkaW5nOiAwLjVyZW07XG59XG5cbi5udG0tbWFuYWdlLW1lbWJlcnNfX2FwcC1yb2xlcyB7XG4gIGRpc3BsYXk6IGZsZXg7XG4gIGFsaWduLWl0ZW1zOiBjZW50ZXI7XG4gIGp1c3RpZnktY29udGVudDogc3BhY2UtYmV0d2VlbjtcbiAgd2lkdGg6IDEwMCU7XG4gIHBhZGRpbmc6IDAuNXJlbSAwO1xufVxuXG4ubnRtLW1hbmFnZS1tZW1iZXJzLWFwcC1yb2xlc19fc2VsZWN0LXdyYXBwZXIge1xuICB3aWR0aDogNTAlO1xuICBtYXgtd2lkdGg6IDI1MHB4O1xufVxuXG4ubnRtLW1hbmFnZS1tZW1iZXJzLWVmZmVjdGl2ZS1hcHAtcm9sZXMge1xuICBkaXNwbGF5OiBmbGV4O1xuICBhbGlnbi1pdGVtczogY2VudGVyO1xuICBqdXN0aWZ5LWNvbnRlbnQ6IHNwYWNlLWJldHdlZW47XG4gIHBhZGRpbmc6IDAuMjVyZW0gMDtcbn1cblxuLm50bS1tYW5hZ2UtbWVtYmVycy1lZmZlY3RpdmUtYXBwLXJvbGVzX19yb2xlLW5hbWUge1xuICB3aWR0aDogNjclO1xuICBtYXgtd2lkdGg6IDMwMHB4O1xufVxuXG4ubnRtLW1hbmFnZS1tZW1iZXJzX19jaGVja2JveC1hbGlnbi1zdGFydC5uZWV0by11aS1jaGVja2JveF9fd3JhcHBlciAubmVldG8tdWktY2hlY2tib3hfX2NvbnRhaW5lciB7XG4gIGFsaWduLWl0ZW1zOiBmbGV4LXN0YXJ0O1xufVxuXG4ubnRtLW1hbmFnZS1tZW1iZXJzX19jaGVja2JveC1hbGlnbi1zdGFydC5uZWV0by11aS1jaGVja2JveF9fd3JhcHBlciAubmVldG8tdWktY2hlY2tib3hbdHlwZT1cImNoZWNrYm94XCJdIHtcbiAgbWFyZ2luLXRvcDogMC4yNXJlbTtcbn1cbiJdfQ== */";
injectCss.n(css,{});

var AppList = function AppList(_ref) {
  var _globalProps$user;
  var globalRoles = _ref.globalRoles,
    savedStateRef = _ref.savedStateRef;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useState = React.useState(savedStateRef.current.isAppListEnabled),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    isAppListEnabled = _useState2[0],
    setIsAppListEnabled = _useState2[1];
  var _useFormikContext = formik.useFormikContext(),
    _useFormikContext$val = _useFormikContext.values,
    _useFormikContext$val2 = _useFormikContext$val.emails,
    emails = _useFormikContext$val2 === void 0 ? [] : _useFormikContext$val2,
    _useFormikContext$val3 = _useFormikContext$val.appRoles,
    appRoles = _useFormikContext$val3 === void 0 ? [] : _useFormikContext$val3,
    setFieldValue = _useFormikContext.setFieldValue;
  var selectedEmail = ramda.pluck("value", emails);
  var isManageProductsLinkEnabled = ((_globalProps$user = initializers.globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.isOwner) && Object.keys(globalRoles).length >= 3;
  React.useEffect(function () {
    if (savedStateRef.current.isAppListEnabled !== isAppListEnabled) {
      appRoles === null || appRoles === void 0 || appRoles.forEach(function (appRole, index) {
        var _globalProps$appName;
        if ((appRole === null || appRole === void 0 ? void 0 : appRole.appName) === ((_globalProps$appName = initializers.globalProps.appName) === null || _globalProps$appName === void 0 ? void 0 : _globalProps$appName.substring(5))) {
          setFieldValue("appRoles[".concat(index, "].isEnabled"), true);
          return;
        }
        setFieldValue("appRoles[".concat(index, "].isEnabled"), isAppListEnabled);
      });
    }
    savedStateRef.current.isAppListEnabled = isAppListEnabled;
  }, [isAppListEnabled]); // eslint-disable-line react-hooks/exhaustive-deps

  var buildRoleOptions = function buildRoleOptions(roles) {
    return roles.map(function (role) {
      return neetoCist.toLabelAndValue(role.name);
    });
  };
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "neeto-ui-flex neeto-ui-flex-col neeto-ui-gap-6",
    children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-ui-w-full space-y-3",
      children: [/*#__PURE__*/jsxRuntime.jsx(Checkbox__default.default, {
        checked: isAppListEnabled,
        className: "ntm-manage-members__checkbox-align-start",
        "data-testid": "ntm-manage-members-app-list-checkbox",
        label: /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
          component: "span",
          lineHeight: "relaxed",
          style: "body2",
          children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
            i18nKey: "neetoTeamMembers.helpers.addMembersToNeetoProducts",
            values: {
              emails: selectedEmail
            }
          })
        }),
        onChange: function onChange() {
          return setIsAppListEnabled(ramda.not);
        }
      }), isManageProductsLinkEnabled && /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
        style: "body2",
        children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
          i18nKey: "neetoTeamMembers.helpers.manageProducts",
          components: {
            button: /*#__PURE__*/jsxRuntime.jsx(Button__default.default, {
              href: RolesRadioGroup.NEETO_AUTH_MANAGE_PRODUCT_URL,
              style: "link"
            })
          }
        })
      })]
    }), /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "neeto-ui-w-full",
      children: appRoles.map(function (_ref2, index) {
        var _globalProps$appName2;
        var appName = _ref2.appName,
          isEnabled = _ref2.isEnabled;
        var isCurrentApp = appName === ((_globalProps$appName2 = initializers.globalProps.appName) === null || _globalProps$appName2 === void 0 ? void 0 : _globalProps$appName2.substring(5));
        var isAppRoleSelectionChecked = isCurrentApp || isEnabled;
        return /*#__PURE__*/jsxRuntime.jsxs("div", {
          className: "ntm-manage-members__app-roles",
          children: [/*#__PURE__*/jsxRuntime.jsx(Tooltip__default.default, {
            content: t("neetoTeamMembers.tooltips.hostAppIsRequired"),
            disabled: !isCurrentApp,
            position: "left",
            children: /*#__PURE__*/jsxRuntime.jsx("span", {
              children: /*#__PURE__*/jsxRuntime.jsx(Switch__default.default, {
                checked: isAppRoleSelectionChecked,
                disabled: isCurrentApp,
                name: "appsRoles[".concat(index, "].isEnabled"),
                label: t("neetoTeamMembers.labels.neeto_", {
                  product: appName
                }),
                onChange: function onChange(_ref3) {
                  var target = _ref3.target;
                  setFieldValue("appRoles[".concat(index, "].isEnabled"), target.checked);
                }
              })
            })
          }), /*#__PURE__*/jsxRuntime.jsx(Tooltip__default.default, {
            content: t("neetoTeamMembers.tooltips.goBackToChangeRole"),
            disabled: !isCurrentApp,
            position: "top",
            children: /*#__PURE__*/jsxRuntime.jsx("span", {
              className: "ntm-manage-members-app-roles__select-wrapper",
              children: /*#__PURE__*/jsxRuntime.jsx(Select__default.default, {
                dataTestid: "ntm-manage-members-app-roles",
                isDisabled: isCurrentApp || !isEnabled,
                name: "appRoles[".concat(index, "].activeRole"),
                options: buildRoleOptions(globalRoles[appName]),
                size: "small",
                strategy: "fixed",
                onChange: function onChange(_ref4) {
                  var value = _ref4.value;
                  setFieldValue("appRoles[".concat(index, "].activeRole"), value);
                }
              })
            })
          })]
        }, appName);
      })
    })]
  });
};

var Confirmation = function Confirmation() {
  var _globalProps$organiza;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useFormikContext = formik.useFormikContext(),
    _useFormikContext$val = _useFormikContext.values,
    emails = _useFormikContext$val.emails,
    role = _useFormikContext$val.role,
    appRoles = _useFormikContext$val.appRoles;
  var selectedEmail = ramda.pluck("value", emails);
  var activeAppRoles = neetoCist.filterBy({
    isEnabled: true
  }, appRoles);
  return activeAppRoles.length > 1 ? /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "neeto-ui-flex neeto-ui-flex-col neeto-ui-gap-6",
    children: [/*#__PURE__*/jsxRuntime.jsx("div", {
      className: "neeto-ui-w-full",
      children: /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
        component: "span",
        lineHeight: "relaxed",
        style: "body2",
        children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
          i18nKey: "neetoTeamMembers.helpers.multipleProductInvitation",
          values: {
            count: selectedEmail.length,
            emails: selectedEmail,
            orgName: (_globalProps$organiza = initializers.globalProps.organization) === null || _globalProps$organiza === void 0 ? void 0 : _globalProps$organiza.name
          }
        })
      })
    }), /*#__PURE__*/jsxRuntime.jsxs("table", {
      className: "neeto-ui-w-full ntm-product-roles-table",
      children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
        children: /*#__PURE__*/jsxRuntime.jsxs("tr", {
          children: [/*#__PURE__*/jsxRuntime.jsx("th", {
            children: t("neetoTeamMembers.common.productName")
          }), /*#__PURE__*/jsxRuntime.jsx("th", {
            children: t("neetoTeamMembers.common.role", constants.SINGULAR)
          })]
        })
      }), /*#__PURE__*/jsxRuntime.jsx("tbody", {
        children: activeAppRoles.map(function (_ref) {
          var appName = _ref.appName,
            activeRole = _ref.activeRole;
          return /*#__PURE__*/jsxRuntime.jsxs("tr", {
            children: [/*#__PURE__*/jsxRuntime.jsx("td", {
              children: /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
                component: "span",
                lineHeight: "relaxed",
                style: "body2",
                children: t("neetoTeamMembers.labels.neeto_", {
                  product: appName
                })
              })
            }), /*#__PURE__*/jsxRuntime.jsx("td", {
              children: /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
                component: "span",
                lineHeight: "relaxed",
                style: "body2",
                children: activeRole
              })
            })]
          }, appName);
        })
      })]
    })]
  }) : /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
    component: "span",
    lineHeight: "relaxed",
    style: "body2",
    children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
      i18nKey: "neetoTeamMembers.helpers.singleProductInvitation",
      values: RolesRadioGroup.getSingleInvitationTranslationProps({
        activeAppRoles: activeAppRoles,
        role: role,
        selectedEmail: selectedEmail
      })
    })
  });
};

var Menu = Dropdown__default.default.Menu,
  MenuItem = Dropdown__default.default.MenuItem;
var MenuItemButton = MenuItem.Button;
var InviteLink = function InviteLink(_ref) {
  var _inviteLinks$, _inviteLinks$2, _inviteLinks$3, _inviteLinks$4, _inviteLinks$5, _inviteLinks$6;
  var t = _ref.t,
    roles = _ref.roles;
  var _useCreateInviteLinks = useInviteLinksApi.useCreateInviteLinks(),
    createInviteLink = _useCreateInviteLinks.mutate,
    isCreateLinkPending = _useCreateInviteLinks.isPending;
  var _useRegenerateInviteL = useInviteLinksApi.useRegenerateInviteLink(),
    regenerateLink = _useRegenerateInviteL.mutate;
  var _useFetchInviteLinks = useInviteLinksApi.useFetchInviteLinks(),
    _useFetchInviteLinks$ = _useFetchInviteLinks.data,
    _useFetchInviteLinks$2 = _useFetchInviteLinks$ === void 0 ? {} : _useFetchInviteLinks$,
    _useFetchInviteLinks$3 = _useFetchInviteLinks$2.inviteLinks,
    inviteLinks = _useFetchInviteLinks$3 === void 0 ? [] : _useFetchInviteLinks$3,
    isFetchLinkLoading = _useFetchInviteLinks.isLoading;
  var _useFormikContext = formik.useFormikContext(),
    values = _useFormikContext.values;
  var isInviteLinkEmpty = !isFetchLinkLoading && ramda.isEmpty(inviteLinks);
  var handleRegenerate = function handleRegenerate() {
    var _findBy = neetoCist.findBy({
        name: values.role
      }, roles),
      roleId = _findBy.id;
    if (ramda.isEmpty(inviteLinks)) {
      createInviteLink({
        organizationRoleId: roleId
      });
      return;
    }
    regenerateLink({
      inviteLinkId: inviteLinks[0].id,
      payload: {
        organizationRoleId: roleId
      }
    });
  };
  if (isFetchLinkLoading || isCreateLinkPending) {
    return /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "neeto-ui-w-full flex justify-center items-center",
      children: /*#__PURE__*/jsxRuntime.jsx(Spinner__default.default, {
        size: "large"
      })
    });
  }
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "neeto-ui-w-full space-y-2",
    children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "flex items-center gap-2 pt-1",
      children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "neeto-ui-rounded-md neeto-ui-border-gray-300 neeto-ui-bg-gray-50 relative flex min-w-0 grow items-center truncate border leading-none",
        children: [/*#__PURE__*/jsxRuntime.jsx("div", {
          className: "relative min-w-0 grow truncate p-2 leading-none",
          children: !isInviteLinkEmpty && RolesRadioGroup.getInviteURL(inviteLinks === null || inviteLinks === void 0 || (_inviteLinks$ = inviteLinks[0]) === null || _inviteLinks$ === void 0 ? void 0 : _inviteLinks$.token)
        }), isInviteLinkEmpty ? /*#__PURE__*/jsxRuntime.jsx(Button__default.default, {
          className: "rounded-ss-none rounded-es-none",
          label: t("neetoTeamMembers.buttons.generateLink"),
          onClick: handleRegenerate
        }) : /*#__PURE__*/jsxRuntime.jsx(CopyToClipboardButton__default.default, {
          className: "rounded-ss-none rounded-es-none",
          label: t("neetoTeamMembers.buttons.copyLink"),
          value: RolesRadioGroup.getInviteURL(inviteLinks === null || inviteLinks === void 0 || (_inviteLinks$2 = inviteLinks[0]) === null || _inviteLinks$2 === void 0 ? void 0 : _inviteLinks$2.token)
        })]
      }), !isInviteLinkEmpty && /*#__PURE__*/jsxRuntime.jsx(Dropdown__default.default, {
        buttonProps: {
          className: "shrink-0"
        },
        buttonStyle: "text",
        icon: MenuHorizontal__default.default,
        children: /*#__PURE__*/jsxRuntime.jsx(Menu, {
          children: /*#__PURE__*/jsxRuntime.jsx(MenuItem, {
            children: /*#__PURE__*/jsxRuntime.jsx(MenuItemButton, {
              onClick: handleRegenerate,
              children: t("neetoTeamMembers.buttons.regenerateLink")
            })
          })
        })
      })]
    }), /*#__PURE__*/jsxRuntime.jsx("div", {
      children: !isInviteLinkEmpty && /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
        className: "leading-relaxed neeto-ui-text-gray-500",
        style: "body3",
        children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
          components: {
            strong: /*#__PURE__*/jsxRuntime.jsx("strong", {})
          },
          i18nKey: "neetoTeamMembers.alerts.messages.inviteLink",
          values: {
            expiryDays: RolesRadioGroup.remainingExpiryDays(inviteLinks === null || inviteLinks === void 0 || (_inviteLinks$3 = inviteLinks[0]) === null || _inviteLinks$3 === void 0 ? void 0 : _inviteLinks$3.expiresAt),
            role: inviteLinks === null || inviteLinks === void 0 || (_inviteLinks$4 = inviteLinks[0]) === null || _inviteLinks$4 === void 0 || (_inviteLinks$4 = _inviteLinks$4.organizationRole) === null || _inviteLinks$4 === void 0 ? void 0 : _inviteLinks$4.name,
            inviteLimit: inviteLinks === null || inviteLinks === void 0 || (_inviteLinks$5 = inviteLinks[0]) === null || _inviteLinks$5 === void 0 ? void 0 : _inviteLinks$5.inviteLimit,
            appName: initializers.globalProps.appName,
            emailDomain: inviteLinks === null || inviteLinks === void 0 || (_inviteLinks$6 = inviteLinks[0]) === null || _inviteLinks$6 === void 0 ? void 0 : _inviteLinks$6.domain
          }
        })
      })
    })]
  });
};
var InviteLink$1 = reactUtils.withT(InviteLink);

var MultipleEmailInput = function MultipleEmailInput(_ref) {
  var _head;
  var _ref$emails = _ref.emails,
    emails = _ref$emails === void 0 ? [] : _ref$emails,
    innerRef = _ref.innerRef,
    _ref$selectedMember = _ref.selectedMember,
    selectedMember = _ref$selectedMember === void 0 ? null : _ref$selectedMember,
    setCurrentPage = _ref.setCurrentPage;
  var isInviteLinkFeatureEnabled = !utils.isNeetoAuthApp();
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useFormikContext = formik.useFormikContext(),
    setFieldValue = _useFormikContext.setFieldValue;
  var handleInputChange = function handleInputChange(event) {
    var email = event.target.value;
    var emailList = [{
      label: email,
      value: email,
      valid: RolesRadioGroup.EMAIL_REGEX.test(email)
    }];
    setFieldValue("emails", emailList);
  };
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: "neeto-ui-w-full",
    children: selectedMember ? /*#__PURE__*/jsxRuntime.jsx(Input__default.default, {
      "data-testid": "ntm-manage-member-email-input",
      name: "emails",
      size: "medium",
      type: "email",
      value: (_head = ramda.head(emails)) === null || _head === void 0 ? void 0 : _head.value,
      label: /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "neeto-ui-w-full neeto-ui-flex neeto-ui-justify-between",
        children: /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
          component: "span",
          style: "body2",
          children: t("neetoTeamMembers.common.email", constants.SINGULAR)
        })
      }),
      onChange: handleInputChange
    }) : /*#__PURE__*/jsxRuntime.jsxs("div", {
      children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "flex items-center justify-between pb-2",
        children: [/*#__PURE__*/jsxRuntime.jsx(Label__default.default, {
          required: true,
          children: t("neetoTeamMembers.common.email", constants.PLURAL)
        }), isInviteLinkFeatureEnabled && /*#__PURE__*/jsxRuntime.jsx(Button__default.default, {
          label: t("neetoTeamMembers.buttons.inviteLink"),
          style: "link",
          onClick: function onClick() {
            return setCurrentPage(RolesRadioGroup.FORM_PAGES.INVITE_LINK);
          }
        })]
      }), /*#__PURE__*/jsxRuntime.jsx(MultiEmailInput__default.default, {
        required: true,
        counter: RolesRadioGroup.COUNTER_PROPS,
        "data-testid": "ntm-manage-member-email-input",
        filterInvalidEmails: RolesRadioGroup.FILTER_INVALID_EMAILS,
        helpText: t("neetoTeamMembers.helpers.enterMultipleEmails"),
        label: "",
        name: "emails",
        placeholder: t("neetoTeamMembers.placeholders.email"),
        ref: innerRef
      })]
    })
  });
};

var NameInputs = reactUtils.withT(function (_ref) {
  var t = _ref.t,
    innerRef = _ref.innerRef;
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "neeto-ui-flex neeto-ui-w-full neeto-ui-gap-4 pt-4 border-t mt-0 neeto-ui-border-gray-200",
    children: [/*#__PURE__*/jsxRuntime.jsx(Input__default.default, {
      "data-testid": "ntm-edit-member-first-name-text-field",
      label: t("neetoTeamMembers.labels.firstName"),
      name: "firstName",
      ref: innerRef
    }), /*#__PURE__*/jsxRuntime.jsx(Input__default.default, {
      "data-testid": "ntm-edit-member-last-name-text-field",
      label: t("neetoTeamMembers.labels.lastName"),
      name: "lastName"
    })]
  });
});

var ProfileSettings = function ProfileSettings(_ref) {
  var member = _ref.member,
    setFieldValue = _ref.setFieldValue,
    isTimezoneFieldDisabled = _ref.isTimezoneFieldDisabled;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var setFieldValueRef = React.useRef(setFieldValue);
  React.useEffect(function () {
    setFieldValueRef.current = setFieldValue;
  }, [setFieldValue]);
  var _useCountries = ProfileImage.useCountries(),
    countryDropdownOptions = _useCountries.countryDropdownOptions,
    selectedCountryOption = _useCountries.selectedCountryOption,
    isFetchingCountriesList = _useCountries.isFetchingCountriesList,
    handleCountryChange = _useCountries.handleCountryChange;
  var timezoneContainerRef = React.useRef(null);
  React.useEffect(function () {
    var node = timezoneContainerRef.current;
    if (!node) return undefined;
    new neetoTimeZones.NeetoTimezoneSelector(node, {
      isTimeFormat24H: member.timeFormat === "24h",
      className: "w-full z-10",
      position: "bottom",
      initialValue: member.timeZone,
      onChange: function onChange(_ref2) {
        var main = _ref2.main;
        return setFieldValueRef.current("timeZone", main);
      },
      disabled: isTimezoneFieldDisabled
    });
    return function () {
      node.innerHTML = "";
    };
  }, [member.timeZone, member.timeFormat, isTimezoneFieldDisabled]);
  React.useEffect(function () {
    var country = neetoCist.findBy({
      value: member.countryIdentifier
    }, countryDropdownOptions);
    if (country) handleCountryChange(country);
  }, [member.countryIdentifier, countryDropdownOptions, handleCountryChange]);
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "w-full space-y-4",
    "data-cy": "ntm-profile-settings",
    children: [/*#__PURE__*/jsxRuntime.jsx(PhoneNumber.FormikPhoneNumberInput, {
      "data-cy": "ntm-edit-member-phonenumber-field",
      label: t("neetoTeamMembers.profile.inputs.label.phonenumber"),
      name: "phonenumber"
    }), /*#__PURE__*/jsxRuntime.jsx(Select__default.default, {
      "data-cy": "ntm-edit-member-country-select",
      isLoading: isFetchingCountriesList,
      label: t("neetoTeamMembers.profile.inputs.label.country"),
      name: "countryId",
      options: countryDropdownOptions,
      value: selectedCountryOption,
      onChange: function onChange(option) {
        var dependentFields = handleCountryChange(option);
        setFieldValue("dateFormat", dependentFields === null || dependentFields === void 0 ? void 0 : dependentFields.dateFormat);
        setFieldValue("countryId", option === null || option === void 0 ? void 0 : option.value);
      }
    }), /*#__PURE__*/jsxRuntime.jsx(Select__default.default, {
      "data-cy": "ntm-edit-member-language-select",
      label: t("neetoTeamMembers.profile.inputs.label.language"),
      name: "language",
      options: constants.LANGUAGE_OPTIONS,
      onChange: function onChange(option) {
        return setFieldValue("language", option.value);
      }
    }), /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "space-y-2",
      children: [/*#__PURE__*/jsxRuntime.jsx(Label__default.default, {
        children: t("neetoTeamMembers.profile.inputs.label.timeZone")
      }), /*#__PURE__*/jsxRuntime.jsx("div", {
        "data-cy": "ntm-edit-member-timezone-select",
        ref: timezoneContainerRef,
        className: classnames__default.default("w-full grow", {
          "neeto-ui-bg-gray-100 pointer-events-none": isTimezoneFieldDisabled
        })
      })]
    }), /*#__PURE__*/jsxRuntime.jsx(Select__default.default, {
      "data-cy": "ntm-edit-member-time-format-select",
      label: t("neetoTeamMembers.profile.inputs.label.preferredTimeFormat"),
      name: "timeFormat",
      options: constants$1.TIME_FORMAT_OPTIONS,
      onChange: function onChange(option) {
        return setFieldValue("timeFormat", option.value);
      }
    }), /*#__PURE__*/jsxRuntime.jsx(Select__default.default, {
      "data-cy": "ntm-edit-member-date-format-select",
      label: t("neetoTeamMembers.profile.inputs.label.preferredDateFormat"),
      name: "dateFormat",
      options: constants$1.DATE_FORMAT_OPTIONS,
      onChange: function onChange(option) {
        return setFieldValue("dateFormat", option.value);
      }
    })]
  });
};

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__default.default(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 ManageMember = function ManageMember(_ref) {
  var _manageMemberComponen, _config$additionalFie2;
  var config = _ref.config,
    onComplete = _ref.onComplete,
    _ref$roles = _ref.roles,
    roles = _ref$roles === void 0 ? [] : _ref$roles,
    _ref$selectedMember = _ref.selectedMember,
    selectedMember = _ref$selectedMember === void 0 ? null : _ref$selectedMember,
    _ref$componentConfig = _ref.componentConfig,
    componentConfig = _ref$componentConfig === void 0 ? {} : _ref$componentConfig;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useState = React.useState(false),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    isCreationStatusPollingEnabled = _useState2[0],
    setIsCreationStatusPollingEnabled = _useState2[1];
  var isViewPermissionGranted = config.permissions.view;
  var isNotDevelopment = initializers.globalProps.railsEnv !== "development";
  var _useFetchMembers = useTeamsApi.useFetchMembers({
      enabled: isViewPermissionGranted
    }),
    team = _useFetchMembers.data;
  var _useFetchMember = useTeamsApi.useFetchMember(selectedMember === null || selectedMember === void 0 ? void 0 : selectedMember.id, {
      enabled: !!selectedMember
    }),
    memberShowData = _useFetchMember.data,
    isMemberDetailLoading = _useFetchMember.isLoading;
  var isTimezoneFieldDisabled = selectedMember && memberShowData && !selectedMember.isOwner && !memberShowData.timezoneChangeEnabled;
  var _useState3 = React.useState(RolesRadioGroup.FORM_PAGES.MAIN),
    _useState4 = _slicedToArray__default.default(_useState3, 2),
    currentPage = _useState4[0],
    setCurrentPage = _useState4[1];
  var formReference = React.useRef(null);
  var inputReference = React.useRef(null);
  var appListSavedStateReference = React.useRef({
    isAppListEnabled: true
  });
  var shouldSkipAppListPage = React.useRef(false);
  var formikValues = React.useRef(null);
  var manageMemberComponentConfig = _objectSpread(_objectSpread({}, RolesRadioGroup.DEFAULT_COMPONENT_CONFIG), {}, {
    initialFocusRef: inputReference
  }, componentConfig);
  var Component = RolesRadioGroup.MEMBERS_FORM_COMPONENT_MAPPER[manageMemberComponentConfig.type || "pane"];
  var haveToFetchRoles = ramda.isEmpty(roles) && isViewPermissionGranted;
  var isEditForm = !!selectedMember;
  var isLastPage = currentPage === RolesRadioGroup.FORM_PAGES.CONFIRMATION || isEditForm;
  var _useFetchRoles = useRolesApi.useFetchRoles({
      select: function select(response) {
        var _response$organizatio;
        return ramda.reverse((_response$organizatio = response.organizationRoles) !== null && _response$organizatio !== void 0 ? _response$organizatio : []);
      },
      enabled: haveToFetchRoles
    }),
    _useFetchRoles$data = _useFetchRoles.data,
    rolesList = _useFetchRoles$data === void 0 ? roles : _useFetchRoles$data,
    isRolesLoading = _useFetchRoles.isLoading;
  var _useFetchGlobalRoles = useRolesApi.useFetchGlobalRoles({
      select: function select(response) {
        return ramda.groupBy(ramda.prop("appName"), response !== null && response !== void 0 ? response : []);
      },
      enabled: isNotDevelopment && !selectedMember && isViewPermissionGranted
    }),
    _useFetchGlobalRoles$ = _useFetchGlobalRoles.data,
    globalRoles = _useFetchGlobalRoles$ === void 0 ? {} : _useFetchGlobalRoles$,
    isGlobalRolesLoading = _useFetchGlobalRoles.isLoading;
  var filteredRoles = utils$1.getFilteredRoles(rolesList, config);
  var _useCreateMember = useTeamsApi.useCreateMember({
      onSuccess: function onSuccess() {
        return setIsCreationStatusPollingEnabled(true);
      }
    }),
    _useCreateMember$data = _useCreateMember.data,
    _useCreateMember$data2 = _useCreateMember$data === void 0 ? {} : _useCreateMember$data,
    jobId = _useCreateMember$data2.jobId,
    createMember = _useCreateMember.mutate,
    isCreatingMember = _useCreateMember.isPending;
  var refetchInterval = function refetchInterval(query) {
    var _ref2 = query.state.data || {},
      isCompleted = _ref2.isCompleted;
    if (isCompleted) {
      setIsCreationStatusPollingEnabled(false);
      return false;
    }
    return 2000;
  };
  var _useMembersCreationSt = useTeamsApi.useMembersCreationStatus(jobId, {
      refetchInterval: refetchInterval,
      enabled: isCreationStatusPollingEnabled
    }),
    creationStatus = _useMembersCreationSt.data;
  React.useEffect(function () {
    var _config$createMember;
    var _ref3 = creationStatus || {},
      isCompleted = _ref3.isCompleted,
      isSuccessful = _ref3.isSuccessful,
      users = _ref3.users,
      error = _ref3.error;
    if (!isCompleted) return;
    handleClose();
    config === null || config === void 0 || (_config$createMember = config.createMember) === null || _config$createMember === void 0 || (_config$createMember = _config$createMember.onSuccess) === null || _config$createMember === void 0 || _config$createMember.callback({
      users: users
    });
    if (isSuccessful) {
      utils$2.showThumbsUpToastr();
    } else {
      Toastr__default.default.error(error);
    }
    useTeamsApi.refetchMembers();
  }, [creationStatus]);
  var _useUpdateMember = useTeamsApi.useUpdateMember({
      onSuccess: function onSuccess() {
        var _config$updateMember, _globalProps$user;
        handleClose(true);
        config === null || config === void 0 || (_config$updateMember = config.updateMember) === null || _config$updateMember === void 0 || (_config$updateMember = _config$updateMember.onSuccess) === null || _config$updateMember === void 0 || _config$updateMember.callback();
        if ((selectedMember === null || selectedMember === void 0 ? void 0 : selectedMember.id) === ((_globalProps$user = initializers.globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id)) {
          window.location.reload();
        }
      }
    }),
    updateMember = _useUpdateMember.mutate,
    isUpdatingMember = _useUpdateMember.isPending;
  var hasRoleChanged = function hasRoleChanged(_ref4) {
    var submitted = _ref4.submitted,
      values = _ref4.values;
    return submitted && (values === null || values === void 0 ? void 0 : values.role) !== (selectedMember === null || selectedMember === void 0 ? void 0 : selectedMember.role);
  };
  var handleClose = function handleClose() {
    var submitted = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    onComplete({
      submitted: hasRoleChanged({
        submitted: submitted,
        values: formikValues.current
      })
    });
    setCurrentPage(RolesRadioGroup.FORM_PAGES.MAIN);
    appListSavedStateReference.current = {
      isAppListEnabled: true
    };
    setIsCreationStatusPollingEnabled(false);
  };
  var _useProfileImageUploa = hooks.useProfileImageUpload({
      uploadConfig: {
        folder: "Auth",
        customMetadata: {
          appName: "neetoAuth"
        }
      }
    }),
    uploadImage = _useProfileImageUploa.uploadImage,
    isUploading = _useProfileImageUploa.isUploading;
  var handleUploadImage = /*#__PURE__*/function () {
    var _ref5 = _asyncToGenerator__default.default(/*#__PURE__*/_regeneratorRuntime__default.default.mark(function _callee(image) {
      var result, didUpload;
      return _regeneratorRuntime__default.default.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            didUpload = false;
            _context.next = 3;
            return uploadImage(image, function (uploadedImageData) {
              didUpload = true;
              result = uploadedImageData;
            });
          case 3:
            if (didUpload) {
              _context.next = 5;
              break;
            }
            throw new Error(t("neetoTeamMembers.common.imageUploadFailed"));
          case 5:
            return _context.abrupt("return", result);
          case 6:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function handleUploadImage(_x) {
      return _ref5.apply(this, arguments);
    };
  }();
  var isProcessing = isCreatingMember || isUpdatingMember || isUploading || isRolesLoading || isGlobalRolesLoading || isMemberDetailLoading;
  var handleAddMember = /*#__PURE__*/function () {
    var _ref6 = _asyncToGenerator__default.default(/*#__PURE__*/_regeneratorRuntime__default.default.mark(function _callee2(values) {
      var _values$avatar, payload, _yield$handleUploadIm, fileId, filePath, url;
      return _regeneratorRuntime__default.default.wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            if (!selectedMember) {
              _context2.next = 25;
              break;
            }
            payload = RolesRadioGroup.renderPayload(values, selectedMember);
            if (!((_values$avatar = values.avatar) !== null && _values$avatar !== void 0 && _values$avatar.file)) {
              _context2.next = 22;
              break;
            }
            if (!payload.profile) payload.profile = {};
            if (!(values.avatar.file === "_destroy")) {
              _context2.next = 8;
              break;
            }
            payload.profile.avatar = {
              fileId: "_destroy",
              filePath: "",
              url: ""
            };
            _context2.next = 22;
            break;
          case 8:
            _context2.prev = 8;
            _context2.next = 11;
            return handleUploadImage(values.avatar.file);
          case 11:
            _yield$handleUploadIm = _context2.sent;
            fileId = _yield$handleUploadIm.fileId;
            filePath = _yield$handleUploadIm.filePath;
            url = _yield$handleUploadIm.url;
            payload.profile.avatar = {
              fileId: fileId,
              filePath: filePath,
              url: url
            };
            _context2.next = 22;
            break;
          case 18:
            _context2.prev = 18;
            _context2.t0 = _context2["catch"](8);
            Toastr__default.default.error(_context2.t0.message);
            return _context2.abrupt("return");
          case 22:
            updateMember({
              id: selectedMember.id,
              payload: payload
            });
            _context2.next = 26;
            break;
          case 25:
            createMember(RolesRadioGroup.renderPayload(values));
          case 26:
          case "end":
            return _context2.stop();
        }
      }, _callee2, null, [[8, 18]]);
    }));
    return function handleAddMember(_x2) {
      return _ref6.apply(this, arguments);
    };
  }();
  var handleOnSubmit = /*#__PURE__*/function () {
    var _ref8 = _asyncToGenerator__default.default(/*#__PURE__*/_regeneratorRuntime__default.default.mark(function _callee3(values, _ref7) {
      var setSubmitting;
      return _regeneratorRuntime__default.default.wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            setSubmitting = _ref7.setSubmitting;
            shouldSkipAppListPage.current = ramda.isEmpty(values.appRoles);
            if (!isLastPage) {
              _context3.next = 7;
              break;
            }
            _context3.next = 5;
            return handleAddMember(values);
          case 5:
            _context3.next = 8;
            break;
          case 7:
            if (currentPage === RolesRadioGroup.FORM_PAGES.APP_LIST || shouldSkipAppListPage.current) {
              setCurrentPage(RolesRadioGroup.FORM_PAGES.CONFIRMATION);
              setSubmitting(false);
            } else if (currentPage === RolesRadioGroup.FORM_PAGES.MAIN) {
              setCurrentPage(RolesRadioGroup.FORM_PAGES.APP_LIST);
              setSubmitting(false);
            }
          case 8:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    }));
    return function handleOnSubmit(_x3, _x4) {
      return _ref8.apply(this, arguments);
    };
  }();
  var handleBackButton = function handleBackButton() {
    if (currentPage === RolesRadioGroup.FORM_PAGES.APP_LIST || shouldSkipAppListPage.current || currentPage === RolesRadioGroup.FORM_PAGES.INVITE_LINK) {
      setCurrentPage(RolesRadioGroup.FORM_PAGES.MAIN);
    } else if (currentPage === RolesRadioGroup.FORM_PAGES.CONFIRMATION) {
      setCurrentPage(RolesRadioGroup.FORM_PAGES.APP_LIST);
    }
  };
  var getTitle = function getTitle() {
    var memberLabel = initializers.taxonomies.member.singular;
    if (selectedMember) {
      return t("neetoTeamMembers.common.edit_", {
        what: memberLabel
      });
    }
    return currentPage === RolesRadioGroup.FORM_PAGES.INVITE_LINK ? t("neetoTeamMembers.common.inviteViaLink") : t("neetoTeamMembers.common.addNew_", {
      what: memberLabel
    });
  };
  var renderRolesRadioGroup = function renderRolesRadioGroup(role) {
    return /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "pt-4 border-t neeto-ui-border-gray-200 w-full",
      children: /*#__PURE__*/jsxRuntime.jsx(RolesRadioGroup.RolesRadioGroup, {
        config: config,
        globalRoles: globalRoles,
        role: role,
        isEdit: !!selectedMember,
        roles: filteredRoles
      })
    });
  };
  var renderFormPage = function renderFormPage(page, emails, role, setFieldValue) {
    var _memberShowData$membe, _memberShowData$membe2, _config$additionalFie;
    switch (page) {
      case RolesRadioGroup.FORM_PAGES.MAIN:
        return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
          children: [selectedMember && /*#__PURE__*/jsxRuntime.jsx(ProfileImage.ProfileImage, {}), selectedMember && /*#__PURE__*/jsxRuntime.jsx(NameInputs, {
            innerRef: inputReference
          }), /*#__PURE__*/jsxRuntime.jsx(MultipleEmailInput, {
            emails: emails,
            selectedMember: selectedMember,
            setCurrentPage: setCurrentPage,
            innerRef: inputReference
          }), selectedMember && /*#__PURE__*/jsxRuntime.jsx(ProfileSettings, {
            isTimezoneFieldDisabled: isTimezoneFieldDisabled,
            setFieldValue: setFieldValue,
            member: _objectSpread(_objectSpread({}, selectedMember), {}, {
              countryIdentifier: (_memberShowData$membe = memberShowData === null || memberShowData === void 0 || (_memberShowData$membe2 = memberShowData.member) === null || _memberShowData$membe2 === void 0 ? void 0 : _memberShowData$membe2.countryIdentifier) !== null && _memberShowData$membe !== void 0 ? _memberShowData$membe : selectedMember.countryIdentifier
            })
          }), renderRolesRadioGroup(role), (_config$additionalFie = config.additionalFields) === null || _config$additionalFie === void 0 ? void 0 : _config$additionalFie.component]
        });
      case RolesRadioGroup.FORM_PAGES.APP_LIST:
        return /*#__PURE__*/jsxRuntime.jsx(AppList, {
          globalRoles: globalRoles,
          savedStateRef: appListSavedStateReference
        });
      case RolesRadioGroup.FORM_PAGES.CONFIRMATION:
        return /*#__PURE__*/jsxRuntime.jsx(Confirmation, {});
      case RolesRadioGroup.FORM_PAGES.INVITE_LINK:
        return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
          children: [/*#__PURE__*/jsxRuntime.jsx(InviteLink$1, {
            roles: filteredRoles
          }), renderRolesRadioGroup(role)]
        });
      default:
        return null;
    }
  };
  return /*#__PURE__*/jsxRuntime.jsxs(Component, {
    className: manageMemberComponentConfig.className,
    "data-testid": "ntm-manage-members-pane-wrapper",
    initialFocusRef: manageMemberComponentConfig.initialFocusRef,
    isOpen: manageMemberComponentConfig.isOpen,
    onClose: function onClose() {
      return handleClose(false);
    },
    children: [/*#__PURE__*/jsxRuntime.jsxs(Component.Header, _objectSpread(_objectSpread({}, manageMemberComponentConfig.headerProps), {}, {
      className: classnames__default.default([{
        "ntm-manage-members__header": currentPage !== RolesRadioGroup.FORM_PAGES.MAIN
      }, (_manageMemberComponen = manageMemberComponentConfig.headerProps) === null || _manageMemberComponen === void 0 ? void 0 : _manageMemberComponen.className]),
      children: [currentPage !== RolesRadioGroup.FORM_PAGES.MAIN && /*#__PURE__*/jsxRuntime.jsx(Button__default.default, {
        "aria-label": "Back",
        icon: LeftArrow__default.default,
        size: "medium",
        style: "text",
        tooltipProps: {
          content: t("neetoTeamMembers.buttons.back"),
          position: "bottom"
        },
        onClick: handleBackButton
      }), /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
        className: "ntm-members-form__header",
        "data-testid": "ntm-manage-members-pane-header",
        style: "h2",
        weight: "semibold",
        children: getTitle()
      }), selectedMember && /*#__PURE__*/jsxRuntime.jsx(Typography__default.default, {
        className: "neeto-ui-text-gray-600",
        style: "body2",
        children: t("neetoTeamMembers.helpers.editPaneSubtitle")
      })]
    })), /*#__PURE__*/jsxRuntime.jsx(Form__default.default, {
      ref: formReference,
      formikProps: {
        enableReinitialize: true,
        initialValues: RolesRadioGroup.renderInitialValues({
          additionalFieldsInitialValues: (_config$additionalFie2 = config.additionalFields) === null || _config$additionalFie2 === void 0 ? void 0 : _config$additionalFie2.initialValues,
          globalRoles: globalRoles,
          memberShowData: memberShowData,
          roles: filteredRoles,
          selectedMember: selectedMember
        }),
        onSubmit: handleOnSubmit,
        validationSchema: RolesRadioGroup.buildValidationSchema(_objectSpread({
          selectedMember: selectedMember
        }, team))
      },
      children: function children(_ref9) {
        var _manageMemberComponen2, _manageMemberComponen3;
        var values = _ref9.values,
          isValid = _ref9.isValid,
          dirty = _ref9.dirty,
          setFieldValue = _ref9.setFieldValue;
        var emails = values.emails,
          role = values.role;
        formikValues.current = values;
        return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
          children: [/*#__PURE__*/jsxRuntime.jsx(index.ScrollToErrorField, {
            formRef: formReference
          }), /*#__PURE__*/jsxRuntime.jsxs(Component.Body, _objectSpread(_objectSpread({}, manageMemberComponentConfig.bodyProps), {}, {
            className: classnames__default.default(["ntm-members-form__body", (_manageMemberComponen2 = manageMemberComponentConfig.bodyProps) === null || _manageMemberComponen2 === void 0 ? void 0 : _manageMemberComponen2.className]),
            children: [isCreationStatusPollingEnabled && /*#__PURE__*/jsxRuntime.jsxs(Callout__default.default, {
              className: "w-full",
              icon: Info__default.default,
              style: "info",
              children: [/*#__PURE__*/jsxRuntime.jsx(Spinner__default.default, {
                size: "small"
              }), t("neetoTeamMembers.helpers.memberCreationStatus", {
                count: emails.length
              })]
            }), renderFormPage(currentPage, emails, role, setFieldValue)]
          })), currentPage !== RolesRadioGroup.FORM_PAGES.INVITE_LINK && /*#__PURE__*/jsxRuntime.jsx(Component.Footer, _objectSpread(_objectSpread({}, manageMemberComponentConfig.footerProps), {}, {
            className: classnames__default.default(["ntm-members-form__footer", (_manageMemberComponen3 = manageMemberComponentConfig.footerProps) === null || _manageMemberComponen3 === void 0 ? void 0 : _manageMemberComponen3.className]),
            children: /*#__PURE__*/jsxRuntime.jsx(ActionBlock__default.default, {
              cancelButtonProps: {
                "data-testid": "ntm-manage-member-cancel-button",
                onClick: function onClick() {
                  return handleClose(false);
                }
              },
              isSubmitting: isProcessing || isCreationStatusPollingEnabled,
              submitButtonProps: {
                "data-testid": isLastPage ? "ntm-manage-member-submit-button" : "ntm-manage-member-continue-button",
                label: isLastPage ? t("neetoTeamMembers.buttons.saveChanges") : t("neetoTeamMembers.buttons.continue"),
                disabled: !isValid || isProcessing || !dirty || isCreationStatusPollingEnabled
              }
            })
          }))]
        });
      }
    })]
  });
};

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