<?php
    $layout = auth()->user()->role === 'super_admin' ? 'layouts.admin' : 'layouts.app';
?>



<?php $__env->startSection('title', 'Import Members'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid px-4 py-3">
    <div class="dashboard-header">
        <div class="container-fluid">
            <div class="row align-items-center dashboard-header-content">
                <div class="col-lg-6">
                    <h1 class="dashboard-title">
                        <i class="fas fa-upload" style="color: var(--dhis2-blue-primary);"></i>
                        Import Members from Excel
                    </h1>
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="javascript:history.back()">Back</a></li>
                            <li class="breadcrumb-item"><a href="<?php echo e(route('component1.members.index')); ?>">Members</a></li>
                            <li class="breadcrumb-item active">Import</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="container py-4">
    <div class="row justify-content-center">
        <div class="col-lg-10">
            <div class="card border-secondary border-2 shadow-lg rounded-3">
                <div class="card-body p-4 p-md-5">
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle me-2"></i>
                        <strong>Instructions:</strong>
                        <ul class="mt-2 mb-0">
                            <li>Download the template format from the button below</li>
                            <li>The Excel file should match the format from "VSLA Members Only Datasheet"</li>
                            <li><strong>Important:</strong> Groups must exist in the system before importing members</li>
                            <li>The system will create new members or update existing ones based on Individual ID and Group</li>
                        </ul>
                    </div>

                    <div class="text-center mb-4">
                        <a href="<?php echo e(route('component1.members.template')); ?>" class="btn btn-outline-primary">
                            <i class="fas fa-download me-2"></i> Download Excel Template
                        </a>
                    </div>

                    <form action="<?php echo e(route('component1.members.import.store')); ?>" method="POST" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        
                        <div class="row g-4 mb-4">
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Excel File <span class="text-danger">*</span></label>
                                <input type="file" name="excel_file" class="form-control <?php $__errorArgs = ['excel_file'];
$__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); ?>" 
                                       accept=".xlsx,.xls,.csv" required>
                                <small class="text-muted">Allowed formats: .xlsx, .xls, .csv (Max size: 10MB)</small>
                                <?php $__errorArgs = ['excel_file'];
$__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-bold">Filter by Group (Optional)</label>
                                <select name="group_id" class="form-select">
                                    <option value="">-- All Groups --</option>
                                    <?php $__currentLoopData = $groups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $id => $name): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($id); ?>" <?php echo e($selectedGroup == $id ? 'selected' : ''); ?>>
                                            <?php echo e($name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <small class="text-muted">If selected, only members from this group will be imported</small>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label fw-bold">Reporting Month</label>
                                <input type="month" name="month" class="form-control" 
                                       value="<?php echo e(old('month', date('Y-m'))); ?>">
                                <small class="text-muted">Data will be recorded for this month</small>
                            </div>
                        </div>

                        <div class="mt-4 pt-3 border-top border-secondary text-end">
                            <a href="<?php echo e(route('component1.members.index')); ?>" class="btn btn-outline-secondary me-2">
                                <i class="fas fa-times me-1"></i> Cancel
                            </a>
                            <button type="submit" class="btn btn-success">
                                <i class="fas fa-upload me-1"></i> Import Members
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php $__env->startPush('scripts'); ?>
<script>
    // Optional: Add file validation before submit
    document.querySelector('form').addEventListener('submit', function(e) {
        const fileInput = document.querySelector('input[name="excel_file"]');
        if (fileInput.files.length > 0) {
            const fileSize = fileInput.files[0].size / 1024 / 1024;
            if (fileSize > 10) {
                e.preventDefault();
                alert('File size exceeds 10MB. Please compress your file.');
            }
        }
    });
</script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make($layout, array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wampserver64\www\sswseepcomponents\resources\views/component1/members/import.blade.php ENDPATH**/ ?>