<?php

namespace App\Http\Controllers;

use App\Models\tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class TagController extends Controller
{
    public static function listTags(){
        $tags = tag::getList();
        return view('conti.tags.list',['tags'=>$tags]);
    }

    public static function insTags(Request $request)
    {
        $validated=$request->validate([
            'tag_name' => 'required',
            ]);
        tag::inserisci($request);
        $tags = tag::getList();
        return view('conti.tags.list',['tags'=>$tags]);
    }

    public function calendartest()
    {
        return view('components.calendar');
    }

    public function updateTag($id)
    {
        $tags=tag::getById($id);
        return json_encode($tags);
    }

    public function updatePostTag(Request $request)
    {
        $validated=$request->validate([
            'cat_name' => 'required',
            ]);
        tag::updateById($request);
        return redirect(route('tags'));
    }

    public function apiList()
    {
        $tags=tag::all();
        return json_encode($tags);
    }

    public function deleteTag($id){
        tag::deleteTag($id);
        return redirect(route('tags'));
    }
}
