<?php

namespace App\Providers\ExcelGroupUnitaryReport;

class PassengerCells extends ExcelPage {

      public function run ($oGroup, $oData) {
        $height = 10;
        
        if($oGroup->Group_ServiceType==2){
            $height = 12;
        }
        if($oGroup->Group_ServiceType>2){
            $height = 13;
        }
        $height++;
        $oPassengers = $oGroup->Passenger;

        $result = [];
        for ($i = 0; $i < $height; $i++) {
            $result[] = [];
        }
                    
        
        $result = array_merge($result, $this->passengerFirst ($oPassengers));
        $result[] = [];
        $result[] = [];
        $result = array_merge($result, $this->passengerSecond ($oPassengers));
        // $result[] = [];
        // $result[] = [];
        // $result[] = [];
        // $result[] = [];
        // $result[] = [];
        // $result[] = [];
        // $result = array_merge( $result, $this->Providers($oGroup->Group_Slaves[0]->Providers) );
        // $result[] = [];
        // $result = array_merge( $result, $this->passengerFirstSlave($oGroup->Group_Slaves[0]->Passenger) );
        // $result[] = [];
        // $result[] = [];
        // $result = array_merge( $result, $this->passengerSecond($oGroup->Group_Slaves[0]->Passenger) );
        $result[] = [];
        if(count($oGroup->Group_Slaves)>0){
            $result[] = [];
        };
        for($i = 0; $i < count($oGroup->Group_Slaves); $i++){

            $result[] = [];
            $result[] = [];
            $result[] = [];
            $result[] = [];
            
            if($oGroup->Group_Slaves[$i]->Group_ServiceType==2){
                $result[] = [];
                $result[] = [];
            }
            if($oGroup->Group_Slaves[$i]->Group_ServiceType>2){
                $result[] = [];
                $result[] = [];
                $result[] = [];
            }
            $result = array_merge( $result, $this->Providers($oGroup->Group_Slaves[$i]->Providers) );
            $result[] = [];
            $result = array_merge( $result, $this->passengerFirstSlave($oGroup->Group_Slaves[$i]->Passenger) );
            $result[] = [];
            $result[] = [];
            $result = array_merge( $result, $this->passengerSecond($oGroup->Group_Slaves[$i]->Passenger) );
        }
        return $result;
    }

    public function passengerFirst ($oPassengers) {
        $result = [];
        $result = [[
            [ 'action' => ''],
            [ 'action' => 'merge', 'lines' => 1],
            [ 'action' => ''],
            [ 'action' => ''],
            [ 'action' => ''],
            [ 'action' => ''],
            [ 'action' => 'merge', 'lines' => 1],
        ]];
        
        foreach ($oPassengers as $oPassenger) {
            $result[] = [
                [ 'action' => ''],
                [ 'action' => 'merge', 'lines' => 1],
                [ 'action' => ''],
                [ 'action' => ''],
                [ 'action' => ''],
                [ 'action' => ''],
                [ 'action' => 'merge', 'lines' => 1],
            ];
        }
        return $result;
    }
    public function passengerFirstSlave ($oPassengers) {
        $result = [];
        $result = [[
            [ 'action' => ''],
            [ 'action' => 'merge', 'lines' => 1],
            [ 'action' => ''],
            [ 'action' => ''],
            [ 'action' => ''],
            [ 'action' => ''],
            [ 'action' => 'merge', 'lines' => 1],
        ]];
        foreach ($oPassengers as $oPassenger) {
            $result[] = [
                [ 'action' => ''],
                [ 'action' => 'merge', 'lines' => 1],
                [ 'action' => ''],
                [ 'action' => ''],
                [ 'action' => ''],
                [ 'action' => ''],
                [ 'action' => 'merge', 'lines' => 1],
            ];
        }
        return $result;
    }
    public function passengerSecond ($oPassengers) {
        $result = [[
            [ 'action' => ''],
            [ 'action' => 'merge', 'lines' => 1],
        ]];
        foreach ($oPassengers as $oPassenger) {
            $result[] = [
                [ 'action' => ''],
                [ 'action' => 'merge', 'lines' => 1],
            ];
        }
        return $result;
    }
    
    public function Providers ($oProviders) {
        $length= ceil(Count($oProviders) / 2);
        $result=[];
        for($k = 0; $k < $length; $k++){	
            $result[] = [];
        }
        return $result;
    }

}