<?php
    $isEdicao = isset($chamadoForm->id) && $chamadoForm->id;
    $isConcluido = $isEdicao && $chamadoForm->status === 'atendido';
    $isNovo = !$isEdicao;
?>

<div class="chamado-resumo-header p-3 bg-light rounded border cursor-pointer" role="button" style="cursor: pointer;"
    aria-expanded="<?php echo e($isNovo ? 'false' : 'true'); ?>">
    <div class="d-flex align-items-center justify-content-between">
        <div>
            <strong>
                <?php if($isNovo): ?>
                    <i class="fa-solid fa-plus-circle me-2 text-primary"></i>
                    <?php echo e(__('Novo Chamado')); ?>

                <?php else: ?>
                    <i class="fa-solid fa-ticket me-2 text-primary"></i>
                    <?php echo e($chamadoForm->numero ?? '#' . $chamadoForm->id); ?>

                    <span
                        class="badge bg-<?php echo e($chamadoForm->status === 'atendido' ? 'success' : ($chamadoForm->status === 'em_andamento' ? 'info' : 'warning')); ?> ms-2">
                        <?php echo e(__(\App\Models\IndicadoresTi\Chamado::STATUS[$chamadoForm->status] ?? $chamadoForm->status)); ?>

                    </span>
                <?php endif; ?>
            </strong>
            <?php if(!$isNovo): ?>
                <small class="text-muted ms-2">
                    <?php echo e($chamadoForm->cliente->nome ?? __('Sem cliente')); ?> |
                    <?php echo e($chamadoForm->setor->nome ?? __('Sem setor')); ?>

                </small>
            <?php endif; ?>
        </div>
        <div class="d-flex align-items-center gap-2">
            <small class="text-muted chamado-resumo-hint d-none d-sm-inline">
                <?php echo e($isNovo ? 'Clique para abrir formulário' : 'Clique para expandir/recolher'); ?>

            </small>
            <i class="fa-solid fa-chevron-down chamado-resumo-chevron transition-transform"></i>
        </div>
    </div>
</div>

