<?php

namespace App\Components\LeadSource;

use App\Models\LeadSource\LeadSource;
use Livewire\Component;

class Create extends Component {

    public $display_name;

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

    public function saveSource() {
        $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');
    }
}
