import 'package:flutter/material.dart';
import 'package:tm_app/core/routes/app_routes.dart';
import 'package:tm_app/core/theme/colors.dart';
import 'package:tm_app/core/utils/size_config.dart';
import 'package:tm_app/views/detail/strings/tender_details_strings.dart';

class SelectMeetingTimeBottomSheet extends StatefulWidget {
  const SelectMeetingTimeBottomSheet({required this.onConfirm, super.key});
  final ValueChanged<String> onConfirm;

  @override
  State<SelectMeetingTimeBottomSheet> createState() =>
      _SelectMeetingTimeBottomSheetState();
}

class _SelectMeetingTimeBottomSheetState
    extends State<SelectMeetingTimeBottomSheet> {
  int selectedType = 0;
  late String type = '';

  final List<Map<String, String>> times = [
    {'title': 'Sun 2025-06-15', 'value': 'mode1', 'time': '10:00'},
    {'title': 'Sun 2025-06-16', 'value': 'mode2', 'time': '12:00'},
    {'title': 'Sun 2025-06-17', 'value': 'mode3', 'time': '14:00'},
    {'title': 'Sun 2025-06-18', 'value': 'mode4', 'time': '16:00'},
    {'title': 'Sun 2025-06-19', 'value': 'mode5', 'time': '18:00'},
  ];

  @override
  Widget build(BuildContext context) {
    return Wrap(
      children: [
        Container(
          width: double.infinity,
          padding: EdgeInsets.fromLTRB(24.0.w(), 24.0.h(), 24.0.w(), 33.0.h()),
          decoration: BoxDecoration(
            color: AppColors.backgroundColor,
            borderRadius: const BorderRadius.only(
              topLeft: Radius.circular(16.0),
              topRight: Radius.circular(16.0),
            ),
          ),
          child: Column(
            children: [
              Text(
                TenderDetailsStrings.meetingTime,
                style: TextStyle(
                  fontSize: 20.0.sp(),
                  fontWeight: FontWeight.w600,
                  color: AppColors.grey70,
                ),
              ),
              SizedBox(height: 15.0.h()),
              ListView.builder(
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                itemCount: times.length,
                itemBuilder: (context, index) {
                  final item = times[index];
                  return Padding(
                    padding: EdgeInsets.only(bottom: 8.0.h()),
                    child: _submissionType(
                      title: item['title']!,
                      time: item['time']!,
                      isSelected: type == item['value'],
                      onTap: () {
                        selectedType = index;
                        type = item['value']!;
                        setState(() {});
                      },
                    ),
                  );
                },
              ),
              SizedBox(height: 8.0.h()),
              SizedBox(height: 8.0.h()),
              InkWell(
                onTap: () {
                  const CompletionOfDocumentsMobileRouteData().push(context);
                  //context.pop();
                },
                child: Container(
                  width: double.infinity,
                  height: 56.0.h(),
                  decoration: BoxDecoration(
                    color: AppColors.primary20,
                    borderRadius: BorderRadius.circular(100),
                  ),
                  alignment: Alignment.center,
                  child: Text(
                    TenderDetailsStrings.apply,
                    style: TextStyle(
                      fontSize: 14.0.sp(),
                      fontWeight: FontWeight.w500,
                      color: AppColors.mainBlue,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget _submissionType({
    required VoidCallback onTap,
    required String title,
    required String time,
    required bool isSelected,
  }) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8.0),
        border: Border.all(
          color: isSelected ? AppColors.mainBlue : AppColors.grey40,
        ),
      ),
      child: InkWell(
        onTap: onTap,
        child: SizedBox(
          width: double.infinity,
          height: 40.0.h(),
          child: Row(
            children: [
              Container(
                width: 20.0.w(),
                height: 20.0.w(),
                margin: EdgeInsets.symmetric(
                  horizontal: 10.0.w(),
                  vertical: 10.0.h(),
                ),
                padding: const EdgeInsets.all(3),
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  border: Border.all(
                    color: isSelected ? AppColors.mainBlue : AppColors.grey70,
                    width: 2.0,
                  ),
                ),
                alignment: Alignment.center,
                child: Container(
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    color: isSelected ? AppColors.mainBlue : Colors.transparent,
                  ),
                ),
              ),
              Expanded(
                child: Row(
                  children: [
                    Text(
                      title,
                      style: TextStyle(
                        fontSize: 14.0.sp(),
                        fontWeight: FontWeight.w500,
                        color: AppColors.grey80,
                      ),
                    ),
                    const Spacer(),
                    Text(
                      time,
                      style: TextStyle(
                        fontSize: 14.0.sp(),
                        fontWeight: FontWeight.w500,
                        color: AppColors.grey80,
                      ),
                    ),
                    SizedBox(width: 10.0.w()),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
