<?php

use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\models\ProductoSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Productos';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="producto-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Crear Producto', ['create'], ['class' => 'btn btn-success']) ?>
    </p>


<?php

$columns = [
    ['class' => 'yii\grid\SerialColumn'],

    [
        'attribute' => 'id',
        'headerOptions' => ['class' => 'text-center'],
        'contentOptions' => ['class' => 'text-center']
    ],

    [
        'attribute' => 'codigo',
        'headerOptions' => ['class' => 'text-center'],
        'contentOptions' => ['class' => 'text-center']
    ],     

    [
        'attribute' => 'nombre',
        'headerOptions' => ['class' => 'text-center'],
        'contentOptions' => ['class' => 'text-center']
    ],       

    [
        'attribute' => 'sello', 
        'label' => 'Sello',
        'format' => 'raw', 
        'value' => function($model) {
            if ($model->sello != '') {
                return Html::tag('span', '   ============== ', [
                    'class' => 'badge ',
                    'style' => 'background-color:'.$model->sello
                ]);
            } 
        },
    ],

    [
        'class' => 'yii\grid\ActionColumn',
        'template' => '{update} {delete}',
        'buttons' => [
            'update' => function ($url, $model, $key) {
                return Html::a('<i class="bi bi-pencil"></i>', $url, [
                    'title' => 'Actualizar',
                    'data-pjax' => '0',
                    'class' => 'btn btn-sm btn-primary',
                ]);
            },
            'delete' => function ($url, $model, $key) {
                return Html::a('<i class="bi bi-trash"></i>', $url, [
                    'title' => 'Eliminar',
                    'data-pjax' => '0',
                    'data-confirm' => '¿Está seguro de eliminar este elemento?',
                    'data-method' => 'post',
                    'class' => 'btn btn-sm btn-danger',
                ]);
            },
        ],
    ]
];

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => $columns,
    'options' => ['class' => 'table-responsive'],
    'tableOptions' => ['class' => 'table table-striped table-bordered'],
    'pager' => [
        'options' => ['class' => 'pagination justify-content-end'],
        'linkContainerOptions' => ['class' => 'page-item'],
        'linkOptions' => ['class' => 'page-link']
    ],
    'summary' => '<div class="summary">Mostrando <b>{begin}-{end}</b> de <b>{totalCount}</b> elementos</div>',
    'layout' => "{summary}\n{items}\n<div class='card-footer clearfix'>{pager}</div>",
]);

?>
</div>

</div>
