import React from 'react';
import { Typography } from '@mui/material';
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import Toast from '@arcblock/ux/lib/Toast';
import SwitchControl from '../../component/switch-control';
import { useBlockletStorageContext } from '../../../contexts/blocklet-storage';

/**
 * @description
 * @param {{
 *  style: import('react').CSSProperties
 * }} {...rest}
 * @return {*}
 */
import { jsx as _jsx } from "react/jsx-runtime";
function AutoBackup({
  ...rest
}) {
  const {
    t
  } = useLocaleContext();
  const {
    autoBackup,
    updateAutoBackup
  } = useBlockletStorageContext();
  const configAutoBackup = async () => {
    try {
      const enabled = !autoBackup?.enabled;
      await updateAutoBackup({
        enabled
      });
      Toast.success(enabled ? t('storage.spaces.autoBackup.enabled') : t('storage.spaces.autoBackup.disabled'));
    } catch (error) {
      Toast.error(error.message);
    }
  };
  return /*#__PURE__*/_jsx(SwitchControl, {
    checked: Boolean(autoBackup?.enabled),
    onChange: configAutoBackup,
    name: "enableWelcomePage",
    labelProps: {
      label: /*#__PURE__*/_jsx(Typography, {
        sx: {
          marginRight: '8px'
        },
        children: /*#__PURE__*/_jsx("span", {
          children: t('storage.spaces.autoBackup.title')
        })
      })
    },
    style: {
      ...rest.style
    }
  });
}
export default AutoBackup;