<?php namespace App\Controllers;

use App\Models\Dashboard_model;
use App\Models\Packages_and_pricing_model;
use App\Models\Member_credits_model;
use App\Models\Cart_model;
use App\Models\Member_model;
use App\Models\Common_model;
use App\Models\Credits_usage_tracking_model;
use App\Models\User_model;

class Dashboard extends BaseController
{
	
	public function __construct()
	{
		$this->session = session();
		$this->dModel = new Dashboard_model();
		$this->UserModel = new User_model();
		$this->PackagesModel = new Packages_and_pricing_model();
		$this->creditsModel = new Member_credits_model();
		$this->cartModel = new Cart_model();
		$this->MemberModel = new Member_model();
		$this->cModel = new Common_model();
		$this->CreditsUsageTrackingModel = new Credits_usage_tracking_model();
	}
	public function index()
	{
		
		
	}
	public function admin_home()
	{
		
		$data = [];
		if(!session()->has('logged_admin_user'))
		{
			return redirect()->to(base_url());
		}
		
		$id = session()->get('logged_admin_user');
		$data['userdata']=$this->dModel->getLoggedInUserData($id);
		$data['MembersCount'] =  $this->MemberModel->selectCount('id')->get()->getRow()->id;
		$data['AdminCount'] =  $this->UserModel->selectCount('id')->where('role','Admin')->get()->getRow()->id;
		$data['CoachCount'] =  $this->UserModel->selectCount('id')->where('role','Coach')->get()->getRow()->id;
		$data['FrontdeskCount'] =  $this->UserModel->selectCount('id')->where('role','Frontdesk')->get()->getRow()->id;
		echo view('layout/header',$data);
		echo view('dashboard',$data);
		echo view('layout/footer');
		//return view('dashboard');
	}
	public function member_home()
	{
		
		$data = [];
		if(!session()->has('logged_user'))
		{
			return redirect()->to(base_url());
		}
		
		
		$data['userdata']=$this->dModel->getLoggedInMemberData(session()->get('logged_user'));
		$data['packageData']=$this->PackagesModel->findAll();
		$data['creditsData']=$this->creditsModel->where('member_id' , session()->get('logged_user') )->findAll();
		$data['cartData'] =  $this->cartModel->select('cart.* ,packages_and_pricing.*')
												->join('packages_and_pricing', 'cart.pack_id = packages_and_pricing.id', 'left')
												->where('cart.member_id', session()->get('logged_user') )
												->findAll();
		//print_r($data);die();
		//echo view('layout/header',$data);
		echo view('member_dashboard',$data);
		//echo view('layout/footer');
		//return view('dashboard');
	}

	
	
}