<?php

use common\widgets\GridView;
use yii\helpers\Html;
use backend\models\Attributesvalues;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\AccountsSerach */
/* @var $dataProvider yii\data\ActiveDataProvider */

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

    <?=GridView::widget([
        //'new' => ,
        'search' => $this->render('_search', ['model' => $searchModel]),
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'responsive' => true,
        'columns' => [
            [
                'class' => common\widgets\ActionColumn::class,
                'header'    => 'Action',
                'target' => '_blank',
            ],
            [
                'attribute' => 'type',
                'value' => 'type',
                'filter' => Attributesvalues::formArray('account_type'),
            ],
            'account_code',
            'name',
            [
                'attribute' => 'address',
                'format' => 'raw',
                'value' => function ($dataModel) {
                    return $dataModel->addressl?->fulladdress;
                }
            ],
            [
                'attribute' => 'telephone',
                'value' => 'addressl.telephone'
            ],
            'stop:boolean',
            // 'PRICE_NO',
            [
                'label' => 'Email',
                'attribute' => 'email',
                'value' => 'email',
                'format' => 'email',
            ],
            [
                'label' => 'Points',
                'attribute' => 'extended.loyalty_points',
                'format' => 'integer',
                'value' => function ($dataModel) {
                    return property_exists($dataModel->extended, 'loyalty_points') ? $dataModel->extended->loyalty_points : false;
                },
                'visible' => function ($dataModel) {
                    return property_exists($dataModel->extended, 'loyalty_points') ? true : false;
                },
            ],
            [
                'class' => common\widgets\TraceabilityColumn::class,
                'attribute' => 'traceability',
                'format' => 'raw',
            ],

        ],
    ]);?>
</div>
