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' 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: 'image', label: 'تصویر' }, ] const SettingsPanel = () => { const { documentSettings, pages, currentPageId, updateDocumentSettings, updateCurrentPageBackground, } = useEditorStore() const colorInputRef = useRef(null) const { mutateAsync: uploadFile, isPending: imageLoading } = useSingleUpload() const currentPage = pages.find((page) => page.id === currentPageId) const backgroundType = currentPage?.backgroundType ?? 'color' const backgroundColor = currentPage?.backgroundColor ?? '#ffffff' const backgroundImageUrl = currentPage?.backgroundImageUrl ?? '' const [uploadedPreviews, setUploadedPreviews] = useState( backgroundImageUrl ? [backgroundImageUrl] : [] ) const { displayStyle, autoPlay, pageFlipSound, leftToRightFlip, } = documentSettings useEffect(() => { setUploadedPreviews( backgroundImageUrl ? [backgroundImageUrl] : [] ) }, [backgroundImageUrl]) 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 handlePreviewChange = (previews: string[]) => { setUploadedPreviews(previews) if (previews.length === 0) { updateCurrentPageBackground({ backgroundImageUrl: '' }) } } return (
{/* ─── تنظیمات نمایش ─── */}

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

{/* استایل نمایش */}
{/* چک‌باکس‌ها */}
updateDocumentSettings({ autoPlay: v })} /> updateDocumentSettings({ pageFlipSound: v })} /> updateDocumentSettings({ leftToRightFlip: v })} />
{/* ─── پس زمینه ─── */}

پس زمینه

{/* نوع پس‌زمینه */}
{BACKGROUND_TYPE_OPTIONS.map((opt) => (
) } type CheckboxRowProps = { label: string checked: boolean onChange: (value: boolean) => void } const CheckboxRow = ({ label, checked, onChange }: CheckboxRowProps) => ( ) export default SettingsPanel