"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _StyledComponents = require("./StyledComponents");
var _ModalHeaderComponent = _interopRequireDefault(require("../../ModalHeaderComponent"));
var _reactRedux = require("react-redux");
var _chatSettingsSlice = require("../../../../roomStore/chatSettingsSlice");
var _Toast = require("../../../Toast");
var _user = require("../../../../networking/api-requests/user.api");
var _styledModalComponents = require("../../styledModalComponents");
var _SharedStyledComponents = require("../SharedStyledComponents");
var _RadioInput = require("./RadioInput");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const VisibilityModal = ({
  handleCloseModal
}) => {
  const dispatch = (0, _reactRedux.useDispatch)();
  const {
    user,
    config
  } = (0, _reactRedux.useSelector)(state => state.chatSettingStore);
  const doUpdateUser = user => dispatch((0, _chatSettingsSlice.setUser)(user));
  const [isProfileOpen, setIsProfileOpen] = (0, _react.useState)(user?.isProfileOpen);
  const [isAssetsOpen, setIsAssetsOpen] = (0, _react.useState)(user?.isAssetsOpen);
  const [notification, setNotification] = (0, _react.useState)(null);
  const showNotification = (message, type) => {
    setNotification({
      message,
      type
    });
    setTimeout(() => setNotification(null), 3000);
  };
  (0, _react.useEffect)(() => {
    if (isProfileOpen !== user.isProfileOpen) {
      (0, _user.updateMe)({
        isProfileOpen
      }).then(({
        data
      }) => {
        doUpdateUser(data.user);
        showNotification('Saved', 'success');
      }).catch(() => showNotification('Error', 'error'));
    }
  }, [isProfileOpen]);
  (0, _react.useEffect)(() => {
    if (isAssetsOpen !== user?.isAssetsOpen) {
      (0, _user.updateMe)({
        isAssetsOpen
      }).then(({
        data
      }) => {
        doUpdateUser(data.user);
        showNotification('Saved', 'success');
      }).catch(() => showNotification('Error', 'error'));
    }
  }, [isAssetsOpen]);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styledModalComponents.ModalContainerFullScreen, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ModalHeaderComponent.default, {
      handleCloseModal: handleCloseModal,
      headerTitle: 'Visibility'
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_SharedStyledComponents.SharedSettingsCenterContainer, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_SharedStyledComponents.SharedSettingsColumnContainer, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SharedStyledComponents.SharedSettingsStyledLabel, {
          children: "Profile Visiblility"
        }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StyledComponents.RadioGroup, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RadioLabel, {
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioInput.RadioInput, {
              option: {
                label: 'Open (default)',
                value: isProfileOpen
              },
              radioColor: config?.colors?.primary,
              checked: isProfileOpen === true,
              onChange: () => setIsProfileOpen(true)
            })
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_SharedStyledComponents.SharedSettingsLabelData, {
            children: "Your profile can be viewed by anyone who follows your profile link or QR code."
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RadioLabel, {
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioInput.RadioInput, {
              option: {
                label: 'Restricted',
                value: isProfileOpen
              },
              radioColor: config?.colors?.primary,
              checked: isProfileOpen === false,
              onChange: () => setIsProfileOpen(false)
            })
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_SharedStyledComponents.SharedSettingsLabelData, {
            children: "Only users with your permission or temporary secure link can see your profile."
          })]
        })]
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_SharedStyledComponents.SharedSettingsColumnContainer, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SharedStyledComponents.SharedSettingsStyledLabel, {
          children: "Documents Visibility"
        }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StyledComponents.RadioGroup, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RadioLabel, {
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioInput.RadioInput, {
              option: {
                label: 'Full (default)',
                value: isAssetsOpen
              },
              radioColor: config?.colors?.primary,
              checked: isAssetsOpen === true,
              onChange: () => setIsAssetsOpen(true)
            })
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_SharedStyledComponents.SharedSettingsLabelData, {
            children: "Show all Documents to those who can see your profile."
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RadioLabel, {
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioInput.RadioInput, {
              option: {
                label: 'InViewidual',
                value: isAssetsOpen
              },
              radioColor: config?.colors?.primary,
              checked: isAssetsOpen === false,
              onChange: () => setIsAssetsOpen(false)
            })
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_SharedStyledComponents.SharedSettingsLabelData, {
            children: "You need to share each document inViewidually before others can see them."
          })]
        })]
      })]
    }), notification && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.Notification, {
      type: notification.type,
      children: notification.message
    })]
  });
};
var _default = exports.default = VisibilityModal;
//# sourceMappingURL=VisibilityModal.js.map