<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\Models\Branch;
use App\Models\Transfer;
use App\Models\Product;
use App\Models\Inventory;
use App\Models\Carmodel;
use App\Models\Carvarient;
use App\Http\Requests\TransferRequest;
use App\Http\Requests\TransferAcceptRequest;
use Auth, DB, Mail, Validator, File, DataTables;
use App\Models\Notice;

class NoticeController extends Controller{
            
        public function index(Request $request)
        {
              if($request->ajax()){
               
                $data = Notice::orderBy('id','DESC')->get();
                  
                return Datatables::of($data)
                        ->addIndexColumn()
             
                        // ->addColumn('action', function($data){
                        //     $return = '<div class="btn-group">';

                        //      if(auth()->user()->can('fule_type-view')){
                        //         $return .= '<a href="'.route('fule_type.view', ['id' => base64_encode($data->id)]).'" class="btn btn-default btn-xs">
                        //                         <i class="fa fa-eye"></i>
                        //                     </a> &nbsp;';
                        //      }   
                            
                        //      if(auth()->user()->can('fule_type-edit')){
                        //         $return .= '<a href="'.route('fule_type.edit', ['id' => base64_encode($data->id)]).'" class="btn btn-default btn-xs">
                        //                         <i class="fa fa-pencil"></i>
                        //                     </a> &nbsp;';
                        //      }   

                        //      if (auth()->user()->can('fule_type-delete')) {
                        //         $return .= '<a href="javascript:;" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
                        //                             <i class="fa fa-bars"></i>
                        //                         </a> &nbsp;
                        //                         <ul class="dropdown-menu">
                        //                             <li><a class="dropdown-item" href="javascript:;" onclick="change_status(this);" data-status="active" data-id="' . base64_encode($data->id) . '">Active</a></li>
                        //                             <li><a class="dropdown-item" href="javascript:;" onclick="change_status(this);" data-status="inactive" data-id="' . base64_encode($data->id) . '">Inactive</a></li>
                        //                             <li><a class="dropdown-item" href="javascript:;" onclick="change_status(this);" data-status="deleted" data-id="' . base64_encode($data->id) . '">Deleted</a></li>
                        //                         </ul>';
                        //      }

                        //     $return .= '</div>';

                        //     return $return;
                        // })

                        /*->editColumn('percentage', function ($data) {
                            return $data->percentage."%";
                        })*/
                        // ->editColumn('status', function ($data) {
                        //     if ($data->status == 'active') {
                        //         return '<span class="badge badge-pill badge-success">Active</span>';
                        //     } else if ($data->status == 'inactive') {
                        //         return '<span class="badge badge-pill badge-warning">Inactive</span>';
                        //     } else if ($data->status == 'deleted') {
                        //         return '<span class="badge badge-pill badge-danger">Deleted</span>';
                        //     }
                        // })

                        // ->rawColumns(['action' ,'percentage' ,'status'])
                        ->make(true);
            }
            return view('notice.index');
        }
 
        public function create(Request $request)
        {
            return view('notice.create');
        }
        public function notice_save(Request $request)
        {
            $ticket = new Notice();
         
            $ticket->title=$request->input('title');
            $ticket->save();
                return redirect()->back()->with(['message'=>'Notice Added']);
            
        }
        
}
