<?php

use yii\bootstrap\Alert;

if (Yii::$app->session->getFlash('message') != null) {
    echo Alert::widget([
        'options' => [
            'class' => 'alert-info',
        ],
        'body' => Yii::$app->session->getFlash('message'),
    ]);
}

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

$this->title = 'BGP';
$this->params['breadcrumbs'] = [
    'Mikrotik',
    'Routing',
    $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' => 'Instances', 'content' => GridView::widget([
                    'dataProvider' => $provider['instances'],
                    'id' => 'interfaces',
                    'rowOptions' => function($provider) {
                        if ($provider->disabled == 'true') {
                            return ['class' => 'info',];
                        }
                    },
                            'columns' => [
                                'name:text:Name',
                                'as:text:AS',
                                'router_id:text:Router ID',
                                'out_filter:text:Out Filter',
                                'cluster_id:text:Cluster ID',
                                [
                                    'class' => 'yii\grid\ActionColumn',
                                    'template' => '{update} {delete}',
                                    'controller' => 'mikrotik/routing/bgp/instances',
                                    'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                        'js:document.location.href="' . Url::toRoute('mikrotik/routing/bgp/instances/create') . '"']),
                                ],
                            ],
                            'showFooter' => false,
                        ])
                    ];
                    $tabs[] = ['label' => 'VRFs', 'content' => GridView::widget([
                            'dataProvider' => $provider['vrf'],
                            'id' => 'interfaces',
                            'rowOptions' => function($provider) {
                                if ($provider->disabled == 'true') {
                                    return ['class' => 'info',];
                                }
                            },
                                    'columns' => [
                                        'instance:text:Instance',
                                        'routing_mark:text:Routing Mark',
                                        'in_filter:text:In Filter',
                                        'out_filter:text:Out Filter',
                                        [
                                            'class' => 'yii\grid\ActionColumn',
                                            'template' => '{update} {delete}',
                                            'controller' => 'mikrotik/routing/bgp/vrf',
                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                'js:document.location.href="' . Url::toRoute('mikrotik/routing/bgp/vrf/create') . '"']),
                                        ],
                                    ],
                                    'showFooter' => false,
                                ])
                            ];
                            $tabs[] = ['label' => 'Peers', 'content' => GridView::widget([

                                    'dataProvider' => $provider['peer'],
                                    'id' => 'interfaces',
                                    'rowOptions' => function($provider) {
                                        if ($provider->disabled == 'true') {
                                            return ['class' => 'info',];
                                        }
                                    },
                                            'columns' => [
                                                'name:text:Name',
                                                'instance:text:Instance',
                                                'remote_address:text:Remote Address',
                                                'remote_as:text:Remote AS',
                                                'multihop:text:Multihop',
                                                'route_reflect:text:Route Reflect',
                                                'ttl:text:TTL',
                                                [
                                                    'class' => 'yii\grid\ActionColumn',
                                                    'template' => '{update} {delete}',
                                                    'controller' => 'mikrotik/routing/bgp/peer',
                                                    'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                        'js:document.location.href="' . Url::toRoute('mikrotik/routing/bgp/peer/create') . '"']),
                                                    'footer' => Html::button('Refresh All', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                        'js:document.location.href="' . Url::toRoute('mikrotik/routing/bgp/peer/refresh') . '"']) . " " . Html::button('Resend All', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                        'js:document.location.href="' . Url::toRoute('mikrotik/routing/bgp/peer/resend') . '"'])
                                                ],
                                            ],
                                            'showFooter' => true,
                                        ])
                                    ];
                                    $tabs[] = ['label' => 'Networks', 'content' => GridView::widget([

                                            'dataProvider' => $provider['network'],
                                            'id' => 'interfaces',
                                            'rowOptions' => function($provider) {
                                                if ($provider->disabled == 'true') {
                                                    return ['class' => 'info',];
                                                }
                                            },
                                                    'columns' => [
                                                        'network:text:Network',
                                                        'synchronize:text:Synchronize',
                                                        [
                                                            'class' => 'yii\grid\ActionColumn',
                                                            'template' => '{update} {delete}',
                                                            'controller' => 'mikrotik/routing/bgp/networks',
                                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                'js:document.location.href="' . Url::toRoute('mikrotik/routing/bgp/networks/create') . '"']),
                                                        ],
                                                    ],
                                                    'showFooter' => false,
                                                ])
                                            ];
                                            $tabs[] = ['label' => 'Aggregates', 'content' => GridView::widget([

                                                    'dataProvider' => $provider['ags'],
                                                    'id' => 'interfaces',
                                                    'rowOptions' => function($provider) {
                                                        if ($provider->disabled == 'true') {
                                                            return ['class' => 'info',];
                                                        }
                                                    },
                                                            'columns' => [
                                                                'prefix:text:Prefix',
                                                                'summary_only:text:Summary Only',
                                                                'inherit_attributes:text:Inherit Attributes',
                                                                'include_igp:text:Include IGP',
                                                                'attribute_filter:text:Attribute Filter',
                                                                'suppress_filter:text:Supress Filter',
                                                                'advertise_filter:text:Advertise Filter',
                                                                [
                                                                    'class' => 'yii\grid\ActionColumn',
                                                                    'template' => '{update} {delete}',
                                                                    'controller' => 'mikrotik/routing/bgp/aggregate',
                                                                    'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                        'js:document.location.href="' . Url::toRoute('mikrotik/routing/bgp/aggregate/create') . '"']),
                                                                ],
                                                            ],
                                                            'showFooter' => false,
                                                        ])
                                                    ];
                                                    $tabs[] = ['label' => 'VPNV4 Routes', 'content' => GridView::widget([
                                                            'dataProvider' => $provider['route'],
                                                            'id' => 'interfaces',
                                                            'columns' => [
                                                                'route_distinguisher:text:Route Distinguisher',
                                                                'dst_address:text:Dst. Address',
                                                                'gateway:text:Gateway',
                                                                'interface:text:Interface',
                                                                'in_label:text:In Label',
                                                                'out_label:text:Out Label',
                                                                [
                                                                    'class' => 'yii\grid\ActionColumn',
                                                                    'template' => '',
                                                                    'controller' => 'mikrotik/routing/bgp/bgp',
                                                                ],
                                                            ],
                                                            'showFooter' => false,
                                                        ])
                                                    ];
                                                    $tabs[] = ['label' => 'Advertisements', 'content' => GridView::widget([
                                                            'dataProvider' => $provider['advertisements'],
                                                            'id' => 'interfaces',
                                                            'columns' => [
                                                                'peer:text:Peer',
                                                                'prefix:text:Prefix',
                                                                'nexthop:text:Nexthop',
                                                                'as_path:text:AS Path',
                                                                'origin:text:Origin',
                                                                'local_pref:text:Local Pref.',
                                                                'med:text:MED',
                                                                [
                                                                    'class' => 'yii\grid\ActionColumn',
                                                                    'template' => '',
                                                                    'controller' => 'mikrotik/routing/bgp/bgp',
                                                                ],
                                                            ],
                                                            'showFooter' => false,
                                                        ])
                                                    ];
                                                    echo Tabs::widget([
                                                        'items' => $tabs]);
                                                    ?>



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



