@extends('admin.layouts.app')

@section('title', __('Import Dependents'))

@section('content')
<x-admin.page-header title="{{ __('Import Dependents') }}" :breadcrumbs="[__('dashboard.dependents') => route('admin.dependents.index'), __('Import Dependents') => '']" />

<div class="row">
    <div class="col-lg-12 p-0">
        <div class="card">
            <div class="card-header pb-0 card-no-border">
                <div class="d-flex flex-wrap gap-2 mt-2">
                    <a href="{{ route('admin.dependents.export') }}" class="btn btn-soft-primary btn-sm">
                        <i class="ri-download-2-line me-1"></i> {{ __('Export Dependents CSV') }}
                    </a>
                    <a href="{{ route('admin.dependents.import.template') }}" class="btn btn-soft-info btn-sm">
                        <i class="ri-file-download-line me-1"></i> {{ __('Download Import Template') }}
                    </a>
                    <a href="{{ route('admin.dependents.index') }}" class="btn btn-light btn-sm">
                        <i class="ri-arrow-left-line me-1"></i> {{ __('Back to Dependents') }}
                    </a>
                </div>

                <div class="alert alert-warning mt-3 mb-0">
                    {{ __('The member_phone column is required to attach each dependent to the parent member account.') }}
                </div>

                @if(session('import_report'))
                    @php $report = session('import_report'); @endphp
                    <div class="alert alert-info mt-3 mb-0">
                        <strong>{{ __('Import Summary') }}:</strong>
                        {{ __('Added') }}: {{ $report['added'] ?? 0 }},
                        {{ __('Skipped') }}: {{ $report['skipped'] ?? 0 }}
                        @if(!empty($report['errors']))
                            <hr class="my-2">
                            <ul class="mb-0 ps-3">
                                @foreach($report['errors'] as $err)
                                    <li>{{ $err }}</li>
                                @endforeach
                            </ul>
                        @endif
                    </div>
                @endif
            </div>

            <div class="card-body">
                <form action="{{ route('admin.dependents.import') }}" method="POST" enctype="multipart/form-data" class="row g-3 align-items-end">
                    @csrf
                    <div class="col-md-8">
                        <label class="form-label">{{ __('File') }}</label>
                        <input type="file" name="file" class="form-control" accept=".csv,.txt,.xlsx,.xls" required>
                    </div>
                    <div class="col-md-4 d-grid">
                        <button type="submit" class="btn btn-success">
                            <i class="ri-upload-2-line me-1"></i> {{ __('Start Import') }}
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection

