<h4 class="mb-4"><i class="fas fa-file-import me-2"></i><?= lang('admin.import') ?></h4>
<div class="card mb-4"><div class="card-header">Upload Import File</div><div class="card-body">
    <form id="import-form" enctype="multipart/form-data">
        <input type="hidden" name="_token" value="<?= csrf_token() ?>">
        <div class="row g-3">
            <div class="col-md-4"><label class="form-label">Import Type</label><select name="import_type" class="form-select"><option value="members">Members</option></select></div>
            <div class="col-md-6"><label class="form-label">CSV File</label><input type="file" name="import_file" class="form-control" accept=".csv,.xls,.xlsx" required></div>
            <div class="col-md-2 d-flex align-items-end"><button type="submit" class="btn btn-primary w-100"><i class="fas fa-upload me-1"></i>Upload</button></div>
        </div>
    </form>
</div></div>
<div class="card"><div class="card-header">Import History</div><div class="card-body">
    <table id="import-table" class="table table-sm table-striped w-100" data-url="/admin/import/datatable"
           data-columns='[{"data":"batch"},{"data":"type"},{"data":"file"},{"data":"total"},{"data":"success"},{"data":"errors"},{"data":"status"},{"data":"by"},{"data":"date"}]'>
        <thead><tr><th>Batch</th><th>Type</th><th>File</th><th>Total</th><th>Success</th><th>Errors</th><th>Status</th><th>By</th><th>Date</th></tr></thead>
    </table>
</div></div>
<?php $__view->push('scripts') ?>
<script>
DataTableHelper.init('import-table');
$('#import-form').on('submit',function(e){
    e.preventDefault();const fd=new FormData(this);
    $.ajax({url:'/admin/import/upload',type:'POST',data:fd,processData:false,contentType:false,dataType:'json',
        success:function(r){if(r.success){FormHelper.showToast('success',r.message);DataTableHelper.reload('import-table');}else FormHelper.showToast('error',r.message);},
        error:function(){FormHelper.showToast('error','Upload failed');}
    });
});
</script>
<?php $__view->endPush() ?>