import { Head, useForm, Link } from '@inertiajs/react';
import React from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Separator } from '@/components/ui/separator';
import AppLayout from '@/layouts/app-layout';

export default function Create() {
    const { data, setData, post, processing, errors } = useForm({
        name: '',
        description: '',
    });

    const submit = (e: React.FormEvent) => {
        e.preventDefault();
        post('/admin/departments');
    };

    return (
        <AppLayout>
            <Head title="Tambah Departemen" />
            
            <div className="p-4 md:p-8 w-full">
                <div className="flex items-center justify-between mb-6">
                    <div>
                        <h2 className="text-2xl font-bold tracking-tight">Tambah Departemen</h2>
                        <p className="text-muted-foreground">Buat divisi baru dalam perusahaan.</p>
                    </div>
                    <Button variant="outline" asChild>
                        <Link href="/admin/departments">Kembali</Link>
                    </Button>
                </div>

                <Card>
                    <CardHeader>
                        <CardTitle>Form Departemen</CardTitle>
                    </CardHeader>
                    <Separator />
                    <CardContent className="pt-6">
                        <form onSubmit={submit} className="space-y-6">
                            
                            <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                                <div className="space-y-2">
                                    <Label>Nama Departemen <span className="text-red-500">*</span></Label>
                                    <Input 
                                        placeholder="Contoh: Information Technology"
                                        value={data.name} 
                                        onChange={e => setData('name', e.target.value)} 
                                    />
                                    {errors.name && <div className="text-red-500 text-xs">{errors.name}</div>}
                                </div>

                                <div className="space-y-2">
                                    <Label>Deskripsi Singkat</Label>
                                    <Input 
                                        placeholder="Keterangan fungsi departemen..."
                                        value={data.description} 
                                        onChange={e => setData('description', e.target.value)} 
                                    />
                                    {errors.description && <div className="text-red-500 text-xs">{errors.description}</div>}
                                </div>
                            </div>

                            <div className="flex justify-end gap-4 pt-4">
                                <Button type="button" variant="ghost" asChild>
                                    <Link href="/admin/departments">Batal</Link>
                                </Button>
                                <Button type="submit" disabled={processing}>
                                    Simpan Departemen
                                </Button>
                            </div>

                        </form>
                    </CardContent>
                </Card>
            </div>
        </AppLayout>
    );
}