<?php

namespace App\Http\Controllers\Admin\Core\App;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;

use Yajra\DataTables\DataTables;

use App\Repositories\Core\App\Applications;
use App\Datatables\Admin\Core\App\ApplicationsDataTable;

class ApplicationController extends Controller
{
    public function index(ApplicationsDataTable $dataTable)
    {
        $data = \App\Repositories\Config::init();
        return $dataTable->render('admin.Core.App.Application.index', $data);
    }

    public function edit(Request $request, $id = false)
    {
        $id = $id ? $id : $request->input('id');
        $data = \App\Repositories\Config::init();
        $data = Applications::get($id);
        return view('Admin.Core.App.Application.edit', $data);
    }

    public function store(Request $request)
    {
        Applications::store($request->all());
        return response()->json(['error' => 0]);
    }

    public function destroy(Request $request, $id = false)
    {
        $id = $id ? $id : $request->input('id');
        Applications::destroy($id);
        return response()->json(['error' => 0]);
    }

    public function toggleActive(Request $request)
    {
        $data = Applications::toggle_active($request->input('id'), ($request->input('active') == 'true') ? 1 : 0);
        return response()->json(['error' => 0]);
    }
}
