<?php
namespace App\Controllers;

use App\Controllers\BaseController;

class BackendController extends BaseController {
    
    public $g_arrmixBackendSessionDetails;
    public $session;

    public static $s_arrmixBackendSessionDetails;
    
    public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
	    parent::initController($request, $response, $logger);
        
        if( false == $this->session ) {
            $this->session = \Config\Services::session();
        }
        
        if( true == isValArr( $this->session->get( 'backend_session' ) ) ) {
            $this->g_arrmixBackendSessionDetails = $this->session->get( 'backend_session' );
            self::$s_arrmixBackendSessionDetails = $this->session->get( 'backend_session' );
        }
        
    }            
    
    public function render( $arrmixData ) {
        $arrmixData['arrmixFlashData'] = $this->session->getFlashData();
        
        if( true == isset( $arrmixData['boolIsHeaderFooter'] ) ) {
            includesHeaderFooter( $arrmixData );
        } else {
            $arrmixData['g_arrmixBackendSessionDetails'] = $this->g_arrmixBackendSessionDetails;
            $arrmixData['arrmixUriSegmentData'] = $this->request->getUri()->getSegments();
            includesAll( $arrmixData );
        }
    }

    public function renderPartial( $arrmixData ) {
        $arrmixData['arrmixFlashData'] = $this->session->getFlashData();
        
        if( true == isset( $arrmixData['is_return_view_content'] ) ) {
            return view( 'backend/' . $arrmixData['view'], $arrmixData );
        }
        
        echo view( 'backend/' . $arrmixData['view'], $arrmixData );
    }
    
    public function showAlertMessage( $arrmixFlashData ) {
        
        if( true == isValArr( $arrmixFlashData ) ) {
            $arrmixData = [];
            
            if( true == isset( $arrmixFlashData['success'] ) ) {
                $arrmixData['strSuccessMessage'] = $arrmixFlashData['success'];
            } else if( true == isset( $arrmixFlashData['error'] ) ) {
                $arrmixData['strErrorMessage'] = $arrmixFlashData['error'];
            } else if( true == isset( $arrmixFlashData['info'] ) ) {
                $arrmixData['strInfoMessage'] =  $arrmixFlashData['info'];
            } else if( true == isset( $arrmixFlashData['warning'] ) ) {
                $arrmixData['strWarningMessage'] =  $arrmixFlashData['warning'];
            } 
            
            echo view( 'backend/includes/alert', $arrmixData );
        }
    }
    
    public function showBreadCrumbs( $arrmixBreadCrumbData ) {
        echo view( 'backend/includes/breadcrumb', $arrmixBreadCrumbData );
    }
   
}
