@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h3>Import Employees</h3>
                </div>
                <div class="card-body">
                    @if(session('import_results'))
                        <div class="alert alert-info">
                            <strong>Import Results:</strong>
                            <ul>
                                <li>Total Rows: {{ session('import_results')['total_rows'] }}</li>
                                <li>Successful: {{ session('import_results')['successful'] }}</li>
                                <li>Dismissed: {{ session('import_results')['dismissed'] }}</li>
                                <li>Updated: {{ session('import_results')['updated'] }}</li>
                                <li>Failed: {{ session('import_results')['failed'] }}</li>
                            </ul>
                            @if(!empty(session('import_results')['details']))
                                <details>
                                    <summary>View Details</summary>
                                    <pre>{{ json_encode(session('import_results')['details'], JSON_PRETTY_PRINT) }}</pre>
                                </details>
                            @endif
                        </div>
                    @endif

                    <form method="POST" action="{{ route('employees.import') }}" enctype="multipart/form-data">
                        @csrf
                        <div class="form-group mb-3">
                            <label for="import_file">Excel/CSV File</label>
                            <input type="file" class="form-control @error('import_file') is-invalid @enderror" 
                                   id="import_file" name="import_file" accept=".xlsx,.csv,.xls" required>
                            @error('import_file')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                            <small class="form-text text-muted">
                                Required columns: employee_code, name, hire_date<br>
                                Optional: email, phone, status, station_code, dismissal_reason, termination_date
                            </small>
                        </div>
                        
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">Import Employees</button>
                            <a href="{{ route('employees.index') }}" class="btn btn-secondary">Cancel</a>
                        </div>
                    </form>
                    
                    <hr>
                    
                    <div class="mt-3">
                        <h5>Sample Excel Format</h5>
                        <table class="table table-sm table-bordered">
                            <thead>
                                <tr>
                                    <th>employee_code</th><th>name</th><th>hire_date</th>
                                    <th>status</th><th>dismissal_reason</th><th>station_code</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr><td>EMP001</td><td>John Doe</td><td>2024-01-15</td>
                                    <td>active</td><td></td><td>STN01</td></tr>
                                <tr><td>EMP002</td><td>Jane Smith</td><td>2023-06-20</td>
                                    <td>terminated</td><td>Poor performance</td><td>STN02</td></tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection