<x-filament-panels::page>
    <form wire:submit="save">
        {{ $this->form }}
        <div class="mt-6">
            <x-filament::button type="submit" color="primary">保存设置</x-filament::button>
        </div>
    </form>

    <x-filament::section heading="AI 润色文章">
        <div class="space-y-2">
            @foreach(\App\Models\Post::query()->latest()->limit(20)->get(['id','title']) as $post)
                <div class="flex items-center justify-between rounded-lg border border-gray-200 p-3 dark:border-white/10">
                    <span class="text-sm">{{ $post->title }}</span>
                    <div class="flex gap-2">
                        <x-filament::button size="sm" color="primary" wire:click="polish({{ $post->id }})">AI 润色</x-filament::button>
                        @if($post->meta['ai_polished'] ?? null)
                            <x-filament::button size="sm" color="success" wire:click="acceptPolish({{ $post->id }})">采纳</x-filament::button>
                        @endif
                    </div>
                </div>
            @endforeach
        </div>

        @if($polishResult)
            <div class="mt-4 rounded-lg border border-gray-300 bg-gray-50 p-4 dark:border-white/10 dark:bg-white/5">
                <h3 class="mb-2 text-sm font-semibold">润色预览（已暂存，点击采纳写回文章）</h3>
                <pre class="whitespace-pre-wrap text-sm">{{ Str::limit($polishResult, 3000) }}</pre>
            </div>
        @endif
    </x-filament::section>
</x-filament-panels::page>
