// TODO this lays out long text lines on a newline after a uilink rather than soft wrapping it.
import 'package:dartboard_resume/annotation_manager.dart';
import 'package:dartboard_resume/models/document_text.dart';
import 'package:dartboard_resume/models/theme.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';

class AnnotatedText extends StatelessWidget {
  AnnotatedText({this.bulletString, required this.stringSections, this.style});

  final String? bulletString;
  final List<DocumentTextLinkData> stringSections;
  final TextStyle? style;

  @override
  Widget build(Context context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(bulletString == null ? '' : '$bulletString ', style: style),
        SizedBox(
          width: DocumentTheme.width - DocumentTheme.margin * 2 - 20.0,
          child: RichText(
            text: TextSpan(
              children: [
                ...stringSections.map((s) {
                  return TextSpan(text: s.text, style: style);
                  // switch (s.type) {
                  //   case DartboardTextType.normal:
                  //     return [Text(s.text, style: style)];
                  //   case DartboardTextType.linkText:
                  //     final number = UrlFootnotes().add(url: s.url!);
                  //     return [
                  //       Text(s.text, style: style),
                  //       UrlLink(
                  //         destination: s.url!,
                  //         child: Padding(
                  //           padding: const EdgeInsets.only(bottom: 4.0, left: 2.0, right: 2.0),
                  //           child: Text(
                  //             number.toString(),
                  //             style: style?.copyWith(color: PdfColors.blue, fontSize: 8),
                  //           ),
                  //         ),
                  //       ),
                  //     ];
                  // }
                }),
                ...stringSections.map((s) {
                  switch (s.type) {
                    case DocumentTextType.normal:
                      return null;
                    case DocumentTextType.linkText:
                      final number = AnnotationManager().add(url: s.url!);
                      return TextSpan(
                        text: ' [$number]',
                        style: style?.copyWith(color: PdfColors.blue, fontSize: 8),
                      );
                    // return UrlLink(
                    //   destination: s.url!,
                    //   child: Padding(
                    //     padding: const EdgeInsets.only(bottom: 4.0, left: 2.0, right: 2.0),
                    //     child: Text(
                    //       number.toString(),
                    //       style: style?.copyWith(color: PdfColors.blue, fontSize: 8),
                    //     ),
                    //   ),
                    // );
                  }
                }).nonNulls,
              ],
            ),
          ),
        ),
      ],
    );
  }
}