<div class="card border-0 shadow-lg rounded-4">
    <div class="card-body p-4 p-md-5">

        <h5 class="mb-4 fw-bold text-dark">
            <i class="fa-solid fa-file-signature me-2 text-success"></i>
            <?php echo e(isset($ata) ? __('Editar Ata') : __('Nova Ata')); ?>

        </h5>

        <div class="row g-4">

            <div class="col-md-3">
                <label class="form-label"><?php echo e(__('Número:')); ?></label>
                <input type="text" name="nr_ata" maxlength="50" class="form-control"
                       value="<?php echo e(old('nr_ata', $ata->nr_ata ?? '')); ?>" required>
            </div>

            <div class="col-md-3">
                <label class="form-label"><?php echo e(__('Processo N°:')); ?></label>
                <input type="text" name="nr_processo" maxlength="50" class="form-control"
                       value="<?php echo e(old('nr_processo', $ata->nr_processo ?? '')); ?>" required>
            </div>

            <div class="col-md-3">
                <label class="form-label"><?php echo e(__('Data:')); ?></label>
                <input type="date" name="dt_data_ata" class="form-control"
                       value="<?php echo e(old('dt_data_ata', $ata->dt_data_ata ?? '')); ?>" required>
            </div>

            <div class="col-md-3">
                <label class="form-label"><?php echo e(__('Vigência:')); ?></label>
                <input type="date" name="dt_vigencia_ata" class="form-control"
                       value="<?php echo e(old('dt_vigencia_ata', $ata->dt_vigencia_ata ?? '')); ?>" required>
            </div>

            <div class="col-md-12 position-relative">
                <label class="form-label"><?php echo e(__('Licitação vinculada:')); ?></label>
                <input type="hidden"
                       name="licitacao_procedimento_id"
                       id="licitacao_procedimento_id"
                       value="<?php echo e(old('licitacao_procedimento_id', $ata->licitacao_procedimento_id ?? '')); ?>">
                <input type="text"
                       class="form-control"
                       id="licitacao_search"
                       data-search-url="<?php echo e(route('admin.atas.searchLicitacoes')); ?>"
                       data-empty-message="<?php echo e(__('Nenhum resultado encontrado.')); ?>"
                       placeholder="<?php echo e(__('Nº do processo, nº da licitação ou trecho do objeto (mín. 2 caracteres)')); ?>"
                       autocomplete="off"
                       value="<?php echo e($licitacaoSelecionada['text'] ?? ''); ?>">
                <div id="licitacao_search_results" class="list-group position-absolute w-100 mt-1 d-none z-3"></div>
                <small class="text-muted d-block mt-2">
                    <i class="fa-solid fa-link me-1"></i>
                    <?php echo e(__('Vincule esta ata a uma licitação para criar acesso direto na página pública.')); ?>

                </small>
            </div>

            <div class="col-12">
                <label class="form-label"><?php echo e(__('Objeto:')); ?></label>
                <textarea name="ds_objeto" rows="3" maxlength="100" class="form-control"
                          required><?php echo e(old('ds_objeto', $ata->ds_objeto ?? '')); ?></textarea>
            </div>

            <div class="col-md-4">
                <label class="form-label"><?php echo e(__('BO N°:')); ?></label>
                <select name="id_bo" id="id_bo" class="form-select" required>
                    <option value=""><?php echo e(__('Selecione')); ?></option>
                    <?php $__currentLoopData = $boletins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $boletim): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($boletim->id); ?>"
                                data-date="<?php echo e(!empty($boletim->publicationDate) ? \Carbon\Carbon::parse($boletim->publicationDate)->format('Y-m-d') : ''); ?>"
                                data-link="<?php echo e($boletim->url); ?>"
                                <?php if(old('id_bo', $ata->id_bo ?? '') == $boletim->id): echo 'selected'; endif; ?>>
                            <?php echo e($boletim->number); ?>

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

            <div class="col-md-4">
                <label class="form-label"><?php echo e(__('BO Data:')); ?></label>
                <input type="text" name="dt_bo" id="dt_bo" class="form-control bg-light"
                       value="<?php echo e(old('dt_bo', $ata->dt_bo ?? '')); ?>" readonly>
            </div>

            <div class="col-md-4">
                <label class="form-label"><?php echo e(__('BO Link:')); ?></label>
                <input type="text" name="ds_link_bo" id="ds_link_bo" class="form-control bg-light"
                       value="<?php echo e(old('ds_link_bo', $ata->ds_link_bo ?? '')); ?>" readonly>
            </div>

            <div class="col-md-6">
                <label class="form-label"><?php echo e(__('Secretaria:')); ?></label>
                <?php
                    $secretariasSelecionadas = collect($secretariasSelecionadas ?? [])
                        ->filter(fn ($value) => !empty($value))
                        ->map(fn ($value) => (string) $value)
                        ->values();
                    if ($secretariasSelecionadas->isEmpty()) {
                        $secretariasSelecionadas = collect(['']);
                    }
                ?>

                <div id="secretarias_container" class="d-flex flex-column gap-2">
                    <?php $__currentLoopData = $secretariasSelecionadas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $secretariaSelecionada): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="input-group secretaria-item">
                            <select name="id_secretaria_ata[]" class="form-select secretaria-select" <?php if($index === 0): ?> required <?php endif; ?>>
                                <option value=""><?php echo e(__('Selecione')); ?></option>
                                <?php $__currentLoopData = $secretarias; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $secretaria): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($secretaria->id); ?>"
                                            data-sigla="<?php echo e($secretaria->abbreviation); ?>"
                                            <?php if((string) $secretariaSelecionada === (string) $secretaria->id): echo 'selected'; endif; ?>>
                                        <?php echo e($secretaria->name); ?>

                                    </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            <?php if($index > 0): ?>
                                <button type="button" class="btn btn-outline-danger remove-secretaria">
                                    <i class="fa-solid fa-trash"></i>
                                </button>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>

                <button type="button" id="add_secretaria_btn" class="btn btn-outline-primary btn-sm mt-2">
                    <i class="fa-solid fa-plus me-1"></i><?php echo e(__('Adicionar secretaria')); ?>

                </button>
            </div>

            <div class="col-md-6">
                <label class="form-label"><?php echo e(__('Sigla:')); ?></label>
                <input type="text" name="ds_sigla" id="ds_sigla" class="form-control bg-light"
                       value="<?php echo e(old('ds_sigla', $ata->ds_sigla ?? '')); ?>" readonly>
            </div>

            <div class="col-md-12">
                <label class="form-label"><?php echo e(__('Ata (PDF):')); ?></label>
                <input type="file" name="nm_arquivo_ata" class="form-control"
                       accept="application/pdf" <?php if(!isset($ata)): ?> required <?php endif; ?>>

                <small class="text-muted d-block mt-2">
                    <i class="fa-solid fa-circle-info me-1"></i>
                    <?php echo e(__('Somente PDF (máx. 10 MB)')); ?>

                </small>

                <?php if(!empty($ata?->nm_arquivo_ata)): ?>
                    <a href="<?php echo e($ata->public_arquivo_ata_url); ?>"
                       target="_blank"
                       rel="noopener noreferrer"
                       class="btn btn-outline-primary btn-sm mt-3">
                        <i class="fa-solid fa-file-pdf me-1"></i> <?php echo e(__('Ver arquivo atual')); ?>

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

        </div>

        <div class="d-flex justify-content-end mt-5">
            <button class="btn btn-success px-5 py-2">
                <i class="fa-solid fa-check me-2"></i><?php echo e(__('Salvar')); ?>

            </button>
        </div>

    </div>
</div>

<?php $__env->startPush('scripts'); ?>
<script src="<?php echo e(asset('pmar/js/admin/atas-form.js')); ?>?v=<?php echo e(@filemtime(public_path('pmar/js/admin/atas-form.js')) ?: time()); ?>"></script>
<?php $__env->stopPush(); ?>
<?php /**PATH /var/www/html/portal/resources/views/admin/atas/_form.blade.php ENDPATH**/ ?>