prepareSeoApprovalChecklistComponent function

SeoApprovalChecklistComponentPlan? prepareSeoApprovalChecklistComponent({
  1. required List<SeoApprovalChecklistItemEntry> items,
  2. required SeoApprovalChecklistState initialState,
  3. required SeoApprovalChecklistViewProjection project,
  4. String? interactionId,
  5. int headingLevel = 2,
  6. String heading = 'Approval checklist',
  7. String interactionLabel = 'Approval checklist controls',
  8. String statusLabel = 'Status',
  9. String progressLabel = 'Progress',
})

Implementation

SeoApprovalChecklistComponentPlan? prepareSeoApprovalChecklistComponent({
  required List<SeoApprovalChecklistItemEntry> items,
  required SeoApprovalChecklistState initialState,
  required SeoApprovalChecklistViewProjection project,
  String? interactionId,
  int headingLevel = 2,
  String heading = 'Approval checklist',
  String interactionLabel = 'Approval checklist controls',
  String statusLabel = 'Status',
  String progressLabel = 'Progress',
}) {
  if (items.isEmpty || items.length > seoApprovalChecklistMaxItems) return null;
  final rawLabels = <String>[
    heading,
    interactionLabel,
    statusLabel,
    progressLabel,
    for (final item in items) item.label,
  ];
  if (rawLabels.fold<int>(0, (sum, label) => sum + label.length) >
      seoApprovalChecklistMaxAggregateLabelTextLength) {
    return null;
  }
  final labels = <String>[];
  for (final raw in rawLabels) {
    final label = canonicalizeSeoConfiguratorText(
      raw,
      maxLength: seoApprovalChecklistMaxLabelTextLength,
    );
    if (label == null) return null;
    labels.add(label.trim());
  }
  final itemLabels = labels.skip(4).toList(growable: false);
  if (itemLabels.toSet().length != itemLabels.length) return null;
  final initial = evaluateInitialSeoApprovalChecklistView(
    project,
    initialState,
    itemCount: items.length,
  );
  if (initial == null) return null;
  final candidateId = interactionId?.trim();
  final id = candidateId != null && isValidSeoInteractionId(candidateId)
      ? candidateId
      : null;
  return SeoApprovalChecklistComponentPlan._(
    items: List.unmodifiable([
      for (final (index, item) in items.indexed)
        (
          label: itemLabels[index],
          nodes: List<SeoNode>.unmodifiable(item.nodes),
        ),
    ]),
    initial: initial,
    interactionId: id,
    headingLevel: headingLevel.clamp(1, 6),
    heading: labels[0],
    interactionLabel: labels[1],
    statusLabel: labels[2],
    progressLabel: labels[3],
  );
}