<?php

namespace App\Components\LeadSource;

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

class Edit extends Component {

    public $display_name;
    public LeadSource $leadSource;

    public function mount() {
        $this->authorize('sources.edit', $this->leadSource);
        $this->display_name = $this->leadSource->display_name;
    }

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

        $this->leadSource->update($data);

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

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