<?php 
use yii\helpers\Html; 
function renderCheckLabel($model, $fieldName, $targetValue) {
    $label = $model->getAttributeLabel($fieldName);
    $value = $model->{$fieldName};
    if (empty($value) && $value !== '0') {
        return $label;
    } else {
        $icon = $value == $targetValue ? 'check' : 'times';
        $class = $value == $targetValue ? 'checkbox-blue' : 'checkbox-red';
        return "<span class=\"$class\"><i class=\"fas fa-$icon text-white\"></i></span> $label";
    }
}
?>
<style>

    .table td {
        text-transform: unset !important;
        text-align: left !important;
        font-size: smaller !important;
        background: var(--table-bg);
        color: var(--table-text);
    }
    .table th {
        text-transform: unset !important;
        text-align: left !important;
        font-size: smaller !important;
        background: var(--table-th-bg);
        color: var(--table-text);
    }
    .bg-light {
        background-color: var(--table-th-bg) !important;
    }
</style>
<div class="row">
    <div class="col">
        <img height="auto" width="200px" src="https://my.inlinetrack.co.uk/images/InlineLogo.png" />
    </div>
</div>
<br />
<table class="table table-outline table-bordered">
    <tr>
        <th><?= $model->getAttributeLabel('jobno') ?></th>
        <th><?= $model->getAttributeLabel('location') ?></th>
        <th colspan="2"><?= $model->getAttributeLabel('employees_on_site') ?></th>
        <th><?= $model->getAttributeLabel('duration_of_works') ?></th>
        <th><?= $model->getAttributeLabel('start_date') ?></th>
        <th><?= $model->getAttributeLabel('finish_date') ?></th>
        <th colspan="2"><?= $model->getAttributeLabel('type_of_facilities') ?></th>
    </tr>
    <tr>
        <td><?= Html::encode($model->jobno) ?></td>
        <td><?= Html::encode($model->location) ?></td>
        <td colspan="2"><?= Html::encode($model->employees_on_site) ?></td>
        <td><?= Html::encode($model->duration_of_works) ?></td>
        <td><?= Html::encode($model->start_date) ?></td>
        <td><?= Html::encode($model->finish_date) ?></td>
        <td>
            <?= Html::CheckBox('type_of_facilities', $model->type_of_facilities == 'Non-transient', ['label' => 'Non-transient']) ?> 
        </td>
        <td>
            <?= Html::CheckBox('type_of_facilities', $model->type_of_facilities == 'Transient', ['label' => 'Transient']) ?> 
        </td>
    </tr>
    <tr>
        <th colspan="3" class="bg-light">
            Table 1 - mixed gender (male & female) use or female only use
        </th>
        <th colspan="4" class="bg-light">
            Table 2 -  single gender (male) staff
        </th>
        <th colspan="2" rowspan="2">
            <?= $model->getAttributeLabel('separate_facilities_disabled'); ?>
        </th>
    </tr>
    <tr>
        <td>
            <?= $model->getAttributeLabel('t1_people_at_work') ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('t1_no_of_toilets') ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('t1_no_of_washbasins') ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('t2_people_at_work') ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('t2_no_of_toilets') ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('t2_no_of_urinals') ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('t2_no_of_washbasins') ?>
        </td>
    </tr>
    <?php $x = 0; ?>
    <?php while($x <= 2){ $x++; ?>
        <tr>
            <td rowspan="">
                <?= renderCheckLabel($model, "t1_people_at_work$x", $x);?>
            </td>
            <td rowspan="">
                <?= renderCheckLabel($model, "t1_no_of_toilets$x", true);?>
            </td>
            <td rowspan="">
                <?= renderCheckLabel($model, "t1_no_of_washbasins$x", true);?>
            </td>
            <td rowspan="">
                <?= renderCheckLabel($model, "t2_people_at_work$x", $x);?>
            </td>
            <td rowspan="">
                <?= renderCheckLabel($model, "t2_no_of_toilets$x", true);?>
            </td>
            <td rowspan="">
                <?= renderCheckLabel($model, "t2_no_of_urinals$x", true);?>
            </td>
            <td rowspan="">
                <?= renderCheckLabel($model, "t2_no_of_washbasins$x", true);?>
            </td>
            <?php if($x == 1){ ?>
                <td>
                    <?= Html::CheckBox('separate_facilities_disabled', $model->separate_facilities_disabled == 'Yes', ['label' => 'Yes']) ?> 
                </td>
                <td>
                    <?= Html::CheckBox('separate_facilities_disabled', $model->separate_facilities_disabled == 'No', ['label' => 'No']) ?> 
                </td>
            <?php }?>
            <?php if($x == 2){ ?>
                <td rowspan="2">
                    <?= $model->separate_facilities_disabled_no ?>
                </td>
                <td rowspan="2">
                    <?= $model->getAttributeLabel('separate_facilities_disabled_no'); ?>
                </td>
            <?php }?>
        </tr>
    <?php }?>
    <tr>
        <td colspan="9" class="bg-light">&nbsp;</td>
    </tr>
    <tr>
        <td>
            <?= $model->getAttributeLabel('water_supply'); ?>
        </td>
        <td>
            <?= Html::CheckBox('water_supply', $model->water_supply == 'Mains Water', ['label' => 'Mains Water', ]) ?>
        </td>
        <td>
            <?= Html::CheckBox('water_supply', $model->water_supply == 'Bottled Water', ['label' => 'Bottled Water', ]) ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('nutritional_facilities'); ?>
        </td>
        <td>
            <?= Html::CheckBox('nutritional_facilities', $model->nutritional_facilities == 'Yes', ['label' => 'Yes', ]) ?>
        </td>
        <td>
            <?= Html::CheckBox('nutritional_facilities', $model->nutritional_facilities == 'No', ['label' => 'No', ]) ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('changing_facilities'); ?>
        </td>
        <td>
            <?= Html::CheckBox('changing_facilities', $model->changing_facilities == 'Yes', ['label' => 'Yes', ]) ?>
        </td>
        <td>
            <?= Html::CheckBox('changing_facilities', $model->changing_facilities == 'No', ['label' => 'No', ]) ?>
        </td>
    </tr>
    <tr>
        <td>
            <?= $model->getAttributeLabel('break_locations'); ?>
        </td>
        <td>
            <?= Html::CheckBox('break_locations', $model->break_locations == 'Yes', ['label' => 'Yes', ]) ?>
        </td>
        <td>
            <?= Html::CheckBox('break_locations', $model->break_locations == 'No', ['label' => 'No', ]) ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('temperature_control'); ?>
        </td>
        <td>
            <?= Html::CheckBox('temperature_control', $model->temperature_control == 'Yes', ['label' => 'Yes', ]) ?>
        </td>
        <td>
            <?= Html::CheckBox('temperature_control', $model->temperature_control == 'No', ['label' => 'No', ]) ?>
        </td>
        <td>
            <?= $model->getAttributeLabel('lockers'); ?>
        </td>
        <td>
            <?= Html::CheckBox('lockers', $model->lockers == 'Yes', ['label' => 'Yes', ]) ?>
        </td>
        <td>
            <?= Html::CheckBox('lockers', $model->lockers == 'No', ['label' => 'No', ]) ?>
        </td>
    </tr>
    <tr>
        <td colspan="9">
            <?= $model->getAttributeLabel('explanation'); ?><br>
            <?= Html::encode($model->explanation) ?>
        </td>
    </tr>
    <tr>
        <td colspan="9" >
            <?= $model->getAttributeLabel('comments'); ?><br>
            <?= Html::encode($model->comments) ?>
        </td>
    </tr>
</table>