<?php

namespace App\Http\Controllers;

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

class note_templates_SINGLE_Controller extends Controller
{
    public $selfName = 'note_templates_SINGLE_Controller';
    public $dashboardName = 'dashboard';

	// GET /note_templates/view/{uid}/ACTION_updateTitle
	public function ACTION_updateTitle(Request $request, $uid) {
		$record = DB::table('note_template')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note_template')->where('id', $uid)->first();
			if($record) return redirect('/note_templates/view/' . $record->uid . '/ACTION_updateTitle');
		}
		return response()->view('admin/note_templates_SINGLE/ACTION_updateTitle', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /note_templates/view/{uid}/SUB_dashboard
	public function SUB_dashboard(Request $request, $uid) {
		$record = DB::table('note_template')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note_template')->where('id', $uid)->first();
			if($record) return redirect('/note_templates/view/' . $record->uid . '/SUB_dashboard');
		}
		return response()->view('admin/note_templates_SINGLE/SUB_dashboard', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /note_templates/view/{uid}/SUB_note_template_section_templates
	public function SUB_note_template_section_templates(Request $request, $uid) {
		$record = DB::table('note_template')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note_template')->where('id', $uid)->first();
			if($record) return redirect('/note_templates/view/' . $record->uid . '/SUB_note_template_section_templates');
		}
		$subRecords = DB::table('note_template_section_template')->where('note_template_id', $record->id)->get();
		$result_section_templates = DB::select("SELECT id, title FROM section_template");
		return response()->view('admin/note_templates_SINGLE/SUB_note_template_section_templates', compact('record', 'subRecords', 'result_section_templates'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /note_templates/view/{uid}/ACTION_add_new_note_template_section_template
	public function ACTION_add_new_note_template_section_template(Request $request, $uid) {
		$record = DB::table('note_template')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note_template')->where('id', $uid)->first();
			if($record) return redirect('/note_templates/view/' . $record->uid . '/ACTION_add_new_note_template_section_template');
		}
		return response()->view('admin/note_templates_SINGLE/ACTION_add_new_note_template_section_template', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}
}
