import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover"; import { Button } from "./ui/button"; import { BackgroundIcon } from "./icons"; import { cn } from "@/lib/utils"; import Image from "next/image"; import { colors } from "@/data/colors"; import { useProjectStore } from "@/stores/project-store"; import { PipetteIcon } from "lucide-react"; type BackgroundTab = "color" | "blur"; export function BackgroundSettings() { const { activeProject, updateBackgroundType } = useProjectStore(); // ✅ Good: derive activeTab from activeProject during rendering const activeTab = activeProject?.backgroundType || "color"; const handleColorSelect = (color: string) => { updateBackgroundType("color", { backgroundColor: color }); }; const handleBlurSelect = (blurIntensity: number) => { updateBackgroundType("blur", { blurIntensity }); }; const tabs = [ { label: "Color", value: "color", }, { label: "Blur", value: "blur", }, ]; return (

Background

{tabs.map((tab) => ( { // Switch to the background type when clicking tabs if (tab.value === "color") { updateBackgroundType("color", { backgroundColor: activeProject?.backgroundColor || "#000000", }); } else { updateBackgroundType("blur", { blurIntensity: activeProject?.blurIntensity || 8, }); } }} className={cn( "text-muted-foreground cursor-pointer", activeTab === tab.value && "text-foreground" )} > {tab.label} ))}
{activeTab === "color" ? ( ) : ( )}
); } function ColorView({ selectedColor, onColorSelect, }: { selectedColor: string; onColorSelect: (color: string) => void; }) { return (
{colors.map((color) => ( onColorSelect(color)} /> ))}
); } function ColorItem({ color, isSelected, onClick, }: { color: string; isSelected: boolean; onClick: () => void; }) { return (
); } function BlurView({ selectedBlur, onBlurSelect, }: { selectedBlur: number; onBlurSelect: (blurIntensity: number) => void; }) { const blurLevels = [ { label: "Light", value: 4 }, { label: "Medium", value: 8 }, { label: "Heavy", value: 18 }, ]; const blurImage = "https://images.unsplash.com/photo-1501785888041-af3ef285b470?q=80&w=1470&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"; return (
{blurLevels.map((blur) => (
onBlurSelect(blur.value)} > {`Blur
{blur.label}
))}
); }