<?php
namespace backend\components;

use Yii;
use common\models\Order;
use yii\helpers\Html;
use common\components\RoleDefinition;
use common\components\Helper;

class AdminMenuStructure{
	
	public $menuItems;
	public $emptyUrl = '#';//maybe null
	
	public function __construct(){
		$this->menuItems = [];
	}
	
	protected function can($authItem){
		$result = false;
		if (\Yii::$app->user->can($authItem)) {
			$result = true;
		}
		return $result;
	}
	
	
	
	
	
	protected function addUserMainMenu(){
		
		$userMainMenu = null;
		$items = [];
		if (!Yii::$app->user->isGuest) {
		
			//$today = \Yii::$app->formatter->asDate( time() );
			$today = \Yii::$app->formatter->asDate( strtotime('today UTC') );
			$tomorrow = \Yii::$app->formatter->asDate( strtotime('tomorrow UTC') );
			
			$todayDatetime = \Yii::$app->formatter->asDatetime( strtotime('today UTC') );
			$tomorrowDatetime = \Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') );
			
			
			/////////////////////////////
			// Beállítások
			/////////////////////////////
			if ( RoleDefinition::isAdmin()){
			$items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']];
			$items[] = ['label' => 'Jogosultságok', 'url' =>['/user/role']];
			$this->menuItems[]  = ['label' => 'Beállítások', 'url' => $this->emptyUrl,
				'items' =>  $items
			];
			}
			
			/////////////////////////////
			// Törszadatok
			/////////////////////////////
			$items = [];
			$items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']];
			if ( RoleDefinition::isAdmin()){
				$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
			}
			$items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
			$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
			$items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ];
			$items[] = ['label' => 'Kulcsok', 'url' =>['/key/index']];
// 			$items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ];
			$this->menuItems[] = ['label' => 'Törzsadatok', 'url' =>$this->emptyUrl,
			'items' =>  $items
			];
			
			/////////////////////////////
			// BÉRLETEK
			/////////////////////////////
			$items = [];
			$items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] , 'target_url' => ['/customer/index' ,'/customer/view','/ticket/index-customer'] ];
			$items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ];
			$items[] = ['label' => 'Bérletek', 'url' => ['/ticket/index' , 'TicketSearch[start]' =>$today,'TicketSearch[end]' => $tomorrow ] ];
			$items[] = ['label' => 'Statisztika', 'url' => ['/ticket/statistics' , 'TicketSearchStatisitcs[start]' =>$today,'TicketSearchStatisitcs[end]' => $tomorrow ] ];
			$items[] = ['label' => 'Kártya létrehozás', 'url' => ['/card-package/index' ,  ] ];
			$items[] = ['label' => 'Kártya csomag RFId hozzárendelés', 'url' => ['/card-package/import' ,  ] ];
			$items[] = ['label' => 'Érvényességek újraszámolása', 'url' => ['/card/recalculate' ,  ] ];
			$this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' =>  $this->emptyUrl,
				'items' =>  $items
			];
			
			/////////////////////////////
			// Termékek
			/////////////////////////////
			$items = [];
			$items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ];
			$items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ];
			$items[] = ['label' => 'Selejt', 'url' => ['/waste/index' ,'WasteSearch[date_start]' =>$today,'WasteSearch[date_end]' => $tomorrow ] ];
			$items[] = ['label' => 'Leltár csoport', 'url' => ['/inventory-group/index'] ];
			$items[] = ['label' => 'Leltár', 'url' => ['/inventory/index'] ];
			$items[] = ['label' => 'Részletes eladások', 'url' => ['/transfer/sale'  ,'TransferSaleSearch[start]' =>$todayDatetime,'TransferSaleSearch[end]' => $tomorrowDatetime ] ];
			$items[] = ['label' => 'Termék összesítő', 'url' => ['/product/statistics'  ,'ProductStatisticsSearch[start]' =>$todayDatetime,'ProductStatisticsSearch[end]' => $tomorrowDatetime ] ];
			$this->menuItems[] = ['label' => 'Termékek', 'url' =>  $this->emptyUrl,
				'items' =>  $items
			];
			
			/////////////////////////////
			// Pénzügy
			/////////////////////////////
			$items = [];
			$items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$todayDatetime,'TransferSearch[end]' => $tomorrowDatetime ] ];
