import { useEffect, useRef, useState } from 'react' import { clx } from '@/helpers/utils' import { useEditorStore } from '../store/editorStore' import type { DisplayStyle, BackgroundType } from '../store/editorStore' import UploadBoxDraggble from '@/components/UploadBoxDraggble' import { useSingleUpload } from '@/pages/uploader/hooks/useUploaderData' import ColorsImage from '@/assets/images/colors.png' import ColorPicker from '@/components/ColorPicker' import Select from '@/components/Select' import { toCssLinearGradient } from '../utils/gradient' const PRESET_COLORS = [ '#a8edcf', '#e91e8c', '#ff9800', '#6d8b8b', '#111111', '#e53935', '#e0e0e0', ] const DISPLAY_STYLE_OPTIONS: { value: DisplayStyle; label: string }[] = [ { value: 'single', label: 'تک صفحه ای' }, { value: 'double', label: 'دو صفحه ای' }, ] const BACKGROUND_TYPE_OPTIONS: { value: BackgroundType; label: string }[] = [ { value: 'color', label: 'رنگ' }, { value: 'gradient', label: 'گرادیانت' }, { value: 'image', label: 'تصویر' }, { value: 'video', label: 'ویدیو' }, ] const SettingsPanel = () => { const { documentSettings, pages, currentPageId, updateDocumentSettings, updateCurrentPageBackground, } = useEditorStore() const colorInputRef = useRef(null) const { mutateAsync: uploadFile, isPending: mediaLoading } = useSingleUpload() const currentPage = pages.find((page) => page.id === currentPageId) const backgroundType = currentPage?.backgroundType ?? 'color' const backgroundColor = currentPage?.backgroundColor ?? '#ffffff' const backgroundGradient = currentPage?.backgroundGradient ?? { from: '#ffffff', to: '#e2e8f0', angle: 135, } const backgroundImageUrl = currentPage?.backgroundImageUrl ?? '' const backgroundVideoUrl = currentPage?.backgroundVideoUrl ?? '' const [uploadedPreviews, setUploadedPreviews] = useState( backgroundImageUrl ? [backgroundImageUrl] : [] ) const { displayStyle, autoPlay, pageFlipSound, smartGuide, // leftToRightFlip, } = documentSettings useEffect(() => { setUploadedPreviews( backgroundImageUrl ? [backgroundImageUrl] : [] ) }, [backgroundImageUrl]) useEffect(() => { if (backgroundType !== 'video') return setUploadedPreviews(backgroundVideoUrl ? [backgroundVideoUrl] : []) }, [backgroundType, backgroundVideoUrl]) const handleImageFiles = async (files: File[]) => { if (files.length === 0) return const file = files[files.length - 1] if (!file) return try { const result = await uploadFile({ file }) const imageUrl = result?.data?.url if (!imageUrl) return updateCurrentPageBackground({ backgroundImageUrl: imageUrl }) setUploadedPreviews([imageUrl]) } catch { // TODO: show error toast } } const handleVideoFiles = async (files: File[]) => { if (files.length === 0) return const file = files[files.length - 1] if (!file) return try { const result = await uploadFile({ file }) const videoUrl = result?.data?.url if (!videoUrl) return updateCurrentPageBackground({ backgroundVideoUrl: videoUrl }) setUploadedPreviews([videoUrl]) } catch { // TODO: show error toast } } const handlePreviewChange = (previews: string[]) => { setUploadedPreviews(previews) if (previews.length === 0) { if (backgroundType === 'image') { updateCurrentPageBackground({ backgroundImageUrl: '' }) } else if (backgroundType === 'video') { updateCurrentPageBackground({ backgroundVideoUrl: '' }) } } } return (
{/* ─── تنظیمات نمایش ─── */}

تنظیمات نمایش

{/* استایل نمایش */}
updateCurrentPageBackground({ backgroundColor: e.target.value })} className="absolute inset-0 opacity-0 w-full h-full cursor-pointer" />
{/* نمایش رنگ انتخاب‌شده */}
{backgroundColor}
)} {backgroundType === 'gradient' && (

گرادیانت خطی

updateCurrentPageBackground({ backgroundGradient: { ...backgroundGradient, from: value }, }) } /> updateCurrentPageBackground({ backgroundGradient: { ...backgroundGradient, to: value }, }) } />
updateCurrentPageBackground({ backgroundGradient: { ...backgroundGradient, angle: Number(e.target.value), }, }) } className="w-full" /> updateCurrentPageBackground({ backgroundGradient: { ...backgroundGradient, angle: Number(e.target.value) || 0, }, }) } className="w-16 h-9 rounded-lg border border-border px-2 text-xs" />
)} {/* ─── آپلود تصویر ─── */} {backgroundType === 'image' && (
{mediaLoading ? (
در حال آپلود...
) : ( )}
)} {backgroundType === 'video' && (
{mediaLoading ? (
در حال آپلود...
) : ( )} {backgroundVideoUrl && (
)}
)}
) } type CheckboxRowProps = { label: string checked: boolean onChange: (value: boolean) => void } const CheckboxRow = ({ label, checked, onChange }: CheckboxRowProps) => ( ) export default SettingsPanel