<?php
$mot_tipo = isset($data->Motivo->MOT_TIPO) ? $data->Motivo->MOT_TIPO : null;

if (!in_array($data->ATD_IDMOTIVO, [464, 467, 455, 454])) {
    if($mot_tipo == 1) {
        $this->renderPartial('/atendimentos/_sav_view', array('data' => $data));
    } else if($data->ATD_TIPO == "D") {
        $this->renderPartial('/atendimentos/_dview', array('data' => $data));
    } else {
        $this->renderPartial('/atendimentos/_view', array('data' => $data));
    }
} else {
    $to = isset($CLI_EMAIL) ? $CLI_EMAIL : '';
    $link = Util::linkEmailAtendimento($data, $to);
?>

<div class="info-cliente atendimentos">
    <div class="col-xs-12 header">
        <a data-toggle='tooltip' data-placement='right' class="col-xs-2" title='Avaliação de Satistação'>
            <i class="fa fa-comments-o"></i> Código: <?php echo $data->ATD_IDATENDIMENTO; ?>
        </a>
        <ul class="col-xs-10 text-right">
            <li><a href="<?php echo $link; ?>"><?php echo FaHtml::iconMail(); ?></a></li>
            <?php
            $ExplodeTipo = explode(',', $data->ATD_TIPO);
            if (($data->ATD_TIPO == "V" or @in_array('V', $ExplodeTipo)) and $data->Motivo->MOT_TIPO == 1) {
            ?>
                <li><a href="<?php echo Yii::app()->createUrl('atendimentos/pdf', array('id'=>$data->ATD_IDATENDIMENTO)); ?>" target="_blank"><?php echo FaHtml::iconPdf(); ?></a></li>
            <?php } ?>
            <?php if ($data->getLinkEditar()) { ?>
                <li><a href="<?php echo Yii::app()->createUrl('atendimentos/'.$data->getLinkEditar(), array('id' => $data->ATD_IDATENDIMENTO, 'retorno' => Yii::app()->controller->action->id)); ?>"><?php echo FaHtml::iconUpdate(); ?></a></li>
            <?php } ?>
            <?php if (User::isAdmin()) { ?>
                <li><a href="<?php echo Yii::app()->createUrl('atendimentos/savdelete', array('id'=>$data->ATD_IDATENDIMENTO)); ?>" onclick="return confirm('Deseja realmente excluir este item?');"><?php echo FaHtml::iconDelete(); ?></a></li>
            <?php } ?>
        </ul>
    </div>
    <?php $last = 'odd'; ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="solicitacoes-view">
        <tr class="<?php echo $last = ($last=='even'?'odd':'even'); ?>">
            <td width="5%"><strong>Data</strong></td>
            <td width="15%"><?php echo $data->ATD_DTCADASTRO; ?></td>
            <td width="5%"><strong>Horário</strong></td>
            <td width="15%">
                <?php
                    echo substr($data->ATD_HORAINICIO, 0, 5);
                    if(isset($data->ATD_HORAFINAL)){
                        echo " às ".substr($data->ATD_HORAFINAL, 0, 5);
                    }
                ?>
            </td>
            <td width="10%"><strong>Total de Horas</strong></td>
            <td width="20%"><?php echo substr($data->ATD_TOTALHORAS, 0, 5); ?></td>
            <td width="5%"><strong>Atendente</strong></td>
            <td width="25%"><?php echo $data->Atendente; ?></td>
        </tr>
        <tr class="<?php echo $last = ($last=='even'?'odd':'even'); ?>">
            <td><strong>Tipo</strong></td>
            <td><?php echo Util::getTipoAtendimento(explode(',', $data->ATD_TIPO)); ?></td>
            <td><strong>Situação</strong></td>
            <td><?php echo Util::getSituacaoAtendimento($data->ATD_SITUACAO); ?></td>
            <td><strong>Motivo</strong></td>
            <td colspan="2"><?php echo $data->Motivo; ?></td>
            <td></td>
        </tr>
        <tr class="<?php echo $last = ($last=='even'?'odd':'even'); ?>">
            <?php if($data->ATD_IDMOTIVO == 455) { ?>
                <td><strong>Grau de satisfação</strong></td>
                <td><?php echo $data->getSatisfacao('ATD_NOTA_SATISFACAO_IMPLANTACAO'); ?></td>
                <td><strong>Contato</strong></td>
                <td><?php echo $data->ATD_CONTATO; ?></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            <?php } else { ?>
                <td><strong>Contato</strong></td>
                <td colspan="7"><?php echo $data->ATD_CONTATO; ?></td>
            <?php } ?>
        </tr>
        <tr class="<?php echo $last = ($last=='even'?'odd':'even'); ?>">
            <td><strong>Descrição</strong></td>
            <td colspan="7" class="overflow-break-word">
                <?php echo Util::niceTextAtendimentos($data->ATD_OBS); ?>
                <?php if (!empty($data->ATD_UPDATE)) { ?>
                    <a class="toggle_atendimentos_update" href="#" data-toggle="toggle_<?php echo $data->ATD_IDATENDIMENTO; ?>">Atualizações<i class="fa fa-sort-desc"></i></a>
                <?php } ?>
            </td>
        </tr>
        <?php if (!empty($data->ATD_UPDATE)) { ?>
            <tr class="<?php echo $last = ($last=='even'?'odd':'even'); ?> toggle_atd toggle_<?php echo $data->ATD_IDATENDIMENTO; ?>">
                <td><strong>Atualizações</strong></td>
                <td colspan="7" class="overflow-break-word"><?php echo Util::niceTextAtendimentos($data->ATD_UPDATE); ?></td>
            </tr>
        <?php } ?>
        <?php if(!empty($data->Arquivos)) { ?>
            <tr class="<?php echo $last = ($last=='even'?'odd':'even'); ?>">
                <td><strong>Arquivos</strong></td>
                <td colspan="7">
                    <ul id="links" class="imagens tab-pane fade in active">
                        <?php foreach($data->Arquivos as $arquivo) { ?>
                            <li><?php echo $arquivo->getLink(); ?></li>
                        <?php }?>
                    </ul>
                </td>
            </tr>
        <?php }?>
    </table>
</div>
<?php }?>