<?php

namespace App\Filament\Pages\Settings;

use App\Filament\Support\CheerfulNotification;
use App\Settings\SeoSettings;
use BackedEnum;
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Pages\SettingsPage;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use UnitEnum;

class ManageSeoSettings extends SettingsPage
{
    use HasPageShield;

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

    protected static string|BackedEnum|null $navigationIcon = Heroicon::MagnifyingGlass;

    protected static ?string $navigationLabel = 'SEO';

    protected static ?int $navigationSort = 3;

    protected static string $settings = SeoSettings::class;

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

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Search Engine Optimization')
                    ->description('Atur bagaimana website Anda muncul di mesin pencari.')
                    ->schema([
                        TextInput::make('title')
                            ->label('SEO Title')
                            ->placeholder('simedkom')
                            ->autofocus()
                            ->autocomplete(false)
                            ->helperText('Judul yang muncul di tab browser dan hasil pencarian.'),

                        Textarea::make('description')
                            ->label('SEO Description')
                            ->placeholder('...')
                            ->autocomplete(false)
                            ->helperText('Deskripsi singkat website Anda.'),

                        TextInput::make('keywords')
                            ->label('SEO Keywords')
                            ->placeholder('keyword1, keyword2, keyword3')
                            ->autocomplete(false)
                            ->helperText('Gunakan koma untuk memisahkan kata kunci.'),
                    ])
                    ->columnSpanFull(),
            ]);
    }

    public function getSavedNotification(): ?Notification
    {
        return CheerfulNotification::update()->send();
    }
}
