/** * File: CommentForm.tsx * Created by: AI Assistant * Date: 2025-11-29 * Purpose: Comment form with file upload and privacy controls for kreatiVortex platform * Part of: kreatiVortex - Platform Pembelajaran Tari Online */ 'use client'; import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { uploadFile, isAllowedFileType, formatFileSize, UploadedFile } from '@/lib/upload'; interface CommentFormProps { onSubmit: (content: string, attachments: UploadedFile[], isPrivate?: boolean) => void; placeholder?: string; buttonText?: string; loading?: boolean; showPrivacyToggle?: boolean; isEducator?: boolean; } export default function CommentForm({ onSubmit, placeholder = "Tulis komentar...", buttonText = "Kirim Komentar", loading = false, showPrivacyToggle = false, isEducator = false }: CommentFormProps) { const [content, setContent] = useState(''); const [attachments, setAttachments] = useState([]); const [isPrivate, setIsPrivate] = useState(false); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (content.trim() || attachments.length > 0) { onSubmit(content.trim(), attachments, isPrivate); setContent(''); setAttachments([]); setIsPrivate(false); } }; const handleFileUpload = async (e: React.ChangeEvent) => { const files = e.target.files; if (!files) return; const newAttachments: UploadedFile[] = []; for (let i = 0; i < files.length; i++) { const file = files[i]; if (!isAllowedFileType(file)) { alert(`File ${file.name} tidak diizinkan. Hanya PDF, Word, dan file gambar yang diperbolehkan.`); continue; } if (file.size > 10 * 1024 * 1024) { // 10MB limit alert(`File ${file.name} terlalu besar. Maksimal ukuran file adalah 10MB.`); continue; } try { const uploadedFile = await uploadFile(file, 'comment-attachments'); newAttachments.push(uploadedFile); } catch (error) { console.error('Error uploading file:', error); alert(`Gagal mengupload file ${file.name}`); } } setAttachments(prev => [...prev, ...newAttachments]); }; const removeAttachment = (index: number) => { setAttachments(prev => prev.filter((_, i) => i !== index)); }; return (