<?php

namespace App\Filament\Resources\Applicants\Schemas;

use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Schemas\Schema;

class ApplicantForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                \Filament\Forms\Components\Section::make('Informasi Lowongan')
                    ->schema([
                        \Filament\Forms\Components\Select::make('vacancy_id')
                            ->label('Lowongan')
                            ->relationship('vacancy', 'title')
                            ->required(),
                        \Filament\Forms\Components\Select::make('user_id')
                            ->label('Akun Pengguna (Opsional)')
                            ->relationship('user', 'name')
                            ->searchable(),
                        \Filament\Forms\Components\Select::make('status')
                            ->options([
                                'TERKIRIM' => 'Terkirim',
                                'PROSES' => 'Proses',
                                'DITERIMA' => 'Diterima',
                                'DITOLAK' => 'Ditolak',
                            ])
                            ->required()
                            ->default('TERKIRIM'),
                    ])->columns(3),

                \Filament\Forms\Components\Section::make('Identitas Diri')
                    ->schema([
                        \Filament\Forms\Components\TextInput::make('full_name')->label('Nama Lengkap')->required(),
                        \Filament\Forms\Components\TextInput::make('nik')->label('NIK')->required(),
                        \Filament\Forms\Components\Select::make('gender')
                            ->label('Jenis Kelamin')
                            ->options(['Laki-Laki' => 'Laki-Laki', 'Perempuan' => 'Perempuan']),
                        \Filament\Forms\Components\Select::make('religion')
                            ->label('Agama')
                            ->options([
                                'Islam' => 'Islam', 'Kristen Protestan' => 'Kristen Protestan',
                                'Katolik' => 'Katolik', 'Hindu' => 'Hindu',
                                'Buddha' => 'Buddha', 'Konghucu' => 'Konghucu'
                            ]),
                        \Filament\Forms\Components\TextInput::make('birth_place')->label('Tempat Lahir'),
                        \Filament\Forms\Components\DatePicker::make('birth_date')->label('Tanggal Lahir')->native(false),
                        \Filament\Forms\Components\TextInput::make('weight')->label('Berat Badan (kg)')->numeric(),
                        \Filament\Forms\Components\TextInput::make('height')->label('Tinggi Badan (cm)')->numeric(),
                        \Filament\Forms\Components\Textarea::make('address')->label('Alamat')->columnSpanFull(),
                        \Filament\Forms\Components\TextInput::make('city')->label('Kota/Kabupaten'),
                        \Filament\Forms\Components\TextInput::make('province')->label('Provinsi'),
                        \Filament\Forms\Components\TextInput::make('postal_code')->label('Kode Pos'),
                    ])->columns(2),

                \Filament\Forms\Components\Section::make('Data Tambahan')
                    ->schema([
                        \Filament\Forms\Components\Repeater::make('family_data')
                            ->label('Data Keluarga')
                            ->schema([
                                \Filament\Forms\Components\TextInput::make('hubungan')->label('Hubungan'),
                                \Filament\Forms\Components\TextInput::make('nama')->label('Nama'),
                                \Filament\Forms\Components\Select::make('jenis_kelamin')->label('L/P')->options(['L' => 'Laki-Laki', 'P' => 'Perempuan']),
                                \Filament\Forms\Components\TextInput::make('ttl')->label('Tempat/Tgl Lahir'),
                                \Filament\Forms\Components\TextInput::make('pendidikan')->label('Pendidikan'),
                                \Filament\Forms\Components\TextInput::make('pekerjaan')->label('Pekerjaan'),
                            ])->columns(3)->columnSpanFull(),

                        \Filament\Forms\Components\Repeater::make('education_data')
                            ->label('Riwayat Pendidikan')
                            ->schema([
                                \Filament\Forms\Components\TextInput::make('tingkat')->label('Tingkat'),
                                \Filament\Forms\Components\TextInput::make('nama_sekolah')->label('Nama Sekolah'),
                                \Filament\Forms\Components\TextInput::make('jurusan')->label('Jurusan'),
                                \Filament\Forms\Components\TextInput::make('tahun_lulus')->label('Tahun Lulus'),
                                \Filament\Forms\Components\TextInput::make('ipk')->label('IPK/Nilai'),
                            ])->columns(3)->columnSpanFull(),

                        \Filament\Forms\Components\Repeater::make('experience_data')
                            ->label('Pengalaman Kerja')
                            ->schema([
                                \Filament\Forms\Components\TextInput::make('perusahaan')->label('Nama Perusahaan'),
                                \Filament\Forms\Components\TextInput::make('jabatan')->label('Jabatan'),
                                \Filament\Forms\Components\TextInput::make('periode')->label('Periode'),
                                \Filament\Forms\Components\TextInput::make('gaji')->label('Gaji Akhir'),
                                \Filament\Forms\Components\Textarea::make('alasan_berhenti')->label('Alasan Berhenti')->columnSpanFull(),
                            ])->columns(2)->columnSpanFull(),

                        \Filament\Forms\Components\Repeater::make('other_data')
                            ->label('Data Lain-lain')
                            ->schema([
                                \Filament\Forms\Components\TextInput::make('key')->label('Keterangan'),
                                \Filament\Forms\Components\TextInput::make('value')->label('Nilai'),
                            ])->columns(2)->columnSpanFull(),
                    ])->collapsed(),

                \Filament\Forms\Components\Section::make('Dokumen Pendukung')
                    ->schema([
                        \Filament\Forms\Components\FileUpload::make('documents')
                            ->label('Upload Dokumen (Bisa pilih lebih dari satu)')
                            ->multiple()
                            ->directory('applicant-documents')
                            ->acceptedFileTypes(['application/pdf', 'image/jpeg', 'image/png'])
                            ->maxSize(5120) // 5MB limit
                            ->columnSpanFull(),
                    ]),
            ]);
    }
}
