import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:unit2/model/profile/voluntary_works.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart';

class VolunataryWorkScreen extends StatelessWidget {
  final List<VoluntaryWork> voluntaryWorks;
  const VolunataryWorkScreen({super.key, required this.voluntaryWorks});

  @override
  Widget build(BuildContext context) {
    DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
    return Scaffold(
      appBar: AppBar(
        title: const Text(voluntaryScreenTitle),
        backgroundColor: primary,
        actions: [AddLeading(onPressed: (){})],
      ),
      body: voluntaryWorks.isNotEmpty? ListView.builder(
          itemCount: voluntaryWorks.length,
          padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
          itemBuilder: (BuildContext context, int index) {
            String position = voluntaryWorks[index].position!.title!;
            String agency = voluntaryWorks[index].agency!.name!;
            String from = dteFormat2.format(voluntaryWorks[index].fromDate!);
            String hours = voluntaryWorks[index].totalHours.toString();
            String? to = voluntaryWorks[index].toDate == null
                ? "Present"
                : dteFormat2.format(voluntaryWorks[index].toDate!);
            return Column(
              children: [
                Container(
                  decoration: box1(),
                  padding:
                      const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
                  child: Row(
                    children: [
                      Expanded(
                        child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                position,
                                style: Theme.of(context)
                                    .textTheme
                                    .titleMedium!
                                    .copyWith(fontWeight: FontWeight.w500),
                              ),
                              const SizedBox(
                                height: 5,
                              ),
                              Text(
                                agency,
                                style: Theme.of(context).textTheme.titleSmall,
                              ),
                              const Divider(),
                              const SizedBox(
                                height: 3,
                              ),
                              Text("$duration : $from to $to"),
                              const SizedBox(
                                height: 5,
                              ),
                              Text("$numberOfHours : $hours hours"),
                            ]),
                      ),
                      IconButton(
                          onPressed: () {}, icon: const Icon(Icons.more_vert))
                    ],
                  ),
                ),
                const SizedBox(
                  height: 5,
                ),
              ],
            );
          }):const EmptyData(message: "You don't have any Voluntary Works added. Please click + to add."),
    );
  }
}
