import React from "react" import { useFavorites } from "@/features/app-state" import { SubtitlePreview } from "@/features/subtitles/components/subtitle-preview" import { useSubtitles } from "@/features/subtitles/hooks/use-subtitle-styles" import { SubtitleStyleTemplate } from "@/features/subtitles/types/subtitles" import type { ListAdapter, ListItem, PreviewComponentProps } from "../types/list" // Адаптер типа для SubtitleStyleTemplate чтобы соответствовать ListItem type SubtitleListItem = SubtitleStyleTemplate & ListItem /** * Компонент превью для стилей субтитров */ const SubtitlePreviewWrapper: React.FC> = ({ item: style, size, viewMode, onClick, onDragStart, }) => { const handleClick = () => { onClick?.(style) } const handleDragStart = (e: React.DragEvent) => { onDragStart?.(style, e) } // Для стилей субтитров SubtitlePreview ожидает другие пропсы const previewSize = typeof size === "number" ? size : size.width const previewWidth = typeof size === "number" ? size : size.width const previewHeight = typeof size === "number" ? size : size.height if (viewMode === "list") { return (
{/* Subtitle preview sample */}
Abc
{/* Style Info */}
{style.labels?.ru || style.labels?.en || style.name}
{style.description?.ru || style.description?.en || ""}
{/* Category */}
{style.category}
{/* Complexity */}
{style.complexity}
{/* Font Family */}
{style.style.fontFamily || "default"}
) } // Thumbnails mode - use the original SubtitlePreview component return (
) } /** * Хук для создания адаптера стилей субтитров */ export function useSubtitlesAdapter(): ListAdapter { const { subtitles, loading, error } = useSubtitles() const { isItemFavorite } = useFavorites() return { // Хук для получения данных useData: () => ({ items: subtitles, loading, error: error ? new Error(error) : null, }), // Компонент превью PreviewComponent: SubtitlePreviewWrapper, // Функция для получения значения сортировки getSortValue: (style, sortBy) => { switch (sortBy) { case "name": return (style.labels?.ru || style.labels?.en || style.name).toLowerCase() case "category": return style.category.toLowerCase() case "complexity": // Определяем порядок сложности: basic < intermediate < advanced const complexityOrder = { basic: 0, intermediate: 1, advanced: 2 } return complexityOrder[style.complexity || "basic"] case "font": return (style.style.fontFamily || "default").toLowerCase() default: return (style.labels?.ru || style.labels?.en || style.name).toLowerCase() } }, // Функция для получения текста для поиска getSearchableText: (style) => { const texts = [ style.name, style.labels?.ru || "", style.labels?.en || "", style.description?.ru || "", style.description?.en || "", style.category, style.style.fontFamily || "", ...(style.tags || []), ] return texts.filter(Boolean) }, // Функция для получения значения группировки getGroupValue: (style, groupBy) => { switch (groupBy) { case "category": return style.category || "other" case "complexity": return style.complexity || "basic" case "font": return style.style.fontFamily || "default" case "tags": // Группируем по первому тегу или "untagged" return style.tags && style.tags.length > 0 ? style.tags[0] : "untagged" default: return "" } }, // Функция для фильтрации по типу matchesFilter: (style, filterType) => { if (filterType === "all") return true // Фильтрация по сложности if (["basic", "intermediate", "advanced"].includes(filterType)) { return (style.complexity || "basic") === filterType } // Фильтрация по категории if (["basic", "cinematic", "stylized", "minimal", "animated", "modern"].includes(filterType)) { return style.category === filterType } return true }, // Обработчики импорта не нужны для стилей субтитров (они встроенные) importHandlers: undefined, // Проверка избранного isFavorite: (style) => isItemFavorite(style, "subtitle"), // Тип для системы избранного favoriteType: "subtitle", } }