import { motion, Reorder, useDragControls } from "framer-motion";
import { Eye, EyeOff, GripVertical, Trash2 } from "lucide-react";
import { cn } from "@/lib/utils";
import { MenuSection } from "@/types/resume";
import { useTranslations } from "@/i18n/compat/client";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
interface LayoutItemProps {
item: MenuSection;
isBasic?: boolean;
activeSection: string;
setActiveSection: (id: string) => void;
toggleSectionVisibility: (id: string) => void;
updateMenuSections: (sections: MenuSection[]) => void;
removeCustomData: (sectionId: string) => void;
menuSections: MenuSection[];
}
const LayoutItem = ({
item,
isBasic = false,
activeSection,
setActiveSection,
toggleSectionVisibility,
updateMenuSections,
removeCustomData,
menuSections
}: LayoutItemProps) => {
const dragControls = useDragControls();
const t = useTranslations("common");
if (isBasic) {
return (
setActiveSection(item.id)}
>
{item.icon}
{item.title}
);
}
return (
{
dragControls.start(event);
}}
className={cn(
"w-8 flex items-center justify-center touch-none shrink-0",
"border-border",
"cursor-grab hover:bg-muted/50"
)}
>
setActiveSection(item.id)}
>
{item.icon}
{item.title}
{
e.stopPropagation();
toggleSectionVisibility(item.id);
}}
className={cn(
"p-1.5 rounded-md mr-2",
"hover:bg-muted text-muted-foreground hover:text-foreground transition-colors"
)}
>
{item.enabled ? (
) : (
)}
e.stopPropagation()}
className={cn(
"p-1.5 rounded-md text-primary",
"hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
)}
>
e.stopPropagation()}>
{t("delete")} {item.title}
{t("deleteModuleConfirm")}
e.stopPropagation()}>{t("cancel")}
{
e.stopPropagation();
const updatedSections = menuSections.filter(
(section) => section.id !== item.id
);
const currentIndex = menuSections.findIndex(
(section) => section.id === item.id
);
const fallbackSection =
menuSections[currentIndex - 1] ?? updatedSections[0];
updateMenuSections(updatedSections);
if (item.id.startsWith("custom")) {
removeCustomData(item.id);
}
if (fallbackSection) {
setActiveSection(fallbackSection.id);
}
}}
className="bg-gradient-to-r from-rose-500 to-orange-400 hover:from-rose-600 hover:to-orange-500 text-white shadow-sm border-0"
>
{t("confirm")}
);
};
export default LayoutItem;