<?php

namespace Modules\Admin\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Facades\Excel;
use Carbon\Carbon;

use App\Models\User;
use App\Models\AdminDetails;
use App\Models\Companies;
use App\Models\Supliers;
use App\Models\Categories;
use App\Models\Brands;
use App\Models\Products;
use App\Models\ProductGallery;
use App\Models\Banners;
use App\Models\Services;
use App\Models\Waiters;
use App\Models\TablesRooms;

use File;
use Mail;
use Image;
use PDF;
class TablesRoomsController extends Controller
{

    public function add_table_room(Request $request)
    {
        if($request->isMethod('get')){
            return view('admin::table_room.add_table_room');
        }

        if($request->isMethod('post')){
            $request->validate([
                'name'   => 'required'
            ]);
           

            $table = new TablesRooms();
            $table->name = $request->name;
            $table->status = 'active';
            $table->save();

            return back()->with('success', 'Table/Room Successfully Added');
        }
    }


public function table_rooms(Request $request)
    { if($request->isMethod('get')){
        $tables_rooms = TablesRooms::get();
        return view('admin::table_room.table_rooms',['tables_rooms' => $tables_rooms]);
    }

    }

    public function deactivate_table_room($id){
        $tables_rooms = TablesRooms::find($id);
        $tables_rooms->status = "inactive";
        $tables_rooms->update();
        return back()->with('success', 'Table/Room Deactivated');

    }
    public function activate_table_room($id){
        $tables_rooms = TablesRooms::find($id);
        $tables_rooms->status = "active";
        $tables_rooms->update();
        return back()->with('success', 'Table/Room Activated');

    }

    public function edit_table_room($id,Request $request)
    { if($request->isMethod('get')){
        $table_room = TablesRooms::where('id',$id)->first();
        return view('admin::table_room.edit_table_room',['table_room' => $table_room]);
    }
    if($request->isMethod('post')){
        $request->validate([
            'name'   => 'required'
        ]);

        $waiter = TablesRooms::where('id', $id)->first();
        $waiter->name = $request->name;
        $waiter->update();


        return back()->with('success', 'Table/Room Successfully Updated');

    }

    }

    public function delete_table_room($id,Request $request)
    {
        TablesRooms::find($id)->delete();
        return back()->with('success', 'Table/Room Deleted');
    }

}