import 'package:flutter/material.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/models/global_config_model.dart';
import 'package:hmg_qline/models/ticket_model.dart';
import 'package:hmg_qline/utilities/enums.dart';
import 'package:hmg_qline/utilities/extensions.dart';
import 'package:hmg_qline/views/common_widgets/app_texts_widget.dart';
import 'package:hmg_qline/views/main_queue_screen/components/priority_tickets.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';

class PriorityTicketsWithSidelist extends StatelessWidget {
  final List<TicketDetailsModel> tickets;
  final GlobalConfigurationsModel globalConfigurationsModel;
  final ScreenOrientationEnum screenOrientationEnum;

  const PriorityTicketsWithSidelist({
    super.key,
    required this.tickets,
    required this.globalConfigurationsModel,
    required this.screenOrientationEnum,
  });

  @override
  Widget build(BuildContext context) {
    final priorityTickets = tickets.sublist(0, AppConstants.thresholdForListUI);
    final otherTickets = tickets.sublist(AppConstants.thresholdForListUI, tickets.length);

    final List<Widget> children = [
      Expanded(flex: 7, child: PriorityTickets(globalConfigurationsModel: globalConfigurationsModel, tickets: priorityTickets)),
      Container(color: Colors.grey.withOpacity(0.1), width: 10, margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 50)),
      Expanded(
        flex: 6,
        child: ListView(
          children: [
            Padding(
              padding: const EdgeInsets.fromLTRB(10, 0, 10, 10),
              child: Directionality(
                textDirection: globalConfigurationsModel.textDirection,
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                      flex: 5,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          AppText(
                            globalConfigurationsModel.queueNoText ?? "",
                            letterSpacing: -2,
                            fontHeight: 0.5,
                            fontWeight: FontWeight.bold,
                            fontSize: SizeConfig.getWidthMultiplier() * 3.8,
                            textAlign: TextAlign.center,
                            fontFamily: globalConfigurationsModel.screenLanguageEnum == LanguageEnum.arabic ? AppStrings.fontNameCairo : AppStrings.fontNamePoppins,
                          ),
                        ],
                      ),
                    ),
                    Container(
                      color: Colors.grey.withOpacity(0.5),
                      width: 5,
                      height: SizeConfig.getHeightMultiplier() * 0.3,
                      margin: const EdgeInsets.symmetric(horizontal: 15),
                    ),
                    if (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment) ...[
                      Expanded(
                        flex: 5,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            AppText(
                              globalConfigurationsModel.callForText ?? "",
                              letterSpacing: -2,
                              fontHeight: 0.5,
                              fontWeight: FontWeight.bold,
                              fontSize: SizeConfig.getWidthMultiplier() * 3.8,
                              textAlign: TextAlign.center,
                            ),
                          ],
                        ),
                      ),
                      Container(
                        color: Colors.grey.withOpacity(0.5),
                        width: 5,
                        height: SizeConfig.getHeightMultiplier() * 0.3,
                        margin: const EdgeInsets.symmetric(horizontal: 15),
                      ),
                    ],
                    Expanded(
                      flex: 3,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          AppText(
                            (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment ? globalConfigurationsModel.roomText : globalConfigurationsModel.counterText) ?? "",
                            letterSpacing: -2,
                            fontHeight: 0.5,
                            fontWeight: FontWeight.bold,
                            fontSize: SizeConfig.getWidthMultiplier() * 3.8,
                            textAlign: TextAlign.center,
                            fontFamily: globalConfigurationsModel.screenLanguageEnum == LanguageEnum.arabic ? AppStrings.fontNameCairo : AppStrings.fontNamePoppins,
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            ListView.builder(
              shrinkWrap: true,
              itemCount: otherTickets.length,
              itemBuilder: (ctx, index) {
                final ticketModel = otherTickets[index].ticketModel;
                return Padding(
                  padding: const EdgeInsets.all(8),
                  child: Directionality(
                    textDirection: globalConfigurationsModel.textDirection,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Expanded(
                          flex: 5,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              AppText(
                                ticketModel!.queueNo ?? "",
                                letterSpacing: -1,
                                fontWeight: FontWeight.bold,
                                fontSize: SizeConfig.getWidthMultiplier() * 3.5,
                                textAlign: TextAlign.center,
                                fontHeight: 0.5,
                                fontFamily: globalConfigurationsModel.screenLanguageEnum == LanguageEnum.arabic ? AppStrings.fontNameCairo : AppStrings.fontNamePoppins,
                              ),
                            ],
                          ),
                        ),
                        Container(
                          color: Colors.grey.withOpacity(0.5),
                          width: 5,
                          height: SizeConfig.getHeightMultiplier() * 0.3,
                          margin: const EdgeInsets.symmetric(horizontal: 15),
                        ),
                        if (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment) ...[
                          Expanded(
                            flex: 5,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Padding(
                                  padding: const EdgeInsets.only(bottom: 8.0),
                                  child: SizedBox(
                                    height: SizeConfig.getWidthMultiplier() * 3,
                                    child: ticketModel.callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.3),
                                  ),
                                ),
                                const SizedBox(width: 15),
                                AppText(
                                  ticketModel.callTypeEnum.getMessageByCallType(globalConfigurationsModel, isListView: true),
                                  color: ticketModel.callTypeEnum.getColorByCallType(),
                                  fontSize: SizeConfig.getWidthMultiplier() * 3,
                                  fontWeight: FontWeight.w600,
                                  fontHeight: 0.5,
                                ),
                              ],
                            ),
                          ),
                          Container(
                            color: Colors.grey.withOpacity(0.5),
                            width: 5,
                            height: SizeConfig.getHeightMultiplier() * 0.3,
                            margin: const EdgeInsets.symmetric(horizontal: 15),
                          ),
                        ],
                        Expanded(
                          flex: 3,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              AppText(
                                ticketModel.roomNo ?? "",
                                color: AppColors.blackColor,
                                letterSpacing: -1.5,
                                fontHeight: 0.5,
                                fontSize: SizeConfig.getWidthMultiplier() * 3.3,
                                fontWeight: FontWeight.w600,
                                fontFamily: globalConfigurationsModel.screenLanguageEnum == LanguageEnum.arabic ? AppStrings.fontNameCairo : AppStrings.fontNamePoppins,
                              ),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                );
              },
            ),
          ],
        ),
      )
    ];
    return (screenOrientationEnum == ScreenOrientationEnum.portraitUp || screenOrientationEnum == ScreenOrientationEnum.portraitDown)
        ? Row(
            children: children,
          )
        : Column(
            children: children,
          );
  }
}
