<?php $__env->startSection('title', 'Create Budget'); ?>

<?php $__env->startSection('content'); ?>
    <?php if (isset($component)) { $__componentOriginal00a2e3c817942d1565d2933416f28c6a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal00a2e3c817942d1565d2933416f28c6a = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.page-head','data' => ['title' => 'Set Up Budget','subtitle' => 'Budget by account with variance tracking']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('page-head'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Set Up Budget','subtitle' => 'Budget by account with variance tracking']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal00a2e3c817942d1565d2933416f28c6a)): ?>
<?php $attributes = $__attributesOriginal00a2e3c817942d1565d2933416f28c6a; ?>
<?php unset($__attributesOriginal00a2e3c817942d1565d2933416f28c6a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal00a2e3c817942d1565d2933416f28c6a)): ?>
<?php $component = $__componentOriginal00a2e3c817942d1565d2933416f28c6a; ?>
<?php unset($__componentOriginal00a2e3c817942d1565d2933416f28c6a); ?>
<?php endif; ?>

    <?php if (isset($component)) { $__componentOriginal36665f0dc0e45320e21db1e20a989acf = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal36665f0dc0e45320e21db1e20a989acf = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.panel','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('panel'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
        <form method="POST" action="<?php echo e(route('finance.budgets.store')); ?>" id="budgetForm">
            <?php echo csrf_field(); ?>
            <div style="display:grid; grid-template-columns: repeat(2, 1fr); gap:16px; margin-bottom:20px;">
                <div class="form-group">
                    <label class="form-label" for="name">Budget Name</label>
                    <input class="input" type="text" id="name" name="name" value="<?php echo e(old('name')); ?>" required>
                </div>
                <div class="form-group">
                    <label class="form-label" for="fiscal_year">Fiscal Year</label>
                    <input class="input" type="text" id="fiscal_year" name="fiscal_year" value="<?php echo e(old('fiscal_year', now()->format('Y'))); ?>" required>
                </div>
                <div class="form-group">
                    <label class="form-label" for="academic_year_id">Academic Year</label>
                    <select class="input" id="academic_year_id" name="academic_year_id">
                        <option value="">—</option>
                        <?php $__currentLoopData = $academicYears; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $year): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($year->id); ?>" <?php if(old('academic_year_id') == $year->id): echo 'selected'; endif; ?>><?php echo e($year->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="form-group" style="grid-column: span 2;">
                    <label class="form-label" for="description">Description</label>
                    <textarea class="input" id="description" name="description" rows="2"><?php echo e(old('description')); ?></textarea>
                </div>
            </div>

            <h4 style="margin-bottom:12px;">Budget Lines</h4>
            <table id="linesTable">
                <thead><tr><th>Account</th><th>Amount</th><th>Period</th><th>Notes</th></tr></thead>
                <tbody>
                    <?php for($i = 0; $i < max(1, count(old('lines', []))); $i++): ?>
                        <?php ($line = old('lines.'.$i, [])); ?>
                        <tr>
                            <td>
                                <select class="input" name="lines[<?php echo e($i); ?>][account_id]" required>
                                    <option value="">Select account</option>
                                    <?php $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($account->id); ?>" <?php if(($line['account_id'] ?? '') == $account->id): echo 'selected'; endif; ?>>
                                            <?php echo e($account->code); ?> — <?php echo e($account->name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </td>
                            <td><input class="input" type="number" step="0.01" min="0" name="lines[<?php echo e($i); ?>][amount]" value="<?php echo e($line['amount'] ?? ''); ?>" required style="width:120px;"></td>
                            <td><input class="input" type="text" name="lines[<?php echo e($i); ?>][period]" value="<?php echo e($line['period'] ?? ''); ?>" placeholder="Q1, Term 1"></td>
                            <td><input class="input" type="text" name="lines[<?php echo e($i); ?>][notes]" value="<?php echo e($line['notes'] ?? ''); ?>"></td>
                        </tr>
                    <?php endfor; ?>
                </tbody>
            </table>

            <div style="display:flex; gap:10px; margin-top:16px;">
                <button type="button" class="btn btn-outline" onclick="addLine()">Add Line</button>
                <button type="submit" class="btn btn-primary">Save Budget</button>
                <a href="<?php echo e(route('finance.budgets.index')); ?>" class="btn btn-ghost">Cancel</a>
            </div>
        </form>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal36665f0dc0e45320e21db1e20a989acf)): ?>
<?php $attributes = $__attributesOriginal36665f0dc0e45320e21db1e20a989acf; ?>
<?php unset($__attributesOriginal36665f0dc0e45320e21db1e20a989acf); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal36665f0dc0e45320e21db1e20a989acf)): ?>
<?php $component = $__componentOriginal36665f0dc0e45320e21db1e20a989acf; ?>
<?php unset($__componentOriginal36665f0dc0e45320e21db1e20a989acf); ?>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
function addLine() {
    const tbody = document.querySelector('#linesTable tbody');
    const index = tbody.children.length;
    const firstSelect = tbody.querySelector('select');
    const row = document.createElement('tr');
    row.innerHTML = `
        <td>${firstSelect.outerHTML.replace(/lines\[\d+\]/g, 'lines[' + index + ']').replace(/selected/g, '')}</td>
        <td><input class="input" type="number" step="0.01" min="0" name="lines[${index}][amount]" required style="width:120px;"></td>
        <td><input class="input" type="text" name="lines[${index}][period]"></td>
        <td><input class="input" type="text" name="lines[${index}][notes]"></td>`;
    tbody.appendChild(row);
}
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\southend\resources\views\admin\budgets\create.blade.php ENDPATH**/ ?>