import { Ionicons } from "@expo/vector-icons"; import { BottomSheetBackdrop, type BottomSheetBackdropProps, BottomSheetModal, BottomSheetView, } from "@gorhom/bottom-sheet"; import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import React, { useCallback, useEffect, useMemo, useRef } from "react"; import { useTranslation } from "react-i18next"; import { Alert, StyleSheet, TouchableOpacity, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Text } from "@/components/common/Text"; import useRouter from "@/hooks/useAppRouter"; import { useDeletePlaylist } from "@/hooks/usePlaylistMutations"; interface Props { open: boolean; setOpen: (open: boolean) => void; playlist: BaseItemDto | null; } export const PlaylistOptionsSheet: React.FC = ({ open, setOpen, playlist, }) => { const bottomSheetModalRef = useRef(null); const router = useRouter(); const insets = useSafeAreaInsets(); const { t } = useTranslation(); const deletePlaylist = useDeletePlaylist(); const snapPoints = useMemo(() => ["25%"], []); useEffect(() => { if (open) bottomSheetModalRef.current?.present(); else bottomSheetModalRef.current?.dismiss(); }, [open]); const handleSheetChanges = useCallback( (index: number) => { if (index === -1) { setOpen(false); } }, [setOpen], ); const renderBackdrop = useCallback( (props: BottomSheetBackdropProps) => ( ), [], ); const handleDeletePlaylist = useCallback(() => { if (!playlist?.Id) return; Alert.alert( t("music.playlists.delete_playlist"), t("music.playlists.delete_confirm", { name: playlist.Name }), [ { text: t("common.cancel"), style: "cancel", }, { text: t("common.delete"), style: "destructive", onPress: () => { deletePlaylist.mutate( { playlistId: playlist.Id! }, { onSuccess: () => { setOpen(false); router.back(); }, }, ); }, }, ], ); }, [playlist, deletePlaylist, setOpen, router, t]); if (!playlist) return null; return ( {t("music.playlists.delete_playlist")} ); }; const _styles = StyleSheet.create({ separator: { height: StyleSheet.hairlineWidth, backgroundColor: "#404040", }, });