import {
Blend,
Clapperboard,
FlipHorizontal2,
Music,
Package,
Palette,
Scissors,
Sparkles,
Sticker,
Subtitles,
Type,
Video,
X,
} from "lucide-react"
import { useTranslation } from "react-i18next"
import { Button } from "@/components/ui/button"
import { DraggableType, useDraggable } from "@/features/drag-drop"
import { useResources } from "@/features/resources"
import { TimelineResource } from "@/features/resources/types"
/**
* Компонент для отдельного ресурса с поддержкой drag
*/
function ResourceItem({ resource, onRemove }: { resource: TimelineResource; onRemove: (id: string) => void }) {
const { t } = useTranslation()
// Определяем тип для DragDropManager
const getDraggableType = (resourceType: TimelineResource["type"]): DraggableType => {
switch (resourceType) {
case "media":
return "media"
case "music":
return "music"
case "effect":
return "effect"
case "filter":
return "filter"
case "transition":
return "transition"
case "template":
return "template"
case "styleTemplate":
return "style-template"
case "subtitle":
return "subtitle-style"
default:
return "media"
}
}
// Получаем данные для перетаскивания в зависимости от типа ресурса
const getDragData = () => {
if (resource.type === "media" || resource.type === "music") {
return resource.file
}
if (resource.type === "effect") {
return resource.effect
}
if (resource.type === "filter") {
return resource.filter
}
if (resource.type === "transition") {
return resource.transition
}
if (resource.type === "template") {
return resource.template
}
if (resource.type === "styleTemplate") {
return resource.template
}
if (resource.type === "subtitle") {
return resource.style
}
return null
}
// Получаем URL для превью
const getPreviewUrl = () => {
const data = getDragData()
if (!data) return ""
if ("path" in data) return data.path
if ("thumbnail" in data) return data.thumbnail
return ""
}
// Используем DragDropManager для перетаскивания
const dragProps = useDraggable(getDraggableType(resource.type), getDragData, () => ({
url: getPreviewUrl(),
width: 120,
height: 80,
}))
return (
{/* Иконка ресурса (слева) */}
{resource.type === "media" &&
}
{resource.type === "music" &&
}
{resource.type === "subtitle" &&
}
{resource.type === "effect" &&
}
{resource.type === "filter" &&
}
{resource.type === "transition" &&
}
{resource.type === "template" &&
}
{resource.type === "styleTemplate" &&
}
{/* Название ресурса (справа) */}
{resource.type === "template"
? t(`templates.templateLabels.${resource.name}`, resource.name)
: resource.type === "styleTemplate"
? t(`styleTemplates.${resource.name}`, resource.name)
: resource.name}
{/* Кнопка удаления - показывается при наведении */}
)
}
/**
* Компонент для отображения ресурсов таймлайна в левой панели
*/
export function ResourcesPanel() {
const { t } = useTranslation()
// Полностью отключаем логирование
const {
effectResources,
filterResources,
transitionResources,
templateResources,
styleTemplateResources,
mediaResources,
musicResources,
subtitleResources,
removeResource,
} = useResources()
// Полностью отключаем логирование
// Категории ресурсов с их данными
const categories = [
{
id: "media",
name: t("browser.tabs.media"),
icon: ,
resources: mediaResources,
},
{
id: "music",
name: t("browser.tabs.music"),
icon: ,
resources: musicResources,
},
{
id: "subtitles",
name: t("browser.tabs.subtitles"),
icon: ,
resources: subtitleResources,
},
{
id: "effects",
name: t("browser.tabs.effects"),
icon: ,
resources: effectResources,
},
{
id: "filters",
name: t("browser.tabs.filters"),
icon: ,
resources: filterResources,
},
{
id: "transitions",
name: t("browser.tabs.transitions"),
icon: ,
resources: transitionResources,
},
{
id: "templates",
name: t("browser.tabs.templates"),
icon: ,
resources: templateResources,
},
{
id: "styleTemplates",
name: t("browser.tabs.styleTemplates"),
icon: ,
resources: styleTemplateResources,
},
]
// Функция для отображения списка ресурсов
const renderResourceList = (resources: TimelineResource[]) => {
if (resources.length === 0) {
return null // Если ресурсов нет, не показываем ничего
}
return (
{resources.map((resource) => (
))}
)
}
return (
{/* Header */}
{t("timeline.resources.title", "Ресурсы")}
{/* Прокручиваемый контейнер для всех категорий */}
{categories.map((category) => (
{/* Заголовок категории */}
{category.icon}
{category.name}
{category.resources.length > 0 && (
({category.resources.length})
)}
{/* Список ресурсов категории */}
{renderResourceList(category.resources)}
{/* Сообщение, если нет ресурсов */}
{category.resources.length === 0 && (
{t("timeline.resources.noResources", "Нет добавленных ресурсов")}
)}
))}
)
}