"use client";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { useEditor } from "@/hooks/use-editor";
import { useElementSelection } from "@/hooks/timeline/element/use-element-selection";
import { usePropertiesStore } from "./stores/properties-store";
import { getPropertiesConfig } from "./registry";
import { cn } from "@/utils/ui";
import { EmptyView } from "./empty-view";
export function PropertiesPanel() {
const editor = useEditor();
useEditor((e) => e.timeline.getTracks());
useEditor((e) => e.media.getAssets());
const { selectedElements } = useElementSelection();
const { activeTabPerType, setActiveTab } = usePropertiesStore();
if (selectedElements.length === 0) {
return (
);
}
if (selectedElements.length > 1) {
return (
{selectedElements.length} elements selected.0
);
}
const mediaAssets = editor.media.getAssets();
const elementsWithTracks = editor.timeline.getElementsWithTracks({
elements: selectedElements,
});
const elementWithTrack = elementsWithTracks[0];
if (!elementWithTrack) return null;
const { element, track } = elementWithTrack;
const config = getPropertiesConfig({ element, mediaAssets });
const visibleTabs = config.tabs;
const storedTabId = activeTabPerType[element.type];
const isStoredTabVisible = visibleTabs.some((t) => t.id === storedTabId);
const activeTabId = isStoredTabVisible ? storedTabId : config.defaultTab;
const activeTab =
visibleTabs.find((t) => t.id === activeTabId) ?? visibleTabs[0];
if (!activeTab) return null;
return (
{visibleTabs.map((tab) => (
{tab.label}
))}
{activeTab.content({ trackId: track.id })}
);
}