<?php $__env->startSection('title', env('APP_NAME') . ' :: ' . ($linha ? __('Editar Linha') : __('Nova Linha')) . ' - MobiAngra'); ?>

<?php $__env->startSection('content'); ?>
<div class="card shadow-sm">
    <?php
        $isEdicao = $linha !== null;
        $headLine = "<i class='fa-solid fa-bus'></i> " . ($isEdicao ? __('Linha :cod - :nome', ['cod' => $linha->codigo, 'nome' => $linha->nome]) : __('Nova Linha de Horários'));
    ?>

    <?php echo $__env->make('components.buttons._headLineButtonsBackAdd', [
        'headLine'        => $headLine,
        'routeBack'       => 'admin.mobiangra.index',
        'routeBackParams' => ['tab' => 'horarios'],
        'nameBack'        => __('Voltar'),
        'permission'      => 'GERENCIADOR_DE_MOBIANGRA',
    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <div class="card-body">
        <?php echo $__env->make('errors.messageFlash', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

        
        <form action="<?php echo e($isEdicao ? route('admin.mobiangra.horarios.linhas.update', $linha) : route('admin.mobiangra.horarios.linhas.store')); ?>"
              method="post">
            <?php echo csrf_field(); ?>
            <?php if($isEdicao): ?> <?php echo method_field('PUT'); ?> <?php endif; ?>

            <div class="border rounded p-3 mb-4">
                <h5 class="mb-3"><i class="fa-solid fa-info-circle me-1"></i><?php echo e(__('Dados da Linha')); ?></h5>
                <div class="row g-3">
                    <div class="col-md-2">
                        <label class="form-label fw-semibold"><?php echo e(__('Código')); ?> <span class="text-danger">*</span></label>
                        <input type="text" name="codigo" class="form-control <?php $__errorArgs = ['codigo'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                               value="<?php echo e(old('codigo', $linha->codigo ?? '')); ?>"
                               placeholder="ex: 101, C01, T10" maxlength="20" required>
                        <?php $__errorArgs = ['codigo'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold"><?php echo e(__('Nome Curto')); ?> <span class="text-danger">*</span></label>
                        <input type="text" name="nome" class="form-control <?php $__errorArgs = ['nome'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                               value="<?php echo e(old('nome', $linha->nome ?? '')); ?>"
                               placeholder="ex: CANTAGALO x DIVISA MANGARATIBA" maxlength="255" required>
                        <?php $__errorArgs = ['nome'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label fw-semibold"><?php echo e(__('Nome Completo (exibido ao público)')); ?> <span class="text-danger">*</span></label>
                        <input type="text" name="nome_completo" class="form-control <?php $__errorArgs = ['nome_completo'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                               value="<?php echo e(old('nome_completo', $linha->nome_completo ?? '')); ?>"
                               placeholder="ex: 101 - CANTAGALO x DIVISA MANGARATIBA" maxlength="255" required>
                        <?php $__errorArgs = ['nome_completo'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label fw-semibold"><?php echo e(__('Tarifa (R$)')); ?></label>
                        <input type="number" step="0.01" min="0" name="tarifa"
                               class="form-control <?php $__errorArgs = ['tarifa'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                               value="<?php echo e(old('tarifa', $linha->tarifa ?? '')); ?>" placeholder="7,00">
                        <?php $__errorArgs = ['tarifa'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label fw-semibold"><?php echo e(__('Tarifa Cidadão (R$)')); ?></label>
                        <input type="number" step="0.01" min="0" name="tarifa_cidadao"
                               class="form-control <?php $__errorArgs = ['tarifa_cidadao'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                               value="<?php echo e(old('tarifa_cidadao', $linha->tarifa_cidadao ?? '')); ?>" placeholder="2,00">
                        <?php $__errorArgs = ['tarifa_cidadao'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label fw-semibold"><?php echo e(__('Ordem')); ?></label>
                        <input type="number" min="0" name="ordem"
                               class="form-control"
                               value="<?php echo e(old('ordem', $linha->ordem ?? 0)); ?>">
                    </div>
                    <div class="col-md-2 d-flex align-items-end">
                        <div class="form-check mb-2">
                            <input class="form-check-input" type="checkbox" name="publicada" id="publicada" value="1"
                                   <?php echo e(old('publicada', $linha->publicada ?? true) ? 'checked' : ''); ?>>
                            <label class="form-check-label" for="publicada"><?php echo e(__('Publicada')); ?></label>
                        </div>
                    </div>
                </div>

                <?php if($isEdicao): ?>
                    
                    <hr>
                    <h6 class="mt-2 mb-1">
                        <i class="fa-solid fa-circle-half-stroke me-1 text-muted"></i><?php echo e(__('Legendas de cores')); ?>

                    </h6>
                    <p class="text-muted small mb-2">
                        <?php echo e(__('Explique o significado dos horários marcados em cores diferentes na planilha.')); ?>

                    </p>
                    <div id="legendas-container">
                        <?php $__currentLoopData = $linha->legendas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $leg): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="d-flex align-items-center gap-2 mb-2 legenda-row">
                            <select name="legendas[<?php echo e($i); ?>][cor]" class="form-select form-select-sm" style="width:130px" required>
                                <?php $__currentLoopData = ['azul' => __('🔵 Azul'), 'vermelho' => __('🔴 Vermelho'), 'verde' => __('🟢 Verde'), 'laranja' => __('🟠 Laranja'), 'amarelo' => __('🟡 Amarelo'), 'preto' => __('⚫ Preto')]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $val => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($val); ?>" <?php echo e($leg->cor === $val ? 'selected' : ''); ?>><?php echo e($label); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            <input type="text" name="legendas[<?php echo e($i); ?>][descricao]" class="form-control form-control-sm"
                                   value="<?php echo e($leg->descricao); ?>" placeholder="<?php echo e(__('Ex: Saindo do Cantagalo')); ?>" required>
                            <button type="button" class="btn btn-sm btn-outline-danger flex-shrink-0 remover-legenda" title="<?php echo e(__('Remover')); ?>">
                                <i class="fa-solid fa-trash"></i>
                            </button>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                    <button type="button" class="btn btn-sm btn-outline-secondary mt-1" id="btn-add-legenda">
                        <i class="fa-solid fa-plus me-1"></i><?php echo e(__('Adicionar legenda')); ?>

                    </button>

                    
                    <hr>
                    <h6 class="mt-2 mb-1">
                        <i class="fa-solid fa-right-left me-1 text-muted"></i><?php echo e(__('Integrações')); ?>

                    </h6>
                    <p class="text-muted small mb-2">
                        <?php echo e(__('Indique quais linhas o passageiro pode usar em sequência pagando apenas uma passagem, e por quanto tempo.')); ?>

                    </p>
                    <div id="integracoes-container">
                        <?php $__currentLoopData = $linha->integracoes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $integ): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php $envolvidas = $integ->linhas_envolvidas ?? []; ?>
                        <div class="integracao-row border rounded p-3 mb-3 bg-light">
                            <div class="d-flex justify-content-between align-items-start mb-2">
                                <strong class="small text-muted"><?php echo e(__('Integração')); ?> <?php echo e($i + 1); ?></strong>
                                <button type="button" class="btn btn-sm btn-outline-danger remover-integracao" title="<?php echo e(__('Remover integração')); ?>">
                                    <i class="fa-solid fa-trash"></i>
                                </button>
                            </div>

                            
                            <div class="mb-3">
                                <label class="form-label form-label-sm fw-semibold">
                                    <i class="fa-regular fa-clock me-1"></i><?php echo e(__('Tempo de integração')); ?>

                                </label>
                                <div class="input-group input-group-sm" style="max-width:180px">
                                    <input type="number" min="0" max="9999"
                                           name="integracoes[<?php echo e($i); ?>][tempo_minutos]"
                                           class="form-control"
                                           value="<?php echo e($integ->tempo_minutos); ?>">
                                    <span class="input-group-text"><?php echo e(__('minutos')); ?></span>
                                </div>
                            </div>

                            
                            <label class="form-label form-label-sm fw-semibold mb-2">
                                <i class="fa-solid fa-bus me-1"></i><?php echo e(__('Linhas envolvidas na integração')); ?>

                            </label>
                            <div class="linhas-envolvidas-container d-flex flex-column gap-2 mb-2">
                                <?php $__currentLoopData = $envolvidas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $j => $lenv): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="linha-envolvida-row d-flex align-items-center gap-2">
                                    <?php if($j > 0): ?>
                                    <span class="text-muted fw-bold" style="width:20px;text-align:center">↔</span>
                                    <?php else: ?>
                                    <span style="width:20px"></span>
                                    <?php endif; ?>
                                    <input type="text"
                                           name="integracoes[<?php echo e($i); ?>][linhas][<?php echo e($j); ?>][codigo]"
                                           class="form-control form-control-sm"
                                           style="max-width:80px"
                                           value="<?php echo e($lenv['codigo'] ?? ''); ?>"
                                           placeholder="<?php echo e(__('Cód.')); ?>" required>
                                    <input type="text"
                                           name="integracoes[<?php echo e($i); ?>][linhas][<?php echo e($j); ?>][nome]"
                                           class="form-control form-control-sm"
                                           value="<?php echo e($lenv['nome'] ?? ''); ?>"
                                           placeholder="<?php echo e(__('Nome do destino, ex: Divisa Mangaratiba')); ?>" required>
                                    <?php if($j >= 2): ?>
                                    <button type="button" class="btn btn-sm btn-outline-danger flex-shrink-0 remover-linha-envolvida" title="<?php echo e(__('Remover')); ?>">
                                        <i class="fa-solid fa-minus"></i>
                                    </button>
                                    <?php else: ?>
                                    <span style="width:30px"></span>
                                    <?php endif; ?>
                                </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </div>
                            <button type="button" class="btn btn-sm btn-outline-secondary btn-add-linha-envolvida">
                                <i class="fa-solid fa-plus me-1"></i><?php echo e(__('Adicionar outra linha')); ?>

                            </button>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                    <button type="button" class="btn btn-sm btn-outline-secondary mt-1" id="btn-add-integracao">
                        <i class="fa-solid fa-plus me-1"></i><?php echo e(__('Adicionar integração')); ?>

                    </button>

                    <div id="mobiangra-horarios-linha-form-config" class="d-none"
                         data-legenda-idx="<?php echo e(count($linha->legendas)); ?>"
                         data-integracao-idx="<?php echo e(count($linha->integracoes)); ?>"
                         data-legendas='<?php echo json_encode($linha->legendas->map(fn ($l) => ["cor" => $l->cor, "descricao" => $l->descricao])->values(), 512) ?>'
                         data-cor-azul="<?php echo e(__('🔵 Azul')); ?>"
                         data-cor-vermelho="<?php echo e(__('🔴 Vermelho')); ?>"
                         data-cor-verde="<?php echo e(__('🟢 Verde')); ?>"
                         data-cor-laranja="<?php echo e(__('🟠 Laranja')); ?>"
                         data-cor-amarelo="<?php echo e(__('🟡 Amarelo')); ?>"
                         data-cor-preto="<?php echo e(__('⚫ Preto')); ?>"
                         data-ph-descricao="<?php echo e(__('Ex: Saindo do Cantagalo')); ?>"
                         data-ph-codigo="<?php echo e(__('Cód.')); ?>"
                         data-ph-nome="<?php echo e(__('Nome do destino, ex: Divisa Mangaratiba')); ?>"
                         data-label-integracao="<?php echo e(__('Integração')); ?>"
                         data-label-tempo="<?php echo e(__('Tempo de integração')); ?>"
                         data-label-minutos="<?php echo e(__('minutos')); ?>"
                         data-label-linhas="<?php echo e(__('Linhas envolvidas na integração')); ?>"
                         data-label-add-linha="<?php echo e(__('Adicionar outra linha')); ?>"
                         data-label-remover="<?php echo e(__('Remover')); ?>"
                         data-label-remover-integracao="<?php echo e(__('Remover integração')); ?>"
                         data-label-pintor="<?php echo e(__('Clique em cada horário para alternar a cor das legendas cadastradas.')); ?>"
                         data-label-cores="<?php echo e(__('Cores dos horários')); ?>"
                         data-label-sem-legenda="<?php echo e(__('Salve ao menos uma legenda de cor acima para pintar horários.')); ?>"
                         data-label-padrao="<?php echo e(__('Padrão (sem cor)')); ?>"
                         data-label-horarios="<?php echo e(__('horários')); ?>">
                    </div>
                <?php endif; ?>
            </div>

            <div class="d-flex gap-2 mb-4 flex-wrap">
                <?php if($isEdicao && (auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['visualizar'] ?? false)): ?>
                    <a href="<?php echo e(route('mobiangra.horarios', ['linha' => $linha->codigo])); ?>"
                       target="_blank"
                       rel="noopener noreferrer"
                       class="btn btn-outline-primary"
                       <?php if(! $linha->publicada): ?>
                           title="<?php echo e(__('Esta linha está oculta no site. Publique-a para que o público possa vê-la.')); ?>"
                       <?php else: ?>
                           title="<?php echo e(__('Abrir a grade de horários desta linha no site público')); ?>"
                       <?php endif; ?>>
                        <i class="fa-solid fa-eye me-1" aria-hidden="true"></i><?php echo e(__('Visualizar no site')); ?>

                    </a>
                <?php endif; ?>
                <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['editar'] ?? false): ?>
                    <button type="submit" class="btn btn-primary">
                        <i class="fa-solid fa-floppy-disk me-1"></i><?php echo e(__('Salvar dados da linha')); ?>

                    </button>
                    <a href="<?php echo e(route('admin.mobiangra.index', ['tab' => 'horarios'])); ?>" class="btn btn-outline-secondary">
                        <?php echo e(__('Cancelar')); ?>

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

        
        <?php if($isEdicao): ?>
            <hr>
            <div class="d-flex align-items-center justify-content-between mb-3">
                <h5 class="mb-0"><i class="fa-solid fa-table me-1"></i><?php echo e(__('Seções e Horários')); ?></h5>
                <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['adicionar'] ?? false): ?>
                <form action="<?php echo e(route('admin.mobiangra.horarios.secoes.store', $linha)); ?>" method="post" class="d-flex gap-2">
                    <?php echo csrf_field(); ?>
                    <input type="text" name="titulo" class="form-control form-control-sm"
                           style="width:260px" placeholder="<?php echo e(__('Título da nova seção, ex: SAÍDA DO CENTRO')); ?>" required>
                    <button type="submit" class="btn btn-sm btn-success">
                        <i class="fa-solid fa-plus me-1"></i><?php echo e(__('Adicionar seção')); ?>

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

            <?php $__empty_1 = true; $__currentLoopData = $linha->secoes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $secao): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <div class="border rounded mb-3" id="secao-<?php echo e($secao->id); ?>">
                
                <div class="d-flex align-items-center justify-content-between p-3 bg-light rounded-top border-bottom">
                    <form action="<?php echo e(route('admin.mobiangra.horarios.secoes.update', $secao)); ?>" method="post"
                          class="d-flex align-items-center gap-2 flex-grow-1 me-3">
                        <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                        <input type="text" name="titulo" class="form-control form-control-sm fw-semibold"
                               value="<?php echo e($secao->titulo); ?>" required>
                        <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['editar'] ?? false): ?>
                        <button type="submit" class="btn btn-sm btn-outline-primary text-nowrap">
                            <i class="fa-solid fa-pen"></i> <?php echo e(__('Renomear')); ?>

                        </button>
                        <?php endif; ?>
                    </form>
                    <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['excluir'] ?? false): ?>
                    <form action="<?php echo e(route('admin.mobiangra.horarios.secoes.destroy', $secao)); ?>" method="post"
                          onsubmit="return confirm('<?php echo e(__('Excluir esta seção e todos seus horários?')); ?>')">
                        <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                        <button type="submit" class="btn btn-sm btn-outline-danger">
                            <i class="fa-solid fa-trash"></i>
                        </button>
                    </form>
                    <?php endif; ?>
                </div>

                <div class="p-3">
                    
                    <?php if($secao->grades->isNotEmpty()): ?>
                    <div class="row g-3 mb-3">
                        <?php $__currentLoopData = $secao->grades; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $grade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="col-md-4">
                            <div class="card h-100 border-0 shadow-sm">
                                <div class="card-header d-flex justify-content-between align-items-center py-2"
                                     style="background:#0085CD;color:#fff">
                                    <strong class="small"><?php echo e($grade->label); ?></strong>
                                    <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['excluir'] ?? false): ?>
                                    <form action="<?php echo e(route('admin.mobiangra.horarios.grades.destroy', $grade)); ?>"
                                          method="post"
                                          onsubmit="return confirm('<?php echo e(__('Remover esta grade de horários?')); ?>')">
                                        <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="btn btn-sm btn-light border-0 p-1 lh-1">
                                            <i class="fa-solid fa-trash fa-xs text-danger"></i>
                                        </button>
                                    </form>
                                    <?php endif; ?>
                                </div>

                                <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['editar'] ?? false): ?>
                                <div class="card-body p-2">
                                    <form action="<?php echo e(route('admin.mobiangra.horarios.grades.store', $secao)); ?>"
                                          method="post"
                                          class="horarios-grade-form">
                                        <?php echo csrf_field(); ?>
                                        <input type="hidden" name="periodo" value="<?php echo e($grade->periodo); ?>">
                                        <input type="hidden" name="label" value="<?php echo e($grade->label); ?>">

                                        <?php if($linha->legendas->isNotEmpty()): ?>
                                            <p class="text-muted small mb-2">
                                                <?php echo e(__('Clique em um horário para alternar a cor. Abra "Edição em lote" para colar ou alterar a lista inteira.')); ?>

                                            </p>
                                            <div class="horarios-pintor-legenda mb-2">
                                                <?php $__currentLoopData = $linha->legendas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $leg): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <span class="horarios-pintor-legenda__item horarios-pintor-legenda__item--<?php echo e($leg->cor); ?>">
                                                        <?php echo e(__(':cor: :desc', ['cor' => ucfirst($leg->cor), 'desc' => $leg->descricao])); ?>

                                                    </span>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </div>
                                            <div class="horarios-pintor-chips d-flex flex-wrap gap-1 mb-2">
                                                <?php $__currentLoopData = $grade->horariosItens(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <button type="button"
                                                            class="btn btn-sm horarios-pintor-chip horarios-pintor-chip--<?php echo e($item['c'] ?: 'nenhuma'); ?>"
                                                            data-hora="<?php echo e($item['h']); ?>"
                                                            data-cor="<?php echo e($item['c'] ?? ''); ?>"
                                                            title="<?php echo e(__('Clique para alternar a cor')); ?>">
                                                        <?php echo e($item['h']); ?>

                                                    </button>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </div>
                                            <input type="hidden"
                                                   name="horarios_cores"
                                                   class="horarios-cores-input"
                                                   value="">
                                            <textarea name="horarios"
                                                      class="form-control form-control-sm font-monospace horarios-grade-textarea d-none"><?php echo e($grade->horariosComoTexto()); ?></textarea>
                                            <details class="mb-2">
                                                <summary class="small fw-semibold text-primary">
                                                    <?php echo e(__('Edição em lote (colar lista)')); ?>

                                                </summary>
                                                <textarea class="form-control form-control-sm font-monospace horarios-grade-bulk mt-2"
                                                          rows="3"
                                                          placeholder="06:50, 07:00, 07:30..."
                                                          title="<?php echo e(__('Horários separados por vírgula ou nova linha')); ?>"><?php echo e($grade->horariosComoTexto()); ?></textarea>
                                            </details>
                                        <?php else: ?>
                                            <textarea name="horarios"
                                                      class="form-control form-control-sm font-monospace mb-2 horarios-grade-textarea"
                                                      rows="4"
                                                      placeholder="06:50, 07:00, 07:30..."
                                                      title="<?php echo e(__('Horários separados por vírgula ou nova linha')); ?>"><?php echo e($grade->horariosComoTexto()); ?></textarea>
                                            <p class="text-muted small mb-2">
                                                <?php echo e(__('Salve ao menos uma legenda de cor acima para pintar horários.')); ?>

                                            </p>
                                        <?php endif; ?>

                                        <div class="d-flex justify-content-between align-items-center gap-2 mt-1">
                                            <small class="text-muted horarios-grade-count">
                                                <?php echo e(count($grade->horariosItens())); ?> <?php echo e(__('horários')); ?>

                                            </small>
                                            <button type="submit" class="btn btn-sm btn-primary">
                                                <i class="fa-solid fa-floppy-disk me-1"></i><?php echo e(__('Salvar')); ?>

                                            </button>
                                        </div>
                                    </form>
                                </div>
                                <?php else: ?>
                                <div class="card-body p-2">
                                    <div class="d-flex flex-wrap gap-1">
                                        <?php $__currentLoopData = $grade->horariosItens(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <span class="<?php echo \Illuminate\Support\Arr::toCssClasses([
                                                'badge border',
                                                'text-bg-light' => empty($item['c']),
                                                'horarios-pintor-chip--' . $item['c'] => ! empty($item['c']),
                                            ]); ?>"><?php echo e($item['h']); ?></span>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                    <small class="text-muted mt-1 d-block"><?php echo e(count($grade->horariosItens())); ?> <?php echo e(__('horários')); ?></small>
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                    <?php endif; ?>

                    
                    <?php if(auth()->user()->getPermissaoDetalhes('GERENCIADOR_DE_MOBIANGRA')['adicionar'] ?? false): ?>
                    <?php
                        $periodosExistentes = $secao->grades->pluck('periodo')->all();
                        $periodosDisponiveis = array_diff_key($periodos, array_flip($periodosExistentes));
                    ?>
                    <?php if(!empty($periodosDisponiveis)): ?>
                    <form action="<?php echo e(route('admin.mobiangra.horarios.grades.store', $secao)); ?>" method="post"
                          class="border rounded p-3 bg-light">
                        <?php echo csrf_field(); ?>
                        <h6 class="mb-2 text-muted"><?php echo e(__('Adicionar período')); ?></h6>
                        <div class="row g-2">
                            <div class="col-md-3">
                                <select name="periodo" class="form-select form-select-sm" required>
                                    <?php $__currentLoopData = $periodosDisponiveis; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($key); ?>"><?php echo e($label); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-md-2">
                                <input type="text" name="label" class="form-control form-control-sm"
                                       placeholder="<?php echo e(__('Label (opcional)')); ?>">
                            </div>
                            <div class="col">
                                <input type="text" name="horarios" class="form-control form-control-sm"
                                       placeholder="06:50, 07:00, 07:30, 08:00, ..." required>
                            </div>
                            <div class="col-auto">
                                <button type="submit" class="btn btn-sm btn-success">
                                    <i class="fa-solid fa-plus"></i>
                                </button>
                            </div>
                        </div>
                    </form>
                    <?php endif; ?>
                    <?php endif; ?>
                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="alert alert-info">
                <?php echo e(__('Nenhuma seção cadastrada. Adicione ao menos uma seção para incluir os horários.')); ?>

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

<?php $__env->startPush('scripts'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('pmar/css/admin/mobiangra/horarios_linha_form.css')); ?>?v=<?php echo e(time()); ?>">
<?php $__env->stopPush(); ?>

<?php $__env->startPush('after-scripts'); ?>
    <script src="<?php echo e(asset('pmar/js/admin/mobiangra/horarios_linha_form.js')); ?>?v=<?php echo e(time()); ?>"></script>
<?php $__env->stopPush(); ?>

<?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/mobiangra/horarios/linha_form.blade.php ENDPATH**/ ?>