<?php

namespace App\Components\Template;

use App\Models\Contact\ContactCategory;
use App\Models\Contact\Template;
use Livewire\Component;

class Index extends Component {
    public $showCategoryForm = false;
    public $newCategoryName;

    public $templates;

    public function mount() {
        $this->templates = Template::all();
    }

    public function saveCategory() {
        $this->validate(['newCategoryName' => 'required|unique:contact_categories,name']);
        ContactCategory::create(['name' => $this->newCategoryName]);
        $this->newCategoryName = '';
        $this->showCategoryForm = false;
    }

    public function deleteTemplate($id) {
        Template::destroy($id);
    }

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