import { Check, Delete, DriveFileRenameOutline, Grade, Visibility, VisibilityOff } from '@mui/icons-material'; import { IconButton, TextField, Tooltip } from '@mui/material'; import clsx from 'clsx'; import get from 'lodash/get'; import { useTranslation } from 'next-i18next'; import React, { useMemo, useState } from 'react'; import sections from '@/config/sections'; import { useAppDispatch, useAppSelector } from '@/store/hooks'; import { deleteSection, setResumeState } from '@/store/resume/resumeSlice'; import styles from './Heading.module.scss'; type Props = { path: string; name?: string; isEditable?: boolean; isHideable?: boolean; isDeletable?: boolean; action?: React.ReactNode; }; const Heading: React.FC = ({ path, name, isEditable = false, isHideable = false, isDeletable = false, action, }) => { const { t } = useTranslation(); const dispatch = useAppDispatch(); const heading = useAppSelector((state) => get(state.resume, `${path}.name`, name)); const visibility = useAppSelector((state) => get(state.resume, `${path}.visible`, true)); const [editMode, setEditMode] = useState(false); const id = useMemo(() => path && path.split('.').at(-1), [path]); const icon = sections.find((x) => x.id === id)?.icon || ; const toggleVisibility = () => { dispatch(setResumeState({ path: `${path}.visible`, value: !visibility })); }; const toggleEditMode = () => setEditMode(!editMode); const handleChange = (event: React.ChangeEvent) => { dispatch(setResumeState({ path: `${path}.name`, value: event.target.value })); }; const handleDelete = () => { dispatch(deleteSection({ path })); }; return (
{icon}
{editMode ? ( ) : (

{heading}

)}
{isEditable && ( ('builder.common.tooltip.rename-section')}> {editMode ? : } )} {isHideable && ( ('builder.common.tooltip.toggle-visibility')}> {visibility ? : } )} {isDeletable && ( ('builder.common.tooltip.delete-section')}> )} {action}
); }; export default Heading;