2025-06-22 19:28:03 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useTimelineStore } from "@/stores/timeline-store";
|
|
|
|
|
import { useMediaStore } from "@/stores/media-store";
|
2025-06-23 09:18:15 +03:00
|
|
|
import { usePlaybackStore } from "@/stores/playback-store";
|
2025-06-22 19:28:03 +02:00
|
|
|
import { ImageTimelineTreatment } from "@/components/ui/image-timeline-treatment";
|
2025-06-23 09:18:15 +03:00
|
|
|
import { VideoPlayer } from "@/components/ui/video-player";
|
2025-06-22 19:28:03 +02:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Play, Pause } from "lucide-react";
|
|
|
|
|
|
2025-06-22 10:02:50 +02:00
|
|
|
export function PreviewPanel() {
|
2025-06-22 19:28:03 +02:00
|
|
|
const { tracks } = useTimelineStore();
|
|
|
|
|
const { mediaItems } = useMediaStore();
|
2025-06-23 09:18:15 +03:00
|
|
|
const { isPlaying, toggle } = usePlaybackStore();
|
2025-06-22 19:28:03 +02:00
|
|
|
|
|
|
|
|
const firstClip = tracks[0]?.clips[0];
|
|
|
|
|
const firstMediaItem = firstClip
|
|
|
|
|
? mediaItems.find((item) => item.id === firstClip.mediaId)
|
|
|
|
|
: null;
|
|
|
|
|
|
2025-06-22 22:10:50 +02:00
|
|
|
const aspectRatio = firstMediaItem?.aspectRatio || 16 / 9;
|
|
|
|
|
|
2025-06-23 09:18:15 +03:00
|
|
|
const renderContent = () => {
|
2025-06-22 19:28:03 +02:00
|
|
|
if (!firstMediaItem) {
|
|
|
|
|
return (
|
2025-06-23 09:18:15 +03:00
|
|
|
<div className="absolute inset-0 flex items-center justify-center text-muted-foreground/50">
|
|
|
|
|
Drop media to start editing
|
2025-06-22 10:02:50 +02:00
|
|
|
</div>
|
2025-06-22 19:28:03 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 09:18:15 +03:00
|
|
|
if (firstMediaItem.type === "video") {
|
|
|
|
|
return (
|
|
|
|
|
<VideoPlayer
|
|
|
|
|
src={firstMediaItem.url}
|
|
|
|
|
poster={firstMediaItem.thumbnailUrl}
|
|
|
|
|
className="w-full h-full"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-22 19:28:03 +02:00
|
|
|
if (firstMediaItem.type === "image") {
|
|
|
|
|
return (
|
|
|
|
|
<ImageTimelineTreatment
|
|
|
|
|
src={firstMediaItem.url}
|
|
|
|
|
alt={firstMediaItem.name}
|
2025-06-22 22:10:50 +02:00
|
|
|
targetAspectRatio={aspectRatio}
|
2025-06-23 09:18:15 +03:00
|
|
|
className="w-full h-full"
|
2025-06-22 19:28:03 +02:00
|
|
|
backgroundType="blur"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (firstMediaItem.type === "audio") {
|
|
|
|
|
return (
|
|
|
|
|
<div className="absolute inset-0 flex items-center justify-center bg-gradient-to-br from-green-500/20 to-emerald-500/20">
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
<div className="text-6xl mb-4">🎵</div>
|
|
|
|
|
<p className="text-muted-foreground">{firstMediaItem.name}</p>
|
2025-06-23 09:18:15 +03:00
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="mt-4"
|
|
|
|
|
onClick={toggle}
|
|
|
|
|
>
|
|
|
|
|
{isPlaying ? <Pause className="h-4 w-4 mr-2" /> : <Play className="h-4 w-4 mr-2" />}
|
|
|
|
|
{isPlaying ? "Pause" : "Play"}
|
|
|
|
|
</Button>
|
2025-06-22 19:28:03 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2025-06-22 22:10:50 +02:00
|
|
|
<div className="h-full flex flex-col items-center justify-center p-4 overflow-hidden">
|
|
|
|
|
<div
|
2025-06-23 09:18:15 +03:00
|
|
|
className="bg-black rounded-lg shadow-lg relative overflow-hidden flex-shrink-0"
|
2025-06-22 22:10:50 +02:00
|
|
|
style={{
|
|
|
|
|
aspectRatio: aspectRatio.toString(),
|
|
|
|
|
width: aspectRatio > 1 ? "100%" : "auto",
|
|
|
|
|
height: aspectRatio <= 1 ? "100%" : "auto",
|
|
|
|
|
maxWidth: "100%",
|
|
|
|
|
maxHeight: "100%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-06-23 09:18:15 +03:00
|
|
|
{renderContent()}
|
2025-06-22 10:02:50 +02:00
|
|
|
</div>
|
2025-06-22 19:28:03 +02:00
|
|
|
|
|
|
|
|
{firstMediaItem && (
|
|
|
|
|
<div className="mt-4 text-center">
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
2025-06-23 09:18:15 +03:00
|
|
|
{firstMediaItem.name}
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-xs text-muted-foreground/70">
|
|
|
|
|
{aspectRatio.toFixed(2)} • {aspectRatio > 1 ? "Landscape" : aspectRatio < 1 ? "Portrait" : "Square"}
|
2025-06-22 19:28:03 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-06-22 10:02:50 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|