<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ConcernController extends Controller
{
    public function index()
    {
        $concerns = DB::table('concerns')->get();
        $concern = null;
        return view('concerns.index', compact('concerns', 'concern'));
    }

    public function create() { return view('concerns.create'); }

    public function store(Request $request)
    {
        DB::table('concerns')->insert(['uz' => $request->uz ?? $request->name, 'ru' => $request->ru ?? $request->name, 'cr' => $request->cr ?? $request->name, 'created_at' => now(), 'updated_at' => now()]);
        return redirect()->route('concerns.index');
    }

    public function show($id)
    {
        $concern = DB::table('concerns')->find($id);
        return view('concerns.show', compact('concern'));
    }

    public function edit($id)
    {
        $concern = DB::table('concerns')->find($id);
        return view('concerns.edit', compact('concern'));
    }

    public function update(Request $request, $id)
    {
        DB::table('concerns')->where('id', $id)->update(['uz' => $request->uz ?? $request->name, 'ru' => $request->ru ?? $request->name, 'cr' => $request->cr ?? $request->name, 'updated_at' => now()]);
        return redirect()->route('concerns.index');
    }

    public function destroy($id)
    {
        DB::table('concerns')->delete($id);
        return redirect()->route('concerns.index');
    }
}
