import { router, useForm } from '@inertiajs/react';
import { ChevronDown, Clapperboard, Trash2 } from 'lucide-react';
import type { FormEvent } from 'react';
import { useState } from 'react';
import VideoSectionController from '@/actions/App/Http/Controllers/VideoSectionController';
import InputError from '@/components/input-error';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import type { HomeSectionInfo, Store, VideoSectionInfo } from '@/types';
const selectClass =
'h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50 md:text-sm';
/** The picture YouTube shows for a video, to preview the link. Null for Vimeo or a link that is not a video yet. */
function youtubePicture(url: string): string | null {
const match = url.match(
/^https:\/\/(?:(?:www\.|m\.)?youtube\.com\/(?:watch\?v=|shorts\/)|youtu\.be\/)([A-Za-z0-9_-]{6,20})/,
);
return match ? `https://i.ytimg.com/vi/${match[1]}/mqdefault.jpg` : null;
}
/**
* The Design tab's Video box: add a YouTube or Vimeo video, change it, or remove it.
*/
export default function VideoBox({
store,
videos,
homeSections,
busy,
}: {
store: Store;
videos: VideoSectionInfo[];
homeSections: HomeSectionInfo[];
busy: boolean;
}) {
return (