<?php

namespace App\Filament\Pages\Settings;

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

class ManageSocialMediaSettings extends SettingsPage
{
    use HasPageShield;

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

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

    protected static ?string $navigationLabel = 'Media Sosial';

    protected static ?int $navigationSort = 2;

    protected static string $settings = SocialMediaSettings::class;

    protected static ?string $title = 'Pengaturan Media Sosial';

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Link Media Sosial')
                    ->description('Atur link media sosial resmi Anda.')
                    ->schema([
                        Grid::make(2)
                            ->schema([
                                TextInput::make('facebook')
                                    ->label('Facebook')
                                    ->placeholder('https://facebook.com/username')
                                    ->autofocus()
                                    ->autocomplete(false)
                                    ->url(),

                                TextInput::make('twitter')
                                    ->label('Twitter')
                                    ->placeholder('https://twitter.com/username')
                                    ->autocomplete(false)
                                    ->url(),

                                TextInput::make('instagram')
                                    ->label('Instagram')
                                    ->placeholder('https://instagram.com/username')
                                    ->autocomplete(false)
                                    ->url(),

                                TextInput::make('youtube')
                                    ->label('YouTube')
                                    ->placeholder('https://youtube.com/username')
                                    ->autocomplete(false)
                                    ->url(),
                            ]),
                    ])
                    ->columnSpanFull(),
            ]);
    }

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