<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\NepaliCalendar;

class CalendarController extends Controller
{
	public function convert(Request $request){
		$from = $request->from;
		$year = $request->year;
		$month = $request->month;
		$date = $request->date;
		$nepaliCalendar = new NepaliCalendar;
		if($from=="AD"){
			$nepaliData = $nepaliCalendar->eng_to_nep($year,$month,$date);
			$englishData = $nepaliCalendar->nep_to_eng($nepaliData['year'],$nepaliData['month'],$nepaliData['date']);
			session()->flash('AD',$englishData);
			session()->flash('BS',$nepaliData);
		}
		else{
			$englishData = $nepaliCalendar->nep_to_eng($year,$month,$date);
			$nepaliData = $nepaliCalendar->eng_to_nep($englishData['year'],$englishData['month'],$englishData['date']);
			session()->flash('AD',$englishData);
			session()->flash('BS',$nepaliData);
		}
		return redirect()->back();
	}
}
