<?php

namespace App\Http\Controllers;

use App\Models\Note;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Session;

class NoteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $notes = Note::where('user_id' , Auth::user()->id)->get();
        return view('Dashboard.Notes.index' , compact('notes'));
    }


    
    public function store(Request $request)
    {


        $colors =  array('rounded-md flex items-center px-5 py-4 mb-2 bg-theme-17 text-theme-11' , 'rounded-md flex items-center px-5 py-4 mb-2 bg-theme-18 text-theme-9' , 'rounded-md flex items-center px-5 py-4 mb-2 bg-theme-14 text-theme-10' , 'rounded-md flex items-center px-5 py-4 mb-2 bg-theme-31 text-theme-6'); //['lightblue' , 'lightgreen' , 'lightgray'];

        $color = array_rand($colors);

        Note::create([
            'user_id' => $request->user_id,
            'title' => 'Title',
            'description' => $request->description,
            'color' => $colors[$color]
        ]);
        Session::flash('success_message' , 'Note Successfully Added!');
        return redirect('/Note?note=save');
    }

  
    public function destroy($id)
    {


        Note::find($id)->delete();
        Session::flash('success_message' , 'Note Successfully Deleted!');
        return redirect('/Note?note=delete');
    }
}
