<?php

namespace App\Components\LeadSource;

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

class Create extends Component {
    use AuthorizesRequests;

    public $display_name;

    public function mount(): void {
        $this->authorize('sources.create');
    }

    public function saveSource() {
        $this->authorize('sources.create');
        $data = $this->validate([
            'display_name' => 'required|max:255|string|unique:lead_sources,display_name',
        ]);

        $leadSource = LeadSource::create($data);

        return redirect()->route('sources.show', $leadSource);
    }

    public function render() {
        return view('components.lead-source.create');
    }
}
