<?php

namespace App\Filament\Resources\Customers\Pages;

use App\Filament\Resources\Customers\CustomerResource;
use Filament\Actions\DeleteAction;
use Filament\Actions\Action;
use Filament\Resources\Pages\EditRecord;
use Filament\Notifications\Notification;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\RichEditor;

class EditCustomer extends EditRecord
{
    protected static string $resource = CustomerResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Action::make('send_email')
                ->label('Send email')
                ->icon('heroicon-m-envelope')
                ->color('primary')
                ->modalWidth('2xl')
                ->form([
                    TextInput::make('to')
                        ->label('To')
                        ->disabled()
                        ->dehydrated(false)
                        ->default(fn ($record) => $record?->email),
                    TextInput::make('subject')
                        ->label('Subject')
                        ->required(),
                    RichEditor::make('body')
                        ->label('Body')
                        ->required(),
                ])
                ->action(function ($record, array $data) {
                    Notification::make()
                        ->title('Email Sent')
                        ->body('Email sent to ' . $record->email . ' successfully!')
                        ->success()
                        ->send();
                }),
            DeleteAction::make(),
        ];
    }

    public function content(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema
    {
        $schema->columns(1);

        return parent::content($schema);
    }
}
