<?php

namespace App\Livewire\Pages\Ai;

use App\Domains\Ai\Actions\GenerateAbVariants;
use Illuminate\View\View;
use Livewire\Attributes\Validate;
use Livewire\Component;

class AbGenerator extends Component
{
    #[Validate('required|url|max:2048')]
    public string $targetUrl = '';

    public int $count = 3;

    /** @var string[] */
    public array $variants = [];

    public bool $loading = false;

    public function generate(): void
    {
        $this->validate();
        $this->loading = true;
        $this->variants = app(GenerateAbVariants::class)->handle($this->targetUrl, $this->count);
        $this->loading = false;
    }

    public function render(): View
    {
        return view('livewire.pages.ai.ab-generator')
            ->layout('layouts.nimuli-app', ['title' => 'AI A/B Generator']);
    }
}
