import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:unit2/model/profile/work_history.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';

import '../../../utils/global.dart';

class WorkHistoryScreen extends StatelessWidget {
  final List<WorkHistory> workExperiences;
  const WorkHistoryScreen({super.key, required this.workExperiences});

 

  @override
  Widget build(BuildContext context) {
     DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
    return Scaffold(
      appBar: AppBar(
        title: const Text(workHistoryScreenTitle),
        backgroundColor: primary,
        centerTitle: true,
        actions: [AddLeading(onPressed: (){})],
      ),
      body: workExperiences.isNotEmpty? ListView.builder(
          padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
          itemCount: workExperiences.length,
          itemBuilder: (BuildContext context, int index) {
        String position = workExperiences[index].position!.title!;
        String agency = workExperiences[index].agency!.name!;
        String from =
            dteFormat2.format(workExperiences[index].fromDate!);
        String? to = workExperiences[index].toDate == null
            ? present.toUpperCase()
            : dteFormat2.format(workExperiences[index].toDate!);
        return Column(
   
          children: [
            Container(
              width: screenWidth,
              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.w600),),
                   const Divider(),
                    const SizedBox(height: 8,),
                    Text(agency,style: Theme.of(context).textTheme.titleSmall!.copyWith(fontWeight: FontWeight.w500),),
                    const SizedBox(height: 5,),
                    Text("$from to $to",style: Theme.of(context).textTheme.bodyMedium,),
                  ],
                )),
                IconButton(onPressed: () {}, icon: const Icon(Icons.more_vert,color: Colors.grey,))
              ]),
            ),
            const SizedBox(
              height: 5,
            ),
          ],
        );
      }):const EmptyData(message: "You don't have any Work History added. Please click + to add ."),
    );
  }
}
