<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Category;

class CategoryController extends Controller
{
    public function index()
    {
        $categories = Category::all();
        return view('dashboard.categories.index', compact('categories'));
    }

    public function create()
    {
        return view(view: 'dashboard.categories.create');
    }

    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'icon' => 'nullable|image|mimes:png,jpg,jpeg,svg|max:2048',
        ]);
        $imagePath = null;

        if ($request->hasFile('icon')) {
            $imagePath = $request->file('icon')->store('categories', 'public');
        }

        Category::create([
            'name' => $request->name,
            'icon' => $imagePath,
        ]);

        return redirect()->route('categories.index')->with('success', 'Category added successfully.');
    }

    public function show()
    {
    }

    public function edit()
    {
        return view('dashboard.categories.edit');
    }

    public function update(Request $request, $id)
    {
    }

    public function destroy($id)
    {
    }
}