<div class="chamado-form-wrapper px-3 pt-4" data-aberto="<?php echo e($isNovo ? 'false' : 'true'); ?>"
    style="max-height: <?php echo e($isNovo ? '0' : 'none'); ?>; opacity: <?php echo e($isNovo ? '0' : '1'); ?>; overflow: hidden; transition: max-height 0.4s ease, opacity 0.3s ease;">

    <form action="<?php echo e($action); ?>" method="POST" class="chamado-form" novalidate>
        <?php echo csrf_field(); ?>
        <?php if($method !== 'POST'): ?>
            <?php echo method_field($method); ?>
        <?php endif; ?>

        <?php $__currentLoopData = $filterParams ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php if($value): ?>
                <input type="hidden" name="<?php echo e($key); ?>" value="<?php echo e($value); ?>">
            <?php endif; ?>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        <?php if($isConcluido): ?>
            <div class="alert alert-warning d-flex align-items-center gap-2 mb-3" role="alert">
                <i class="fa-solid fa-lock"></i>
                <?php echo e(__('Este chamado está finalizado. Marque "Reabrir chamado" para editar.')); ?>

            </div>
        <?php endif; ?>

        <div class="mb-4">
            <div class="fw-semibold text-uppercase small text-secondary border-bottom pb-2 mb-3">
                <?php echo e(__('IDENTIFICAÇÃO')); ?></div>
            <div class="row g-2">

                <div class="col-md-6">
                    <label class="form-label" for="canal-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Canal')); ?></label>

                    <?php if($isConcluido): ?>
                        <input type="hidden" name="canal" value="<?php echo e($chamadoForm->canal); ?>">
                    <?php endif; ?>
                    <select class="form-select" name="<?php echo e($isConcluido ? '_canal_readonly' : 'canal'); ?>"
                        id="canal-<?php echo e($chamadoForm->id ?? 'novo'); ?>" <?php echo e($isConcluido ? 'disabled' : ''); ?> required>
                        <?php $__currentLoopData = \App\Models\IndicadoresTi\Chamado::CANAL; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $valor => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($valor); ?>" <?php if(old('canal', $chamadoForm->canal) === $valor): echo 'selected'; endif; ?>>
                                <?php echo e(__($label)); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-6">
                    <label class="form-label" for="solicitante-<?php echo e($chamadoForm->id ?? 'novo'); ?>">
                        <?php echo e(__('Solicitante')); ?> <span class="text-danger">*</span>
                    </label>

                    <?php if($isConcluido): ?>
                        <input type="hidden" name="solicitante_id"
                            value="<?php echo e($chamadoForm->user_id ?? $chamadoForm->cliente_id); ?>">
                        <input type="hidden" name="solicitante_tipo"
                            value="<?php echo e($chamadoForm->user_id ? 'usuario' : 'cliente'); ?>">
                    <?php endif; ?>

                    <div class="input-group">
                        <div class="position-relative flex-grow-1">

                            <input type="text" class="form-control js-cliente-search"
                                id="solicitante-<?php echo e($chamadoForm->id ?? 'novo'); ?>" name="solicitante_nome"
                                placeholder="Digite para buscar cliente ou usuário..." autocomplete="off"
                                <?php echo e($isConcluido ? 'disabled' : ''); ?>

                                value="<?php echo e(old(
                                    'solicitante_nome',
                                    $chamadoForm->user_id
                                        ? ($chamadoForm->solicitante->matriculation
                                            ? $chamadoForm->solicitante->name . ' — ' . $chamadoForm->solicitante->matriculation
                                            : $chamadoForm->solicitante->name)
                                        : ($chamadoForm->cliente
                                            ? $chamadoForm->cliente->nome .
                                                ($chamadoForm->cliente->cpf
                                                    ? ' — ' . $chamadoForm->cliente->cpf
                                                    : ($chamadoForm->cliente->matricula
                                                        ? ' — Mat. ' . $chamadoForm->cliente->matricula
                                                        : ''))
                                            : ''),
                                )); ?>">

                            <input type="hidden" name="solicitante_id" class="js-solicitante-id"
                                value="<?php echo e(old('solicitante_id', $chamadoForm->user_id ?? $chamadoForm->cliente_id)); ?>">

                            <input type="hidden" name="solicitante_tipo" class="js-solicitante-tipo"
                                value="<?php echo e(old('solicitante_tipo', $chamadoForm->user_id ? 'usuario' : 'cliente')); ?>">
                        </div>

                        <?php if(!$isConcluido): ?>
                            <button type="button" class="btn btn-outline-secondary" data-bs-toggle="modal"
                                data-bs-target="#modal-novo-cliente" title="Cadastrar novo cliente">
                                <i class="fa-solid fa-plus"></i>
                            </button>

                            <button type="button" class="btn btn-outline-danger js-limpar-cliente"
                                style="display: none;">
                                <i class="fa-solid fa-xmark"></i>
                            </button>
                        <?php endif; ?>
                    </div>

                    <div class="js-cliente-info mt-1" style="display: none;">
                        <small class="text-muted">
                            <span class="js-cliente-detalhes"></span>
                        </small>
                    </div>
                </div>

            </div>
        </div>

        <div class="mb-4">
            <div class="fw-semibold text-uppercase small text-secondary border-bottom pb-2 mb-3">
                <?php echo e(__('CLASSIFICAÇÃO')); ?></div>
            <div class="row g-2">

                <div class="col-md-4">
                    <label class="form-label" for="setor-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Setor')); ?> <span
                            class="text-danger">*</span></label>
                    <?php if($isConcluido): ?>
                        <input type="hidden" name="setor_id" value="<?php echo e($chamadoForm->setor_id); ?>">
                    <?php endif; ?>
                    <select class="form-select js-setor-select"
                        name="<?php echo e($isConcluido ? '_setor_readonly' : 'setor_id'); ?>"
                        id="setor-<?php echo e($chamadoForm->id ?? 'novo'); ?>" <?php echo e($isConcluido ? 'disabled' : 'required'); ?>>
                        <option value=""><?php echo e(__('Selecione')); ?></option>
                        <?php $__currentLoopData = $setores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $setor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($setor->id); ?>" <?php if((int) old('setor_id', $chamadoForm->setor_id) === $setor->id): echo 'selected'; endif; ?>>
                                <?php echo e($setor->nome); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-4">
                    <label class="form-label" for="assunto-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Assunto')); ?> <span
                            class="text-danger">*</span></label>
                    <?php if($isConcluido): ?>
                        <input type="hidden" name="assunto_id" value="<?php echo e($chamadoForm->assunto_id); ?>">
                    <?php endif; ?>
                    <select class="form-select js-assunto-select"
                        name="<?php echo e($isConcluido ? '_assunto_readonly' : 'assunto_id'); ?>"
                        id="assunto-<?php echo e($chamadoForm->id ?? 'novo'); ?>" <?php echo e($isConcluido ? 'disabled' : 'required'); ?>>
                        <option value=""><?php echo e(__('Selecione')); ?></option>
                        <?php $__currentLoopData = $assuntosForm; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $assunto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($assunto->id); ?>" <?php if((int) old('assunto_id', $chamadoForm->assunto_id) === $assunto->id): echo 'selected'; endif; ?>>
                                <?php echo e($assunto->nome); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-4">
                    <label class="form-label"
                        for="subassunto-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Subassunto')); ?>

                        <span class="text-danger">*</span></label>
                    <?php if($isConcluido): ?>
                        <input type="hidden" name="subassunto_id" value="<?php echo e($chamadoForm->subassunto_id); ?>">
                    <?php endif; ?>
                    <select class="form-select js-subassunto-select"
                        name="<?php echo e($isConcluido ? '_subassunto_readonly' : 'subassunto_id'); ?>"
                        id="subassunto-<?php echo e($chamadoForm->id ?? 'novo'); ?>"
                        <?php echo e($isConcluido ? 'disabled' : 'required'); ?>>
                        <option value=""><?php echo e(__('Selecione')); ?></option>
                        <?php $__currentLoopData = $subassuntosForm; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subassunto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($subassunto->id); ?>" <?php if((int) old('subassunto_id', $chamadoForm->subassunto_id) === $subassunto->id): echo 'selected'; endif; ?>>
                                <?php echo e($subassunto->nome); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-4">
                    <label class="form-label" for="tipo-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Tipo')); ?> <span
                            class="text-danger">*</span></label>
                    <?php if($isConcluido): ?>
                        <input type="hidden" name="tipo" value="<?php echo e($chamadoForm->tipo); ?>">
                    <?php endif; ?>
                    <select class="form-select" name="<?php echo e($isConcluido ? '_tipo_readonly' : 'tipo'); ?>"
                        id="tipo-<?php echo e($chamadoForm->id ?? 'novo'); ?>" <?php echo e($isConcluido ? 'disabled' : 'required'); ?>>
                        <?php $__currentLoopData = \App\Models\IndicadoresTi\Chamado::TIPO; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $valor => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($valor); ?>" <?php if(old('tipo', $chamadoForm->tipo) === $valor): echo 'selected'; endif; ?>>
                                <?php echo e(__($label)); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-4">
                    <label class="form-label"
                        for="prioridade-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Prioridade')); ?>

                        <span class="text-danger">*</span></label>
                    <?php if($isConcluido): ?>
                        <input type="hidden" name="prioridade" value="<?php echo e($chamadoForm->prioridade); ?>">
                    <?php endif; ?>
                    <select class="form-select" name="<?php echo e($isConcluido ? '_prioridade_readonly' : 'prioridade'); ?>"
                        id="prioridade-<?php echo e($chamadoForm->id ?? 'novo'); ?>"
                        <?php echo e($isConcluido ? 'disabled' : 'required'); ?>>
                        <?php $__currentLoopData = \App\Models\IndicadoresTi\Chamado::PRIORIDADE; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $valor => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($valor); ?>" <?php if(old('prioridade', $chamadoForm->prioridade) === $valor): echo 'selected'; endif; ?>>
                                <?php echo e(__($label)); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-4">
                    <label class="form-label" for="status-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Status')); ?>

                        <span class="text-danger">*</span></label>
                    <?php if($isConcluido): ?>
                        <input type="hidden" name="status" value="<?php echo e($chamadoForm->status); ?>">
                    <?php endif; ?>
                    <select class="form-select" name="<?php echo e($isConcluido ? '_status_readonly' : 'status'); ?>"
                        id="status-<?php echo e($chamadoForm->id ?? 'novo'); ?>" <?php echo e($isConcluido ? 'disabled' : 'required'); ?>>
                        <?php $__currentLoopData = \App\Models\IndicadoresTi\Chamado::STATUS; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $valor => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($valor); ?>" <?php if(old('status', $chamadoForm->status) === $valor): echo 'selected'; endif; ?>>
                                <?php echo e(__($label)); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

            </div>
        </div>

        <div class="mb-4">
            <div class="fw-semibold text-uppercase small text-secondary border-bottom pb-2 mb-3"><?php echo e(__('DESCRIÇÃO')); ?>

            </div>
            <div>
                <label class="form-label visually-hidden"
                    for="descricao-<?php echo e($chamadoForm->id ?? 'novo'); ?>"><?php echo e(__('Descrição')); ?></label>
                <textarea class="form-control" name="descricao" id="descricao-<?php echo e($chamadoForm->id ?? 'novo'); ?>" rows="4"
                    <?php echo e($isConcluido ? 'readonly' : ''); ?> placeholder="<?php echo e(__('Descreva o chamado (opcional)')); ?>"><?php echo e(old('descricao', $chamadoForm->descricao)); ?></textarea>
            </div>
        </div>

        <div class="mb-4">
            <div class="fw-semibold text-uppercase small text-secondary border-bottom pb-2 mb-3">
                <?php echo e(__('ATENDIMENTO')); ?></div>
            <div class="row g-2">
                <div class="col-md-3">
                    <label class="form-label"><?php echo e(__('Responsável')); ?></label>
                    <input type="text" class="form-control"
                        value="<?php echo e($isEdicao ? $chamadoForm->atendente->name ?? '—' : auth()->user()->name ?? ''); ?>"
                        readonly aria-readonly="true">
                </div>
                <div class="col-md-3">
                    <label class="form-label"><?php echo e(__('Abertura')); ?></label>
                    <input type="text" class="form-control"
                        value="<?php echo e(optional($chamadoForm->data_abertura)->format('d/m/Y H:i')); ?>" readonly
                        aria-readonly="true">
                </div>
                <div class="col-md-3">
                    <label class="form-label"><?php echo e(__('Fechamento')); ?></label>
                    <input type="text" class="form-control"
                        value="<?php echo e(optional($chamadoForm->data_fechamento)->format('d/m/Y H:i') ?? '—'); ?>" readonly
                        aria-readonly="true">
                </div>
                <div class="col-md-3">
                    <label class="form-label"><?php echo e(__('Tempo de Atendimento')); ?></label>
                    <?php if($isEdicao && $chamadoForm->isEmAndamento() && $chamadoForm->data_abertura): ?>
                        <div class="input-group">
                            <span class="form-control tempo-em-andamento"
                                data-inicio="<?php echo e(($chamadoForm->data_reabertura ?? $chamadoForm->data_abertura)->toIsoString()); ?>"
                                data-acumulado="<?php echo e($chamadoForm->tempo_acumulado ?? 0); ?>">
                                <?php echo e($chamadoForm->getTempoAtendimentoFormatado()); ?>

                            </span>
                            <span class="input-group-text bg-warning text-dark" title="<?php echo e(__('Em andamento')); ?>">
                                <i class="fa-solid fa-spinner fa-spin"></i>
                            </span>
                        </div>
                    <?php elseif($isEdicao && $chamadoForm->data_fechamento): ?>
                        <input type="text" class="form-control"
                            value="<?php echo e($chamadoForm->getTempoAtendimentoFormatado()); ?>" readonly>
                    <?php else: ?>
                        <input type="text" class="form-control" value="—" readonly>
                    <?php endif; ?>
                </div>

                <div class="col-12">
                    <label class="form-label" for="unidade-select-<?php echo e($chamadoForm->id ?? 'novo'); ?>">
                        <?php echo e(__('Unidade Organizacional')); ?> <span class="text-danger">*</span>
                    </label>
                    <?php if($unidadesDoUsuario->isEmpty()): ?>
                        <input type="text" class="form-control"
                            value="<?php echo e(__('Nenhuma unidade vinculada ao seu perfil.')); ?>" disabled readonly>
                        <input type="hidden" name="unidade_organizacional_id" value="">
                    <?php else: ?>
                        <?php if($isConcluido): ?>
                            <input type="hidden" name="unidade_organizacional_id"
                                value="<?php echo e($chamadoForm->unidade_organizacional_id); ?>">
                        <?php endif; ?>
                        <?php
                            $unidadeDefault = old(
                                'unidade_organizacional_id',
                                $chamadoForm->unidade_organizacional_id ??
                                    ($unidadesDoUsuario->count() === 1 ? $unidadesDoUsuario->first()->id : null),
                            );
                        ?>
                        <select class="form-select"
                            name="<?php echo e($isConcluido ? '_unidade_readonly' : 'unidade_organizacional_id'); ?>"
                            id="unidade-select-<?php echo e($chamadoForm->id ?? 'novo'); ?>"
                            <?php echo e($isConcluido ? 'disabled' : ''); ?>>
                            <option value=""><?php echo e(__('Selecione a unidade...')); ?></option>
                            <?php $__currentLoopData = $unidadesDoUsuario; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unidade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($unidade->id); ?>" <?php if($unidadeDefault == $unidade->id): echo 'selected'; endif; ?>>
                                    <?php echo e($unidade->abbreviation); ?> — <?php echo e($unidade->name); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    <?php endif; ?>
                    <small class="text-muted"><?php echo e(__('Opcional — unidade que originou o chamado.')); ?></small>
                </div>
            </div>
        </div>

        <?php if($isConcluido): ?>
            <div class="form-check mb-3">
                <input class="form-check-input" type="checkbox" value="1" id="reabrir-<?php echo e($chamadoForm->id); ?>"
                    name="reabrir">
                <label class="form-check-label" for="reabrir-<?php echo e($chamadoForm->id); ?>">
                    <?php echo e(__('Reabrir chamado para edição')); ?>

                </label>
            </div>
        <?php endif; ?>

        <div class="d-flex gap-2 flex-wrap align-items-center mb-5">
            <button class="btn btn-outline-primary" type="submit">
                <i class="fa-solid fa-floppy-disk me-1"></i><?php echo e(__('Salvar')); ?>

            </button>

            <?php if($isEdicao && !$isConcluido): ?>
                <button type="button" class="btn btn-success" data-bs-toggle="modal"
                    data-bs-target="#modal-concluir-<?php echo e($chamadoForm->id); ?>">
                    <i class="fa-solid fa-check me-1"></i><?php echo e(__('Concluir Chamado')); ?>

                </button>

                <a href="<?php echo e(route('admin.indicadoresTi.fecharAba', $chamadoForm->id)); ?>"
                    class="btn btn-outline-secondary ms-auto">
                    <i class="fa-solid fa-xmark me-1"></i><?php echo e(__('Fechar')); ?>

                </a>
            <?php endif; ?>

            <?php if($isEdicao && $isConcluido): ?>
                <a href="<?php echo e(route('admin.indicadoresTi.fecharAba', $chamadoForm->id)); ?>"
                    class="btn btn-outline-secondary ms-auto">
                    <i class="fa-solid fa-xmark me-1"></i><?php echo e(__('Fechar')); ?>

                </a>
            <?php endif; ?>
        </div>
    </form>

    <?php if($isEdicao): ?>
        <?php
            $userId = auth()->id();
            $isDiretorTi = auth()->user()->permissoes->pluck('permissao')->contains('DIRETOR_TI');
            $isAtendente = $chamadoForm->atendente_id === $userId;
            $isParticipante = $chamadoForm->isParticipante($userId);
        ?>

        <div class="mb-4">
            <div
                class="fw-semibold text-uppercase small text-secondary border-bottom pb-2 mb-3 d-flex justify-content-between align-items-center">
                <span><?php echo e(__('PARTICIPANTES')); ?></span>
                <?php if(!$isConcluido && !$isParticipante): ?>
                    <form action="<?php echo e(route('admin.indicadoresTi.participantes.store', $chamadoForm->id)); ?>"
                        method="POST" class="d-inline">
                        <?php echo csrf_field(); ?>
                        <?php $__currentLoopData = $filterParams ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if($value): ?>
                                <input type="hidden" name="<?php echo e($key); ?>" value="<?php echo e($value); ?>">
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <button type="submit" class="btn btn-sm btn-warning">
                            <i class="fa-solid fa-user-plus me-1"></i><?php echo e(__('Me adicionar a este chamado')); ?>

                        </button>
                    </form>
                <?php endif; ?>
            </div>
            <div class="border rounded p-2">
                <div class="d-flex align-items-center gap-2 p-2 border-bottom">
                    <span class="badge bg-primary">Responsável</span>
                    <span class="fw-semibold"><?php echo e($chamadoForm->atendente->name ?? '—'); ?></span>
                    <small class="text-muted"><?php echo e($chamadoForm->atendente->matriculation ?? ''); ?></small>
                </div>

                <?php $outrosParticipantes = $chamadoForm->participantes->where('id', '!=', $chamadoForm->atendente_id); ?>
                <?php $__empty_1 = true; $__currentLoopData = $outrosParticipantes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $participante): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="d-flex align-items-center gap-2 p-2 <?php echo e(!$loop->last ? 'border-bottom' : ''); ?>">
                        <span class="badge bg-secondary">Participante</span>
                        <span><?php echo e($participante->name); ?></span>
                        <small class="text-muted"><?php echo e($participante->matriculation); ?></small>
                        <?php if(!$isConcluido && ($participante->id === $userId || $isDiretorTi)): ?>
                            <form action="<?php echo e(route('admin.indicadoresTi.participantes.destroy', $chamadoForm->id)); ?>"
                                method="POST" class="ms-auto">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <input type="hidden" name="user_id" value="<?php echo e($participante->id); ?>">
                                <?php $__currentLoopData = $filterParams ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($value): ?>
                                        <input type="hidden" name="<?php echo e($key); ?>"
                                            value="<?php echo e($value); ?>">
                                    <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <button type="submit" class="btn btn-sm btn-outline-danger" title="Remover">
                                    <i class="fa-solid fa-xmark"></i>
                                </button>
                            </form>
                        <?php endif; ?>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <p class="text-muted small p-2 mb-0">Nenhum participante adicional.</p>
                <?php endif; ?>

                <?php if(!$isConcluido && ($isAtendente || $isDiretorTi)): ?>
                    <div class="mt-2 pt-2 border-top">
                        <input type="text" class="form-control form-control-sm js-participante-search"
                            data-chamado="<?php echo e($chamadoForm->id); ?>"
                            placeholder="<?php echo e(__('Buscar e adicionar participante...')); ?>" autocomplete="off">
                        <form id="form-add-participante-<?php echo e($chamadoForm->id); ?>"
                            action="<?php echo e(route('admin.indicadoresTi.participantes.store', $chamadoForm->id)); ?>"
                            method="POST" class="d-none">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="user_id" class="js-participante-user-id">
                            <?php $__currentLoopData = $filterParams ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($value): ?>
                                    <input type="hidden" name="<?php echo e($key); ?>" value="<?php echo e($value); ?>">
                                <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </form>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if($isEdicao): ?>
        <div class="mb-4">
            <div class="fw-semibold text-uppercase small text-secondary border-bottom pb-2 mb-3">
                <i class="fa-solid fa-timeline me-1"></i><?php echo e(__('HISTÓRICO')); ?>

            </div>
            <div class="border rounded p-0">
                <?php $__empty_1 = true; $__currentLoopData = $chamadoForm->logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <?php
                        $tipoInfo = \App\Models\IndicadoresTi\ChamadoLog::TIPOS[$log->tipo] ?? [
                            'label' => $log->tipo,
                            'icon' => 'fa-circle',
                            'color' => 'secondary',
                        ];
                    ?>
                    <div class="d-flex align-items-start gap-3 p-3 <?php echo e(!$loop->last ? 'border-bottom' : ''); ?>">
                        <div class="text-<?php echo e($tipoInfo['color']); ?> pt-1"
                            style="min-width: 20px; text-align: center;">
                            <i class="fa-solid <?php echo e($tipoInfo['icon']); ?>"></i>
                        </div>
                        <div class="flex-grow-1">
                            <div class="d-flex justify-content-between">
                                <span
                                    class="fw-semibold text-<?php echo e($tipoInfo['color']); ?>"><?php echo e($tipoInfo['label']); ?></span>
                                <small class="text-muted"><?php echo e($log->created_at->format('d/m/Y H:i')); ?></small>
                            </div>
                            <div class="text-muted small"><?php echo e($log->conteudo); ?></div>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <p class="text-muted small p-3 mb-0">Nenhum registro no histórico.</p>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

