"use strict";

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