<?php

namespace App\Filament\Pages\Settings;

use App\Settings\GeneralSettings;
use BackedEnum;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Pages\SettingsPage;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use UnitEnum;

class ManageGeneralSettings extends SettingsPage
{
    protected static string|BackedEnum|null $navigationIcon = Heroicon::Cog6Tooth;

    protected static string $settings = GeneralSettings::class;

    protected static string|UnitEnum|null $navigationGroup = 'Pengaturan';

    protected static ?string $navigationLabel = 'Umum';

    protected static ?string $title = 'Pengaturan Umum';

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Informasi')
                    ->schema([
                        TextInput::make('site_name')
                            ->label('Nama Website')
                            ->placeholder('Simedkom')
                            ->autofocus()
                            ->autocomplete(false)
                            ->required()
                            ->maxLength(255),

                        Textarea::make('site_description')
                            ->label('Deskripsi Website')
                            ->placeholder('Aplikasi Sistem Media Komunikasi Kabupaten Purwakarta')
                            ->autocomplete(false)
                            ->required(),

                        Textarea::make('address')
                            ->label('Alamat')
                            ->placeholder('Jl. Laks. Laut RE. Martadinata No.47')
                            ->autocomplete(false)
                            ->rows(3)
                            ->required()
                            ->maxLength(255),

                        TextInput::make('site_email')
                            ->label('Email Website')
                            ->placeholder('diskominfo@purwakartakab.go.id')
                            ->email()
                            ->required()
                            ->maxLength(255),

                        TextInput::make('site_phone')
                            ->label('Nomor Telepon')
                            ->placeholder('(0264) 200222')
                            ->required()
                            ->maxLength(255),

                        RichEditor::make('about_us')
                            ->label('Tentang Kami')
                            ->placeholder('...')
                            ->required()
                            ->columnSpanFull(),
                    ])->columnSpan(2),

                Section::make('Lampiran')
                    ->schema([
                        FileUpload::make('site_logo')
                            ->label('Logo Website')
                            ->required()
                            ->image()
                            ->directory('settings'),

                        FileUpload::make('site_icon')
                            ->label('Icon Website')
                            ->required()
                            ->image()
                            ->directory('settings'),
                    ])->columnSpan(1),
            ])
            ->columns(3);
    }
}
