<?php

namespace App\Http\Controllers;

use App\Models\User;
use App\New_departments;
use Illuminate\Http\Request;
use Datatables;

use  Sentinel;

class New_departmentsController extends Controller
{
    public function get_user_info()
    {
        return User::select(['first_name as full_name', 'user_avatar', 'id'])->where('id', Sentinel::getUser()->id)->get()->first();
    }


    public   function insert(Request  $request)
    {



        // $title = trans('quotation.quotations');

        New_departments::create($request->all());
        Session()->flash('flash_message', 'Created Successfully');
        return $this->index($request);
    } //insert
    public   function create(Request  $request)
    {
        $title = 'Create New Department';
        $user_data = $this->get_user_info();
        // $title = trans('quotation.quotations');
        return view('new_departments.create', compact('user_data', 'title'));
    } //create


    public   function index(Request  $request)
    {
        $user_data = $this->get_user_info();
        // $title = 'Create New Service';
        // $title = trans('quotation.quotations');
        return view('new_departments.index', compact('user_data'));
    } //index

    public function anyData()
    {
        $data = New_departments::select(['*'])->where([['status', 1]])->orderBy('id', 'DESC')->get();
        // return $this->getTable($clients);
        return Datatables::of($data)


            ->addColumn('status', function ($data) {
                if ($data->status == 1)
                    return 'Active';
                else
                    return '';
            })
            ->add_column(
                'action',

                '
            <div class="dropdown">
              <button class="btn" style="border-left:1px solid #0d8bf2">Actions
  
              </button>
              <div class="dropdown-content">
               
             
                <a href="#">Edit</a>
                <a href="#">Delete</a>
              </div>
            </div>'
            )





            // ->add_column('id', $clients->id)
            // ->add_column('price', $clients->id)
            // ->add_column('delete', '
            //     <form action="{{ route(\'clients.destroy\', $id) }}" method="POST">
            // <input type="hidden" name="_method" value="DELETE">
            // <input type="submit" name="submit" value="Delete" class="btn btn-danger" onClick="return confirm(\'Are you sure?\')"">

            // {{csrf_field()}}
            // </form>')
            ->make(true);
    }

    //
}