// 			$items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
			$items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ];
			$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
			$items[] = ['label' => 'Későbbi utalások', 'url' => ['/transfer/payment-later','TransferLaterSearch[start]' =>$todayDatetime,'TransferLaterSearch[end]' => $tomorrowDatetime ] ];
			//$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
			$this->menuItems[] = ['label' => 'Pénzügy', 'url' =>  $this->emptyUrl,
			'items' =>  $items
			];
			/////////////////////////////
			// Tartós megbízások
			/////////////////////////////
			$items = [];
			$items[] = ['label' => 'Szerződések', 'url' => ['/contract/index'   ] ];
			$items[] = ['label' => 'Megbízások', 'url' => ['/ticket-installment-request/index' , 'TicketInstallmentRequestSearch[start]' =>$today,'TicketInstallmentRequestSearch[end]' => $tomorrow ] ];
			$items[] = ['label' => 'Giro kötegbe jelölés', 'url' => ['/ticket-installment-request/pending' ,  'TicketInstallmentRequestSearchPending[end]' => $tomorrow ] ];
			$items[] = ['label' => 'GIRO köteg létrehozás', 'url' => ['/ticket-installment-request/download-giro'  ] ];
			$items[] = ['label' => 'GIRO kötegek', 'url' => ['/ugiro/index'  ] ];
			$items[] = ['label' => 'Detsta feltöltés', 'url' => ['/ugiro/upload'  ] ];
// 			$items[] = ['label' => 'Részletek aktiválása', 'url' => ['/ugiro/parts'  ] ];
// 			$items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
// 			$items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ];
// 			$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
			if ( RoleDefinition::isAdmin()   ){
			$this->menuItems[] = ['label' => 'Tartós megbízások', 'url' =>  $this->emptyUrl,
			'items' =>  $items
			];
			}
			/////////////////////////////
			// Kap lug megbízások
			/////////////////////////////
			$items = [];
			$items[] = ['label' => 'Kártya események', 'url' => ['/door-log/index' , 'DoorLogSearch[start]' =>$todayDatetime,'DoorLogSearch[end]' => $tomorrowDatetime ] ];
			$items[] = ['label' => 'Esemény napló', 'url' => ['/log/index' , 'LogSearch[start]' =>$todayDatetime,'LogSearch[end]' => $tomorrowDatetime ] ];
// 			$items[] = ['label' => 'Részletek aktiválása', 'url' => ['/ugiro/parts'  ] ];
// 			$items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
// 			$items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ];
// 			$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
			$this->menuItems[] = ['label' => 'Események', 'url' =>  $this->emptyUrl,
			'items' =>  $items
			];
			
			
			/////////////////////////////
			// Hírlevelek
			/////////////////////////////
			$items = [];
			$items[] = ['label' => 'Hírlevelek', 'url' => ['/newsletter/index' , 'NewsletterSearch[start]' =>$todayDatetime,'NewsletterSearch[end]' => $tomorrowDatetime ] ];
			// 			$items[] = ['label' => 'Részletek aktiválása', 'url' => ['/ugiro/parts'  ] ];
			// 			$items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
			// 			$items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ];
			// 			$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
			$this->menuItems[] = ['label' => 'Hírlevél', 'url' =>  $this->emptyUrl,
					'items' =>  $items
			];
			
		}
		
	}
	
	protected function addLoginMainMenu(){
		if (Yii::$app->user->isGuest) {
			$mainMenuItem= ['label' => Yii::t('common/site','Login'), 'url' => ['/site/login']];
		} else {
			$mainMenuItem= [
					'label' => Yii::t('common/site','Logout') . '(' . Yii::$app->user->identity->username . ')',
					'url' => ['/site/logout'],
					'linkOptions' => ['data-method' => 'post']
			];
		}
		$this->menuItems[] = $mainMenuItem;
	}
	
	
	public function run(){
		$this->addUserMainMenu();
// 		$this->addLoginMainMenu();
		return $this->menuItems;
	}
	
	
}
