<?php

namespace App\Filament\Resources\VillageProfiles\Schemas;

use Filament\Forms\Components\FileUpload;
use Filament\Schemas\Components\Grid;
use Filament\Forms\Components\RichEditor;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;

class VillageProfileForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Tabs::make('Profil Desa')
                    ->columnSpanFull()
                    ->tabs([
                        Tab::make('Visi, Misi & Sejarah')
                            ->icon('heroicon-o-document-text')
                            ->schema([
                                RichEditor::make('visi')
                                    ->label('Visi Desa')
                                    ->required()
                                    ->columnSpanFull(),
                                Textarea::make('misi')
                                    ->label('Misi Desa')
                                    ->placeholder("Masukkan misi desa (pisahkan dengan baris baru)")
                                    ->required()
                                    ->rows(5)
                                    ->columnSpanFull(),
                                Grid::make(2)
                                    ->schema([
                                        RichEditor::make('sejarah')
                                            ->label('Sejarah Desa')
                                            ->required()
                                            ->columnSpan(2),
                                        RichEditor::make('sejarah_asal_usul')
                                            ->label('Asal Usul Nama Desa')
                                            ->required()
                                            ->columnSpan(2),
                                        FileUpload::make('sejarah_image')
                                            ->label('Foto Sejarah Desa')
                                            ->image()
                                            ->imageEditor()
                                            ->disk('public')
                                            ->visibility('public')
                                            ->columnSpan(2),
                                        FileUpload::make('logo_kabupaten')
                                            ->label('Logo Kabupaten')
                                            ->image()
                                            ->imageEditor()
                                            ->disk('public')
                                            ->visibility('public')
                                            ->columnSpan(2)
                                            ->helperText('Upload logo Kabupaten/Kota (format PNG/JPG, ukuran proporsional)'),
                                    ]),
                            ]),

                        Tab::make('Data Umum & Batas')
                            ->icon('heroicon-o-information-circle')
                            ->schema([
                                Section::make('Informasi Wilayah & Kependudukan')
                                    ->columns(2)
                                    ->schema([
                                        TextInput::make('luas_wilayah')
                                            ->label('Luas Wilayah')
                                            ->required()
                                            ->placeholder('Contoh: 12.5 Km²'),
                                        TextInput::make('jumlah_penduduk')
                                            ->label('Jumlah Penduduk')
                                            ->required()
                                            ->placeholder('Contoh: 805 Jiwa'),
                                        TextInput::make('jumlah_kk')
                                            ->label('Jumlah Kepala Keluarga (KK)')
                                            ->required()
                                            ->placeholder('Contoh: 252 KK'),
                                        TextInput::make('jumlah_rt')
                                            ->label('Jumlah RT')
                                            ->required()
                                            ->placeholder('Contoh: 6'),
                                        TextInput::make('jumlah_dusun')
                                            ->label('Jumlah Dusun')
                                            ->required()
                                            ->placeholder('Contoh: 2'),
                                    ]),
                                Section::make('Batas-Batas Wilayah')
                                    ->columns(2)
                                    ->schema([
                                        TextInput::make('batas_utara')
                                            ->label('Batas Utara')
                                            ->required(),
                                        TextInput::make('batas_timur')
                                            ->label('Batas Timur')
                                            ->required(),
                                        TextInput::make('batas_selatan')
                                            ->label('Batas Selatan')
                                            ->required(),
                                        TextInput::make('batas_barat')
                                            ->label('Batas Barat')
                                            ->required(),
                                    ]),
                            ]),

                        Tab::make('Struktur Organisasi')
                            ->icon('heroicon-o-user-group')
                            ->schema([
                                Section::make('Pimpinan Utama')
                                    ->columns(2)
                                    ->schema([
                                        TextInput::make('kades_name')->label('Nama Kepala Desa')->required(),
                                        FileUpload::make('kades_image')
                                            ->label('Foto Kepala Desa')
                                            ->image()
                                            ->disk('public')
                                            ->visibility('public'),
                                            
                                        TextInput::make('sekdes_name')->label('Nama Sekretaris Desa')->required(),
                                        FileUpload::make('sekdes_image')
                                            ->label('Foto Sekretaris Desa')
                                            ->image()
                                            ->disk('public')
                                            ->visibility('public'),
                                    ]),
                                Section::make('Kepala Urusan (KAUR)')
                                    ->columns(3)
                                    ->schema([
                                        Grid::make(1)
                                            ->columnSpan(1)
                                            ->schema([
                                                TextInput::make('kaur_keuangan_name')->label('KAUR Keuangan')->required(),
                                                FileUpload::make('kaur_keuangan_image')
                                                    ->label('Foto KAUR Keuangan')
                                                    ->image()
                                                    ->disk('public')
                                                    ->visibility('public'),
                                            ]),
                                        Grid::make(1)
                                            ->columnSpan(1)
                                            ->schema([
                                                TextInput::make('kaur_perencanaan_name')->label('KAUR Perencanaan')->required(),
                                                FileUpload::make('kaur_perencanaan_image')
                                                    ->label('Foto KAUR Perencanaan')
                                                    ->image()
                                                    ->disk('public')
                                                    ->visibility('public'),
                                            ]),
                                        Grid::make(1)
                                            ->columnSpan(1)
                                            ->schema([
                                                TextInput::make('kaur_tu_name')->label('KAUR Tata Usaha (TU)')->required(),
                                                FileUpload::make('kaur_tu_image')
                                                    ->label('Foto KAUR Tata Usaha')
                                                    ->image()
                                                    ->disk('public')
                                                    ->visibility('public'),
                                            ]),
                                    ]),
                                Section::make('Kepala Seksi (KASI)')
                                    ->columns(3)
                                    ->schema([
                                        TextInput::make('kasi_pemerintahan_name')->label('KASI Pemerintahan')->required(),
                                        TextInput::make('kasi_kesejahteraan_name')->label('KASI Kesejahteraan')->required(),
                                        TextInput::make('kasi_pelayanan_name')->label('KASI Pelayanan')->required(),
                                    ]),
                                Section::make('Lembaga Lain')
                                    ->columns(3)
                                    ->schema([
                                        TextInput::make('ketua_bpd_name')->label('Ketua BPD')->required(),
                                        TextInput::make('kadus_1_name')->label('Ketua Dusun I')->required(),
                                        TextInput::make('kadus_2_name')->label('Ketua Dusun II')->required(),
                                    ]),
                            ]),
                    ]),
            ]);
    }
}
