<?php

namespace App\Http\Controllers\Admin;

use App\Models\Admin\Taxonomy;
use App\Http\Controllers\Controller;

class TaxonomyController extends Controller
{
    public function index()
    {
        $id = request()->get('id');
        $taxonomy = null;
        $ancestors = collect();

        if ($id) {
            $taxonomy = Taxonomy::find($id);
            if ($taxonomy) {
                $ancestors = $taxonomy->ancestors();
            }
        }

        return view('admin.taxonomy.index', [
            'taxonomy' => $taxonomy,
            'ancestors' => $ancestors
        ]);
    }

    public function create()
    {
        $id = request()->get('id');
        $taxonomy = null;
        $ancestors = collect();

        if ($id) {
            $taxonomy = Taxonomy::find($id);
            if ($taxonomy) {
                $ancestors = $taxonomy->ancestors();
            }
        }

        return view('admin.taxonomy.create', [
            'taxonomy' => $taxonomy,
            'ancestors' => $ancestors
        ]);
    }

    public function edit($id)
    {
        $taxonomy = Taxonomy::find($id);

        return view('admin.taxonomy.edit', ['taxonomy' => $taxonomy]);
    }

    public function show($id)
    {
        $taxonomy = Taxonomy::find($id);

        return view('admin.taxonomy.show', ['taxonomy' => $taxonomy]);
    }
}
