import 'package:flutter/material.dart';
import 'package:my_attendance/models/attendance_entry.dart';
import 'package:my_attendance/services/attendance_service.dart';
import 'package:provider/provider.dart';

class LeaveRequestScreen extends StatelessWidget {
  const LeaveRequestScreen({super.key});
  static const routeName = '/request-leave';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Request Leave')),
      body: SafeArea(
        child: ListView(
          padding: const EdgeInsets.all(8.0),
          children: [
            ...LeaveType.values.map(
              (type) => Card(
                child: ListTile(
                  leading: Icon(
                    _getLeaveTypeIcon(type),
                    color: Theme.of(context).colorScheme.primary,
                  ),
                  title: Text(_getLeaveTypeName(type)),
                  onTap: () {
                    Provider.of<AttendanceService>(
                      context,
                      listen: false,
                    ).markAsLeave(type);
                    Navigator.of(context).pop();
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  String _getLeaveTypeName(LeaveType type) {
    switch (type) {
      case LeaveType.sick:
        return 'Sick Leave';
      case LeaveType.annual:
        return 'Annual Leave';
      case LeaveType.nationalHoliday:
        return 'National Holiday';
      case LeaveType.companyWfh:
        return 'Company WFH';
    }
  }

  IconData _getLeaveTypeIcon(LeaveType type) {
    switch (type) {
      case LeaveType.sick:
        return Icons.sick_outlined;
      case LeaveType.annual:
        return Icons.card_travel;
      case LeaveType.nationalHoliday:
        return Icons.flag_outlined;
      case LeaveType.companyWfh:
        return Icons.business_center_outlined;
    }
  }
}
