import 'dart:developer';

import 'package:flutter/material.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/views/main_queue_screen/components/ticket_item.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';

class PriorityTickets extends StatelessWidget {
  final List<TicketDetailsModel> tickets;
  final GlobalConfigurationsModel globalConfigurationsModel;

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

  @override
  Widget build(BuildContext context) {
    final TicketData firstTicket = tickets[0].ticketModel!;
    final List<TicketDetailsModel> otherTickets = tickets.sublist(1, tickets.length);
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        TicketItem(
          ticketNo: firstTicket.queueNo ?? '',
          scale: globalConfigurationsModel.screenTypeEnum == ScreenTypeEnum.roomLevelScreen ? 2 : 1.2,
          blink: true,
          roomNo: firstTicket.roomNo ?? '',
          roomText: (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment ? globalConfigurationsModel.roomText : globalConfigurationsModel.counterText) ?? "",
          isClinicAdded: false,
          callTypeEnum: firstTicket.callTypeEnum,
          textDirection: globalConfigurationsModel.textDirection,
          screenTypeEnum: globalConfigurationsModel.screenTypeEnum,
          langTypeEnum: globalConfigurationsModel.screenLanguageEnum,
          globalConfigurationsModel: globalConfigurationsModel,
        ),
        if (tickets.length > 1) ...[
          Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: otherTickets.map((ticketDetailsModel) {
              TicketData ticketData = ticketDetailsModel.ticketModel!;

              return Padding(
                padding: EdgeInsets.only(top: SizeConfig.getHeightMultiplier() * 0.5),
                child: TicketItem(
                  ticketNo: ticketData.queueNo ?? '',
                  scale: 0.8,
                  roomNo: ticketData.roomNo ?? '',
                  roomText: (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment ? globalConfigurationsModel.roomText : globalConfigurationsModel.counterText) ?? "",
                  isClinicAdded: false,
                  callTypeEnum: ticketData.callTypeEnum,
                  textDirection: globalConfigurationsModel.textDirection,
                  screenTypeEnum: globalConfigurationsModel.screenTypeEnum,
                  langTypeEnum: globalConfigurationsModel.screenLanguageEnum,
                  globalConfigurationsModel: globalConfigurationsModel,
                ),
              );
            }).toList(),
          )
        ]
      ],
    );
  }
}
