<?php $__env->startSection('title', env('APP_NAME') . ' :: Indicadores de TI'); ?>

<?php $__env->startSection('content'); ?>
    <div class="card shadow-sm">

        <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
            'headLine' => "<i class='fa-solid fa-computer'></i> " . __($headLine ?? 'Indicadores de TI'),
            'routeBack' => 'admin.dashboard',
            'routeBackParams' => [],
            'nameBack' => __('Voltar'),
            'permission' => 'INDICADORES_TI',

            'routeOther' => 'admin.indicadoresTi.relatorio.index',
            'nameOther' => __('Relatórios'),
            'fontawesomeOther' => '<i class="fa-solid fa-chart-bar"></i>',

            'tabs' => [
                [
                    'route' => 'admin.indicadoresTi.gerenciar',
                    'label' => 'Gerenciar Assuntos',
                    'class' => 'fa-sliders',
                    'permission' => 'INDICADORES_TI',
                    'permission_check' => 'editar',
                ],
                [
                    'route' => 'admin.indicadoresTi.gerenciar.clientes',
                    'label' => 'Gerenciar Clientes',
                    'class' => 'fa-users',
                    'permission' => 'INDICADORES_TI',
                    'permission_check' => 'editar',
                ],
            ],
        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

        <div class="card-body">

            <?php if(session('success')): ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <?php echo e(session('success')); ?>

                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>

            <?php if($errors->any()): ?>
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <ul class="mb-0">
                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $erro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <li><?php echo e($erro); ?></li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </ul>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>

            <?php
                $novoFormData = [
                    'chamadoForm' => new \App\Models\IndicadoresTi\Chamado([
                        'status' => 'pendente',
                        'prioridade' => 'media',
                        'tipo' => 'help_desk',
                        'canal' => 'portal',
                        'data_abertura' => now(),
                        'atendente_id' => auth()->id(),
                    ]),
                    'action' => route('admin.indicadoresTi.store'),
                    'method' => 'POST',
                    'assuntosForm' => collect(),
                    'subassuntosForm' => collect(),
                    'filterParams' => $filterParams ?? [],
                ];
            ?>

            <div class="mt-3">
                <?php if(empty($chamadosAbertos)): ?>
                    <div class="tab-content border rounded p-3 bg-white shadow-sm">
                        <div class="tab-pane show active" id="painel-novo-chamado" role="tabpanel">
                            <?php echo $__env->make('admin.indicadoresTi.form', $novoFormData, array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                        </div>
                    </div>
                <?php else: ?>
                    <ul class="nav nav-tabs flex-nowrap overflow-auto" id="abas-chamado" role="tablist" style="scrollbar-width: thin;">
                        <li class="nav-item" role="presentation">
                            <button class="nav-link" id="tab-novo" data-bs-toggle="tab" data-bs-target="#painel-novo-chamado"
                                type="button" role="tab" aria-controls="painel-novo-chamado" aria-selected="false">
                                <i class="fa-solid fa-plus me-1"></i><?php echo e(__('Novo Chamado')); ?>

                            </button>
                        </li>

                        <?php $__currentLoopData = $chamadosAbertos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $chamadoAberto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <li class="nav-item" role="presentation" id="aba-edicao-<?php echo e($chamadoAberto->id); ?>">
                                <div class="nav-link d-flex align-items-center gap-2 px-3">
                                    <button class="nav-link <?php echo e(session('aba_ativa') == $chamadoAberto->id ? 'active' : ''); ?>"
                                        id="tab-editar-<?php echo e($chamadoAberto->id); ?>" data-bs-toggle="tab"
                                        data-bs-target="#painel-editar-<?php echo e($chamadoAberto->id); ?>" type="button" role="tab"
                                        aria-controls="painel-editar-<?php echo e($chamadoAberto->id); ?>"
                                        aria-selected="<?php echo e(session('aba_ativa') == $chamadoAberto->id ? 'true' : 'false'); ?>">
                                        <i class="fa-solid fa-pen-to-square me-1"></i>
                                        <?php echo e($chamadoAberto->numero); ?>

                                    </button>
                                    <a href="<?php echo e(route('admin.indicadoresTi.fecharAba', $chamadoAberto->id)); ?>"
                                        class="btn-close ms-1 fechar-aba-link" title="<?php echo e(__('Fechar aba')); ?>"
                                        aria-label="<?php echo e(__('Fechar aba')); ?>" data-chamado-id="<?php echo e($chamadoAberto->id); ?>"
                                        style="font-size: 0.65rem; vertical-align: middle;"></a>
                                </div>
                            </li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </ul>

                    <div class="tab-content border border-top-0 rounded-bottom p-3 bg-white shadow-sm">
                        <div class="tab-pane fade" id="painel-novo-chamado" role="tabpanel" aria-labelledby="tab-novo">
                            <?php echo $__env->make('admin.indicadoresTi.form', $novoFormData, array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                        </div>

                        <?php $__currentLoopData = $chamadosAbertos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $chamadoAberto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="tab-pane fade <?php echo e(session('aba_ativa') == $chamadoAberto->id ? 'show active' : ''); ?>"
                                id="painel-editar-<?php echo e($chamadoAberto->id); ?>" role="tabpanel"
                                aria-labelledby="tab-editar-<?php echo e($chamadoAberto->id); ?>">
                                <?php echo $__env->make('admin.indicadoresTi.form', [
                                    'chamadoForm' => $chamadoAberto,
                                    'action' => route('admin.indicadoresTi.update', $chamadoAberto->id),
                                    'method' => 'PUT',
                                    'assuntosForm' => $chamadoAberto->setor_id
                                        ? \App\Models\IndicadoresTi\Assunto::where('setor_id', $chamadoAberto->setor_id)->orderBy('nome')->get()
                                        : collect(),
                                    'subassuntosForm' => $chamadoAberto->assunto_id
                                        ? \App\Models\IndicadoresTi\Subassunto::where('assunto_id', $chamadoAberto->assunto_id)->orderBy('nome')->get()
                                        : collect(),
                                    'filterParams' => $filterParams,
                                ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                <?php endif; ?>
            </div>

            <div class="mt-4">
                <?php echo $__env->make('admin.indicadoresTi.list', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            </div>

        </div>
    </div>

    <div class="modal fade" id="modal-novo-cliente" tabindex="-1" aria-labelledby="modal-novo-cliente-label"
        aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modal-novo-cliente-label"><?php echo e(__('Novo Cliente')); ?></h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                        aria-label="<?php echo e(__('Fechar')); ?>"></button>
                </div>
                <div class="modal-body">
                    <div id="novo-cliente-erro" class="alert alert-danger d-none" role="alert"></div>

                    <div class="mb-3">
                        <label class="form-label" for="nc-nome"><?php echo e(__('Nome')); ?> <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="nc-nome"
                            placeholder="<?php echo e(__('Nome completo')); ?>" autocomplete="off">
                    </div>

                    <div class="mb-3">
                        <label class="form-label" for="nc-tipo-identificacao"><?php echo e(__('Tipo de Identificação')); ?> <span class="text-danger">*</span></label>
                        <select class="form-select" id="nc-tipo-identificacao">
                            <option value="cpf"><?php echo e(__('CPF')); ?></option>
                            <option value="matricula"><?php echo e(__('Matrícula')); ?></option>
                        </select>
                    </div>

                    <div class="mb-3" id="nc-grupo-cpf">
                        <label class="form-label" for="nc-cpf"><?php echo e(__('CPF')); ?> <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="nc-cpf" placeholder="000.000.000-00"
                            autocomplete="off">
                    </div>

                    <div class="mb-3 d-none" id="nc-grupo-matricula">
                        <label class="form-label" for="nc-matricula"><?php echo e(__('Matrícula')); ?> <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="nc-matricula"
                            placeholder="<?php echo e(__('Matrícula do servidor')); ?>" autocomplete="off">
                    </div>

                    <div class="mb-3">
                        <label class="form-label" for="nc-setor"><?php echo e(__('Setor')); ?> <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="nc-setor" placeholder="<?php echo e(__('Setor')); ?>"
                            autocomplete="off">
                    </div>

                    <div class="mb-3">
                        <label class="form-label" for="nc-telefone"><?php echo e(__('Telefone')); ?></label>
                        <input type="text" class="form-control" id="nc-telefone"
                            placeholder="<?php echo e(__('Telefone')); ?>" autocomplete="off">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary"
                        data-bs-dismiss="modal"><?php echo e(__('Cancelar')); ?></button>
                    <button type="button" class="btn btn-primary" id="btn-salvar-cliente">
                        <span class="spinner-border spinner-border-sm d-none me-1" id="spinner-salvar-cliente"
                            role="status" aria-hidden="true"></span>
                        <?php echo e(__('Salvar')); ?>

                    </button>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin.theme', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/portal/resources/views/admin/indicadoresTi/index.blade.php ENDPATH**/ ?>