<?php

use yii\helpers\Html;
use yii\grid\GridView;

$this->title = 'Estado: ' . $estado;
$this->params['breadcrumbs'][] = ['label' => 'Dashboard', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="dashboard-ver-estado">
    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('← Volver al Dashboard', ['index'], ['class' => 'btn btn-default']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'tableOptions' => ['class' => 'table table-striped table-bordered'],
        'columns' => [
            // Tipo de Documento
            [
                'label' => 'Tipo',
                'format' => 'raw',
                'value' => function ($model) {
                    if ($model->tipo_documento === 'CLAC') {
                        return '<span class="label label-danger">CLAC</span>';
                    }
                    if ($model->tipo_documento === 'TBS') {
                        return '<span class="label label-warning">TBS</span>';
                    }
                    return Html::encode($model->tipo_documento);
                },
                'contentOptions' => ['style' => 'text-align: center; width: 80px;'],
            ],

            // Número de Documento
            [
                'attribute' => 'numero_orden',
                'label' => 'N° Documento',
                'format' => 'raw',
                'value' => function($model) {
                    return '<strong style="font-size: 14px;">' . Html::encode($model->numero_orden) . '</strong>';
                },
                'contentOptions' => ['style' => 'width: 150px;'],
            ],

            // Fecha
            [
                'attribute' => 'fecha_cotizacion',
                'label' => 'Fecha de Creación',
                'format' => ['date', 'php:d/m/Y H:i'],
                'contentOptions' => ['style' => 'width: 150px;'],
            ],

            // Cliente
            [
                'label' => 'Cliente',
                'value' => function($model) {
                    return $model->cliente ? $model->cliente->nombre_razon_social : 'N/A';
                },
            ],

            // Cantidad de Items
            [
                'label' => 'Items',
                'format' => 'raw',
                'value' => function($model) {
                    $count = count($model->cotizacionItems);
                    return '<span class="badge" style="background-color: #5bc0de; font-size: 13px;">' . $count . '</span>';
                },
                'contentOptions' => ['style' => 'text-align: center; width: 80px;'],
            ],

            // Acciones
            [
                'label' => 'Acciones',
                'format' => 'raw',
                'value' => function ($model) {
                    return Html::a(
                        '<span class="glyphicon glyphicon-eye-open"></span> Ver Detalles',
                        ['/cotizaciones/view', 'id' => $model->id],
                        ['class' => 'btn btn-sm btn-info']
                    );
                },
                'contentOptions' => ['style' => 'text-align: center; width: 120px;'],
            ],
        ],
    ]); ?>
</div>

<style>
.table > tbody > tr > td {
    vertical-align: middle !important;
}
</style>