import React, { useRef, useState } from 'react' import { router, usePage } from '@inertiajs/react' import StudioLayout from '../../Layouts/StudioLayout' import GroupStudioPromoCard from '../../components/groups/GroupStudioPromoCard' export default function StudioGroupCreate() { const { props } = usePage() const avatarInputRef = useRef(null) const bannerInputRef = useRef(null) const [form, setForm] = useState({ name: '', slug: '', headline: '', bio: '', type: '', founded_at: '', avatar_path: '', banner_path: '', visibility: 'public', membership_policy: 'invite_only', website_url: '', links_json: [{ label: '', url: '' }], avatar_file: null, banner_file: null, }) const [avatarPreview, setAvatarPreview] = useState('') const [bannerPreview, setBannerPreview] = useState('') const updateLink = (index, key, value) => { setForm((current) => ({ ...current, links_json: current.links_json.map((item, itemIndex) => itemIndex === index ? { ...item, [key]: value } : item), })) } const addLink = () => { setForm((current) => ({ ...current, links_json: [...current.links_json, { label: '', url: '' }], })) } const removeLink = (index) => { setForm((current) => ({ ...current, links_json: current.links_json.filter((_, itemIndex) => itemIndex !== index), })) } const submit = () => { router.post(props.endpoints?.store, { ...form, links_json: form.links_json.filter((item) => item.label.trim() !== '' || item.url.trim() !== ''), }, { forceFormData: true, }) } const handleFileSelected = (field, setPreview) => (event) => { const file = event.target.files?.[0] || null setForm((current) => ({ ...current, [field]: file })) setPreview(file ? URL.createObjectURL(file) : '') } const clearSelectedFile = (field, setPreview, inputRef) => { setForm((current) => ({ ...current, [field]: null })) setPreview('') if (inputRef.current) { inputRef.current.value = '' } } return (