<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use yii\widgets\Menu;
use yii\bootstrap\Tabs;

$this->title = 'Interface list';
$this->params['breadcrumbs'] = [
    'Mikrotik',
    $this->title,
];
?>
<div class="site-plugins">
    <div class="row">
        <div class="col-lg-3">
            <?php
            echo Menu::widget($menu);
            ?> 
        </div>
        <div class="col-md-9">
            <h1 style="margin-top: 0px"><?= Html::encode($this->title) ?></h1>

            <?php
            //var_dump($provider);
            $tabs[] = ['label' => 'Interfaces', 'content' => GridView::widget([
                    'dataProvider' => $provider['interfaces'],
                    'id' => 'interfaces',
                    'rowOptions' => function($provider) {
                        if ($provider->disabled == 'true') {
                            return ['class' => 'info',];
                        }
                        if ($provider->running == 'false') {
                            return ['class' => 'danger',];
                        }
                    },
                            'columns' => [
                                'name:text:Name',
                                'type:text:Type',
                                'l2mtu:text:L2 MTU',
                                'tx_byte:text:Total Tx',
                                'rx_byte:text:Total Rx',
                                'tx_packet:text:Total Tx Packets',
                                'rx_packet:text:Total Rx Packets',
                                [
                                    'class' => 'yii\grid\ActionColumn',
                                    'template' => '',
//                                    'buttons' => [
//                                        'update' => function ($url, $model, $key) {
//                                            return Html::a('toggle interface', $url);
//                                        },
//                                    ],
                                    'controller' => 'mikrotik/interfaces/interfaces',
//                        'footer' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
//                            'js:document.location.href="' . Url::toRoute('general/plugins/create') . '"']),
                                ],
                            ],
                            'showFooter' => false,
                        ])
                    ];

                    $tabs[] = ['label' => 'Ethernet', 'content' => GridView::widget([
                            'dataProvider' => $provider['ethernet'],
                            'id' => 'ethernet',
                            'rowOptions' => function($provider) {
                                if ($provider->disabled == 'true') {
                                    return ['class' => 'info',];
                                }
                                if ($provider->running == 'false') {
                                    return ['class' => 'danger',];
                                }
                            },
                                    'columns' => [
                                        'name:text:Name',
                                        'type:text:Type',
                                        'l2mtu:text:L2 MTU',
                                        'tx_bytes:text:Total Tx',
                                        'rx_bytes:text:Total Rx',
                                        'master_port:text:Master Port',
                                        [
                                            'class' => 'yii\grid\ActionColumn',
                                            'template' => '{update}',
                                            'controller' => 'mikrotik/interfaces/ethernet',
//                        'footer' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
//                            'js:document.location.href="' . Url::toRoute('general/plugins/create') . '"']),
                                        ],
                                    ],
                                    'showFooter' => false,
                                ])
                            ];
                            $tabs[] = ['label' => 'EoIP Tunnel', 'content' => GridView::widget([
                                    'dataProvider' => $provider['eoip'],
                                    'id' => 'ethernet',
                                    'rowOptions' => function($provider) {
                                        if ($provider->disabled == 'true') {
                                            return ['class' => 'info',];
                                        }
                                        if ($provider->running == 'false') {
                                            return ['class' => 'danger',];
                                        }
                                    },
                                            'columns' => [
                                                'name:text:Name',
                                                'type:text:Type',
                                                'actual_mtu:text:Actual MTU',
                                                'l2mtu:text:L2 MTU',
                                                [
                                                    'class' => 'yii\grid\ActionColumn',
                                                    'template' => '{update} {delete}',
                                                    'controller' => 'mikrotik/interfaces/eoip',
                                                    'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                        'js:document.location.href="' . Url::toRoute('mikrotik/interfaces/eoip/create') . '"']),
                                                ],
                                            ],
                                            'showFooter' => false,
                                        ])
                                    ];
                                    $tabs[] = ['label' => 'IP Tunnel', 'content' => GridView::widget([
                                            'dataProvider' => $provider['ip'],
                                            'id' => 'ethernet',
                                            'rowOptions' => function($provider) {
                                                if ($provider->disabled == 'true') {
                                                    return ['class' => 'info',];
                                                }
                                            },
                                                    'columns' => [
                                                        'name:text:Name',
                                                        'type:text:Type',
                                                        [
                                                            'class' => 'yii\grid\ActionColumn',
                                                            'template' => '{update} {delete}',
                                                            'controller' => 'mikrotik/interfaces/ip',
                                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                'js:document.location.href="' . Url::toRoute('mikrotik/interfaces/ip/create') . '"']),
                                                        ],
                                                    ],
                                                    'showFooter' => false,
                                                ])
                                            ];
                                            $tabs[] = ['label' => 'GRE Tunnel', 'content' => GridView::widget([
                                                    'dataProvider' => $provider['gre'],
                                                    'id' => 'ethernet',
                                                    'rowOptions' => function($provider) {
                                                        if ($provider->disabled == 'true') {
                                                            return ['class' => 'info',];
                                                        }
                                                    },
                                                            'columns' => [
                                                                'name:text:Name',
                                                                'type:text:Type',
                                                                [
                                                                    'class' => 'yii\grid\ActionColumn',
                                                                    'template' => '{update} {delete}',
                                                                    'controller' => 'mikrotik/interfaces/gre',
                                                                    'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                        'js:document.location.href="' . Url::toRoute('mikrotik/interfaces/gre/create') . '"']),
                                                                ],
                                                            ],
                                                            'showFooter' => false,
                                                        ])
                                                    ];
                                                    $tabs[] = ['label' => 'VLAN', 'content' => GridView::widget([
                                                            'dataProvider' => $provider['vlan'],
                                                            'id' => 'ethernet',
                                                            'rowOptions' => function($provider) {
                                                                if ($provider->disabled == 'true') {
                                                                    return ['class' => 'info',];
                                                                }
                                                            },
                                                                    'columns' => [
                                                                        'name:text:Name',
                                                                        'type:text:Type',
                                                                        [
                                                                            'class' => 'yii\grid\ActionColumn',
                                                                            'template' => '{update} {delete}',
                                                                            'controller' => 'mikrotik/interfaces/vlan',
                                                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                                'js:document.location.href="' . Url::toRoute('mikrotik/interfaces/vlan/create') . '"']),
                                                                        ],
                                                                    ],
                                                                    'showFooter' => false,
                                                                ])
                                                            ];
                                                            $tabs[] = ['label' => 'VRRP', 'content' => GridView::widget([
                                                                    'dataProvider' => $provider['vrrp'],
                                                                    'id' => 'ethernet',
                                                                    'rowOptions' => function($provider) {
                                                                        if ($provider->disabled == 'true') {
                                                                            return ['class' => 'info',];
                                                                        }
                                                                    },
                                                                            'columns' => [
                                                                                'name:text:Name',
                                                                                'type:text:Type',
                                                                                [
                                                                                    'class' => 'yii\grid\ActionColumn',
                                                                                    'template' => '{update} {delete}',
                                                                                    'controller' => 'mikrotik/interfaces/vrrp',
                                                                                    'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                                        'js:document.location.href="' . Url::toRoute('mikrotik/interfaces/vrrp/create') . '"']),
                                                                                ],
                                                                            ],
                                                                            'showFooter' => false,
                                                                        ])
                                                                    ];
                                                                    $tabs[] = ['label' => 'Bonding', 'content' => GridView::widget([
                                                                            'dataProvider' => $provider['bonding'],
                                                                            'id' => 'ethernet',
                                                                            'rowOptions' => function($provider) {
                                                                                if ($provider->disabled == 'true') {
                                                                                    return ['class' => 'info',];
                                                                                }
                                                                            },
                                                                                    'columns' => [
                                                                                        'name:text:Name',
                                                                                        'type:text:Type',
                                                                                        [
                                                                                            'class' => 'yii\grid\ActionColumn',
                                                                                            'template' => '{update} {delete}',
                                                                                            'controller' => 'mikrotik/interfaces/bonding',
                                                                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                                                'js:document.location.href="' . Url::toRoute('mikrotik/interfaces/bonding/create') . '"']),
                                                                                        ],
                                                                                    ],
                                                                                    'showFooter' => false,
                                                                                ])
                                                                            ];
                                                                            echo Tabs::widget([
                                                                                'items' => $tabs]);
                                                                            ?>



        </div>
    </div>
</div>



