import { Button } from '@/components/ui/button'; 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 AppLayout from '@/layouts/app-layout'; import { Head } from '@inertiajs/react'; import { type BreadcrumbItem } from '@/types'; import InputError from '@/components/input-error'; import { useEffect } from 'react'; interface ServiceRoomFormProps { mode: 'create' | 'edit'; room?: { id?: string; code: string; name: string; type: string; class: string; floor?: string; building?: string; wing?: string; capacity: number; price_per_day?: number; facilities?: string; is_available: boolean; is_active: boolean; }; roomTypes: string[]; roomClasses: Record; } const breadcrumbs: BreadcrumbItem[] = [ { title: 'Dashboard', href: '/dashboard' }, { title: 'Manajemen Ruangan', href: '/room-services' }, { title: 'Form Ruangan', href: '#' }, ]; export default function ServiceRoomForm({ mode, room, roomTypes, roomClasses }: ServiceRoomFormProps) { const { data, setData, post, put, processing, errors, reset } = useForm({ code: room?.code || '', name: room?.name || '', type: room?.type || 'Rawat Inap', class: room?.class || 'standard', floor: room?.floor || '', building: room?.building || '', wing: room?.wing || '', capacity: room?.capacity || 1, price_per_day: room?.price_per_day || undefined, facilities: room?.facilities || '', is_available: room?.is_available ?? true, is_active: room?.is_active ?? true, }); const onSubmit = (e: React.FormEvent) => { e.preventDefault(); if (mode === 'create') { post(route('service-rooms.store'), { onSuccess: () => reset(), }); } else { put(route('service-rooms.update', room?.id), { preserveScroll: true, }); } }; // Format price for display const formatPrice = (value: string) => { const num = parseFloat(value.replace(/\D/g, '')) || 0; return isNaN(num) ? '' : num.toLocaleString('id-ID'); }; return (

{mode === 'create' ? 'Tambah Ruangan Baru' : 'Edit Data Ruangan'}

{/* Informasi Dasar */}
setData('code', e.target.value)} placeholder="RJ-101, RI-201" />
setData('name', e.target.value)} placeholder="Ruang Bedah 1, Kamar VIP 2" />
{/* Lokasi */}
setData('floor', e.target.value)} placeholder="1, 2, 3, ..." />
setData('building', e.target.value)} placeholder="Gedung A, Utama, ..." />
setData('wing', e.target.value)} placeholder="Timur, Barat, ..." />
{/* Kapasitas & Harga */}
setData('capacity', parseInt(e.target.value) || 0)} />
{ const value = e.target.value; const num = parseFloat(value.replace(/\D/g, '')) || 0; setData('price_per_day', isNaN(num) ? undefined : num); }} placeholder="500.000" />
{/* Fasilitas */}