<?php

namespace App\Http\Controllers;

use App\Models\User;
use App\Models\Admin;
use App\Models\task;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Classes\jDate;
use App\Classes\jDateTime;
use App\Classes\CalendarUtils;



class pagecontroller extends Controller
{
    public function test()
    {
        return $_SERVER['REMOTE_ADDR'].'|-|'.$_SERVER['HTTP_USER_AGENT'];
    }
    public function index()
    {
        $Admins = Admin::all();
        $tasks = task::all();
        return view('index',compact('Admins','tasks'));
    }
    public function calendar()
    {
        $jDate	= new jDate();
        $jDateTime	= new jDateTime();
        $persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
        $english = [ 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 ];
        $today = substr(str_replace($persian,$english , $jDate::forge(time())->format('date')),-2);
        $days_left = 33-$today;
        $startDate = date("Y-m-d", strtotime("-$today days"));
        $endDate = date("Y-m-d", strtotime("+$days_left days"));
        $tasks = task::whereBetween('d1', [$startDate, $endDate])->orwhereBetween('d3', [$startDate, $endDate])->get();
        $Admins = Admin::all();
        return view('pages.calendar',compact('Admins','tasks'));
    }
    public function calendar_week()
    {
        $jDate	= new jDate();
        $jDateTime	= new jDateTime();
        $persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
        $english = [ 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 ];
        $today = substr(str_replace($persian,$english , $jDate::forge(time())->format('date')),-2);
        $days_left = 33-$today;
        $startDate = date("Y-m-d", strtotime("-$today days"));
        $endDate = date("Y-m-d", strtotime("+$days_left days"));
        $tasks = task::whereBetween('d1', [$startDate, $endDate])->orwhereBetween('d3', [$startDate, $endDate])->get();
        $Admins = Admin::all();
        return view('pages.calendar',compact('Admins','tasks'));
    }

    public function tttest()
    {

        $Jalaliann	= new CalendarUtils();
        $g_y = 1402;
        $g_m = 5;
        $g_d = 9;

        return $Jalaliann->toGregorian($g_y,$g_m,$g_d);
    }



}
