import InputError from '@/components/input-error'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Textarea } from '@/components/ui/textarea'; import { useForm } from '@inertiajs/react'; import { Save } from 'lucide-react'; import { useState } from 'react'; import CertificatePreview from './certificate-preview'; const CertificateBuilderForm = ({ template }: { template?: CertificateTemplate | null }) => { const [logoPreview, setLogoPreview] = useState(template?.logo_path); const { data, setData, post, processing, errors } = useForm({ type: template?.type || 'course', name: template?.name || 'My Certificate Template', logo: null as File | null, template_data: template?.template_data || { primaryColor: '#3730a3', secondaryColor: '#4b5563', backgroundColor: '#dbeafe', borderColor: '#f59e0b', titleText: 'Certificate of Completion', descriptionText: 'This certificate is proudly presented to', completionText: 'for successfully completing the course', footerText: 'Authorized Certificate', fontFamily: 'serif', }, }); const onLogoChange = (name: string, value: unknown) => { setData(name as any, value as any); setLogoPreview(URL.createObjectURL(value as File)); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (template) { // Update existing template post(route('certificate.templates.update', template.id)); } else { // Create new template post(route('certificate.templates.store')); } }; return (
{/* Form Section */}
Basic Information Set the template name and activation status
{errors.type &&

{errors.type}

}
setData('name', e.target.value)} placeholder="e.g., Modern Blue Certificate" /> {errors.name &&

{errors.name}

}
Logo & Branding Upload your institution or course logo
{logoPreview && (
Logo preview
)}
onLogoChange('logo', e.target.files?.[0])} />

Recommended: PNG or SVG, max 1MB

Colors Customize the certificate color scheme
setData('template_data', { ...data.template_data, primaryColor: e.target.value })} className="h-10 w-16" /> setData('template_data', { ...data.template_data, primaryColor: e.target.value })} placeholder="#3730a3" />
setData('template_data', { ...data.template_data, secondaryColor: e.target.value })} className="h-10 w-16" /> setData('template_data', { ...data.template_data, secondaryColor: e.target.value })} placeholder="#4b5563" />
setData('template_data', { ...data.template_data, backgroundColor: e.target.value })} className="h-10 w-16" /> setData('template_data', { ...data.template_data, backgroundColor: e.target.value })} placeholder="#dbeafe" />
setData('template_data', { ...data.template_data, borderColor: e.target.value })} className="h-10 w-16" /> setData('template_data', { ...data.template_data, borderColor: e.target.value })} placeholder="#f59e0b" />
Typography Choose the font style for your certificate
Certificate Text Customize the text content of your certificate
setData('template_data', { ...data.template_data, titleText: e.target.value })} placeholder="Certificate of Completion" />