import { BottomSheetBackdrop, type BottomSheetBackdropProps, BottomSheetModal, BottomSheetTextInput, BottomSheetView, } from "@gorhom/bottom-sheet"; import React, { useCallback, useEffect, useMemo, useRef, useState, } from "react"; import { useTranslation } from "react-i18next"; import { ActivityIndicator, Keyboard } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Button } from "@/components/Button"; import { Text } from "@/components/common/Text"; import { useCreatePlaylist } from "@/hooks/usePlaylistMutations"; interface Props { open: boolean; setOpen: (open: boolean) => void; onPlaylistCreated?: (playlistId: string) => void; initialTrackId?: string; } export const CreatePlaylistModal: React.FC = ({ open, setOpen, onPlaylistCreated, initialTrackId, }) => { const bottomSheetModalRef = useRef(null); const insets = useSafeAreaInsets(); const { t } = useTranslation(); const createPlaylist = useCreatePlaylist(); const [name, setName] = useState(""); const snapPoints = useMemo(() => ["40%"], []); useEffect(() => { if (open) { setName(""); bottomSheetModalRef.current?.present(); } else { bottomSheetModalRef.current?.dismiss(); } }, [open]); const handleSheetChanges = useCallback( (index: number) => { if (index === -1) { setOpen(false); Keyboard.dismiss(); } }, [setOpen], ); const renderBackdrop = useCallback( (props: BottomSheetBackdropProps) => ( ), [], ); const handleCreate = useCallback(async () => { if (!name.trim()) return; const result = await createPlaylist.mutateAsync({ name: name.trim(), trackIds: initialTrackId ? [initialTrackId] : undefined, }); if (result) { onPlaylistCreated?.(result); } setOpen(false); }, [name, createPlaylist, initialTrackId, onPlaylistCreated, setOpen]); const isValid = name.trim().length > 0; return ( {t("music.playlists.create_playlist")} {t("music.playlists.playlist_name")} ); };