import { ChevronRightRounded } from '@mui/icons-material' import { Box, List, ListItem, ListItemButton, ListItemText, ListSubheader, } from '@mui/material' import CircularProgress from '@mui/material/CircularProgress' import React, { ReactNode, useState } from 'react' import isAsyncFunction from '@/utils/is-async-function' interface ItemProps { 'data-setting-target'?: string label: ReactNode extra?: ReactNode children?: ReactNode secondary?: ReactNode onClick?: () => void | Promise } export const SettingItem: React.FC = ({ 'data-setting-target': searchTarget, label, extra, children, secondary, onClick, }) => { const clickable = !!onClick const primary = ( {label} {extra ? extra : null} ) const [isLoading, setIsLoading] = useState(false) const handleClick = () => { if (onClick) { if (isAsyncFunction(onClick)) { setIsLoading(true) onClick()!.finally(() => setIsLoading(false)) } else { onClick() } } } return clickable ? ( {isLoading ? ( ) : ( )} ) : ( {children} ) } export const SettingList: React.FC<{ title: string children: ReactNode }> = ({ title, children }) => ( { return { color: palette.text.primary, } }, ]} disableSticky > {title} {children} )