<?php

namespace App\Filament\Resources\NewsResource\Pages;

use Filament\Actions\ActionGroup;
use Filament\Forms\Components\Select;
use Pboivin\FilamentPeek\Pages\Actions\PreviewAction;
use Pboivin\FilamentPeek\Pages\Concerns\HasPreviewModal;

trait HasNewsPreview
{
    use HasPreviewModal;

    protected function getActions(): array
    {
        return [
            ActionGroup::make([
                PreviewAction::make('tw')
                    ->label('中文（台灣）')
                    ->previewModalData(fn() => ['locale' => 'zh_TW']),
                PreviewAction::make('en')
                    ->label('English')
                    ->previewModalData(fn() => ['locale' => 'en']),
                PreviewAction::make('jp')
                    ->label('jp')
                    ->previewModalData(fn() => ['locale' => 'jp']),
            ])
                ->label('預覽')
                ->icon('heroicon-m-chevron-down')
                ->color('primary')
                ->button()
        ];
    }

    protected function getPreviewModalView(): ?string
    {
        return 'previews.news.show';
    }

    protected function getPreviewModalDataRecordKey(): ?string
    {
        return 'news';
    }

    protected function mutatePreviewModalData(array $data): array
    {
        // relations
        $data['paragraphs'] = $this->data['paragraphs'];
        $data['extraImages'] = $this->data['extra_images'];
        return $data;
    }
}
