exercise-video-modal.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use client";
  2. import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
  3. import { getYouTubeEmbedUrl } from "@/shared/lib/youtube";
  4. import { useI18n } from "locales/client";
  5. interface ExerciseVideoModalProps {
  6. open: boolean;
  7. onOpenChange: (open: boolean) => void;
  8. videoUrl: string;
  9. title: string;
  10. }
  11. export function ExerciseVideoModal({ open, onOpenChange, videoUrl, title }: ExerciseVideoModalProps) {
  12. const youTubeEmbedUrl = getYouTubeEmbedUrl(videoUrl);
  13. const t = useI18n();
  14. return (
  15. <Dialog onOpenChange={onOpenChange} open={open}>
  16. <DialogContent className="max-w-xl p-0 overflow-hidden">
  17. <DialogHeader className="flex flex-row items-center justify-between px-4 pt-4 pb-2">
  18. <DialogTitle className="text-base">{title}</DialogTitle>
  19. </DialogHeader>
  20. <div className="w-full aspect-video bg-black flex items-center justify-center">
  21. {videoUrl ? (
  22. youTubeEmbedUrl ? (
  23. <iframe
  24. allow="autoplay; encrypted-media"
  25. allowFullScreen
  26. className="w-full h-full border-0"
  27. src={youTubeEmbedUrl}
  28. title={title}
  29. />
  30. ) : (
  31. <video
  32. autoPlay
  33. className="w-full h-full object-contain bg-black"
  34. controls
  35. poster=""
  36. src={videoUrl}
  37. />
  38. )
  39. ) : (
  40. <div className="text-white text-center p-8">
  41. {t("workout_builder.exercise.no_video_available")}
  42. </div>
  43. )}
  44. </div>
  45. </DialogContent>
  46. </Dialog>
  47. );
  48. }