</div>

<?php if($isEdicao): ?>
    <div class="modal fade" id="modal-concluir-<?php echo e($chamadoForm->id); ?>" tabindex="-1"
        aria-labelledby="modal-concluir-label-<?php echo e($chamadoForm->id); ?>" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modal-concluir-label-<?php echo e($chamadoForm->id); ?>">
                        <?php echo e(__('Concluir Chamado')); ?>

                    </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                        aria-label="<?php echo e(__('Fechar')); ?>"></button>
                </div>
                <div class="modal-body">
                    <?php echo e(__('Deseja realmente marcar o chamado :numero como concluído?', ['numero' => $chamadoForm->numero ?? ''])); ?>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary"
                        data-bs-dismiss="modal"><?php echo e(__('Cancelar')); ?></button>
                    <form action="<?php echo e(route('admin.indicadoresTi.concluir', $chamadoForm->id)); ?>" method="POST"
                        class="d-inline">
                        <?php echo csrf_field(); ?>
                        <?php $__currentLoopData = $filterParams ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if($value): ?>
                                <input type="hidden" name="<?php echo e($key); ?>" value="<?php echo e($value); ?>">
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <button type="submit" class="btn btn-success">
                            <i class="fa-solid fa-check me-1"></i><?php echo e(__('Confirmar')); ?>

                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>

<?php endif; ?>
<?php /**PATH /var/www/html/portal/resources/views/admin/indicadoresTi/form.blade.php ENDPATH**/ ?>