fillSheetWithChoices static method

void fillSheetWithChoices(
  1. Sheet sheet,
  2. List<(int, int, Choice)> choices,
  3. List<Student> students,
  4. bool applyColors,
)

Implementation

static void fillSheetWithChoices(Sheet sheet, List<(int, int, Choice)> choices, List<Student> students, bool applyColors) {
  int rowIndex = 1; // Start after header

  for (var c in choices) {
    Student? currentStudent = students.where((e) => e.id == c.$1).firstOrNull;
    if (currentStudent == null) continue;

    Choice currentChoice = c.$3;
    int choiceNumber = c.$2;

    // Create cell values for this row
    List<CellValue?> studentValues = [
      TextCellValue(currentStudent.name),
      IntCellValue(choiceNumber),
      TextCellValue(currentChoice.school.country),
      TextCellValue(currentChoice.school.name),
      TextCellValue(currentStudent.departement),
      DoubleCellValue(currentChoice.interranking),
      IntCellValue(currentStudent.ects_number),
      TextCellValue(currentStudent.lang_lvl),
      DoubleCellValue(currentStudent.missed_hours),
      IntCellValue(currentChoice.school.available_slots),
      TextCellValue(currentStudent.comment),
      TextCellValue(currentChoice.post_comment ?? " - ")
    ];

    sheet.appendRow(studentValues);

    // Apply color coding if needed (only for the main sheet)
    if (applyColors) {
      List<Data?> currentRow = sheet.row(rowIndex);

      // Green for accepted choices
      if (currentStudent.accepted != null && currentStudent.accepted!.school.id == currentChoice.school.id) {
        for (var data in currentRow) {
          data?.cellStyle = CellStyle(backgroundColorHex: ExcelColor.green200);
        }
      }
      // Red for rejected choices
      else if (currentStudent.refused.any((choice) => choice.school.id == currentChoice.school.id)) {
        for (var data in currentRow) {
          data?.cellStyle = CellStyle(backgroundColorHex: ExcelColor.red200);
        }
      }
    }

    rowIndex++;
  }
}