// Flutter
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher_string.dart';

_launchSite(String url) async {
  try {
    if (await canLaunchUrlString(url)) {
      await launchUrlString(
        url,
        mode: LaunchMode.externalApplication,
      );
    } else {
      throw "System does not think it can launch '$url'.";
    }
  } on Exception catch (e) {
    throw e.toString();
  }
}

class HelpPage extends StatelessWidget {
  const HelpPage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return Column(
      children: [
        Expanded(
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(4),
                color: theme.colorScheme.onPrimary,
              ),
              child: Column(
                children: [
                  Text(
                    "\t\t This app is meant to be a simple budgeting tool,"
                    " allowing you to view your income and expenses at a high"
                    " level without micro managing specific budget items or"
                    " adding receipts.",
                  ),
                  Text(
                    "\n\t\t Tracked items can be swiped left to right for ,"
                    " Deletion or right to left for Editing. Items are sorted"
                    " from highest to lowest so that the biggest impacts are"
                    " always in view.",
                  ),
                  Text(
                    "\n\t\t To subscribe to app updates, install the Obtanium"
                    " app, then use the URL from the Source Code button below."
                    " Otherwise the app needs installed manually by downloading"
                    " APKs from the Source Code /releases/ page.",
                  ),
                  //Text("Another paragraph.")
                ],
              ),
            ),
          ),
        ),
        Row(
          children: [
            Expanded(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(4),
                    color: theme.colorScheme.onPrimary,
                  ),
                  child: TextButton.icon(
                    onPressed: () {
                      _launchSite(
                        "https://git.hyperling.com/me/flutter-expense-tracker",
                      );
                    },
                    icon: Icon(Icons.code),
                    label: Text("Source Code"),
                  ),
                ),
              ),
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(4),
                    color: theme.colorScheme.onPrimary,
                  ),
                  child: TextButton.icon(
                    onPressed: () {
                      _launchSite(
                        "https://hyperling.com",
                      );
                    },
                    icon: Icon(Icons.web_asset),
                    label: Text("Personal Website"),
                  ),
                ),
              ),
            ),
          ],
        )
      ],
    );
  }
}