<?php

namespace CaptchaPlugin\View\Components;

use Illuminate\View\Component;
use CaptchaPlugin\Services\CaptchaService;

class Captcha extends Component
{
    public string $location;
    public array $attributes;

    public function __construct(string $location = 'default', array $attributes = [])
    {
        $this->location = $location;
        $this->attributes = $attributes;
    }

    public function render()
    {
        $captchaService = app('captcha');

        // Verifică dacă CAPTCHA este activat pentru această locație
        if (!$captchaService->isEnabled($this->location)) {
            return '';
        }

        // Verifică whitelist
        if ($captchaService->isWhitelisted(request()->ip())) {
            return '';
        }

        return view('captcha::components.captcha', [
            'location' => $this->location,
            'provider' => config('captcha.provider'),
            'siteKey' => config('captcha.site_key'),
            'threshold' => config('captcha.threshold', 0.5),
        ]);
    }
}
