<?php

namespace App\Components\Solicitor;

use App\Models\Solicitor\Solicitor;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;

class View extends Component {
    use AuthorizesRequests;
    public Solicitor $solicitor;

    public string $tab = 'overview';

    protected array $allowedTabs = [
        'overview',
        'documents',
        'addresses',
        'email-senders',
        'sms-senders',
        'phone-numbers',
        'logo',
        'history',
    ];

    protected $queryString = [
        'tab' => ['except' => 'overview'],
    ];

    public function mount(Solicitor $solicitor): void {
        $this->authorize('solicitors.view');
        $this->solicitor = $solicitor;

        if (!in_array($this->tab, $this->allowedTabs, true)) {
            $this->tab = 'overview';
        }
    }

    public function setTab(string $tab): void {
        if (!in_array($tab, $this->allowedTabs, true)) {
            return;
        }

        $this->tab = $tab;
    }

    public function render() {
        return view('components.solicitor.view');
    }
}
