import 'dart:html' as html;

import 'package:ambito/src/extensions/extensions.dart';
import 'package:ambito/src/pages/ambito_page.dart';
import 'package:ambito/src/widgets/appbar/ambito_appbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
import 'package:get/get.dart';
import 'package:screen_breakpoints/screen_breakpoints.dart';

import '../../packages/ambito_theme/ambito_theme.dart';

class StartPage extends StatefulWidget {
  const StartPage({super.key, required this.activeLink});

  final AmbitoPage activeLink;

  @override
  State<StartPage> createState() => StartPageState();
}

class StartPageState extends State<StartPage> {
  Widget content = const SizedBox();
  String title = '';

  @override
  void initState() {
    setState(() {
      content = widget.activeLink;
      html.window.history.pushState(
          null, widget.activeLink.title, '#/${widget.activeLink.path}');
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final AmbitoTheme theme = getTheme(context);
    return Scaffold(
        appBar: AmbitoAppbar(
          breakpoint: Breakpoint.fromContext(context),
          theme: theme,
        ),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            if (widget.activeLink.path != 'massnahmen')
              Align(
                alignment: Alignment.centerLeft,
                child: BreadCrumb(
                  items: <BreadCrumbItem>[
                    BreadCrumbItem(
                      content: TextButton(
                        onPressed: () {
                          Get.offAndToNamed('/');
                        },
                        child: const Text('Start'),
                      ),
                    ),
                    BreadCrumbItem(
                      content: Text(
                        widget.activeLink.title,
                      ),
                    ),
                  ],
                  divider: const Icon(Icons.chevron_right),
                ),
              ),
            const SizedBox(height: 50),
            Expanded(
              child: content,
            ),
          ],
        ));
  }

  Widget _linkButton(String link, Widget targetPage) {
    double fontSize = 20;
    return TextButton(
      style: ButtonStyle(
        overlayColor:
            WidgetStateProperty.resolveWith<Color>((Set<WidgetState> states) {
          return Colors.transparent;
        }),
      ),
      onPressed: () {
        Get.offAndToNamed('/');
      },
      child: Text(
        context.translate('page.start.links.$link.title'),
        style: TextStyle(
          fontSize: fontSize,
          fontWeight: FontWeight.bold,
          //color: (activeLink == link) ? Colors.grey.shade800 : Colors.black,
        ),
      ),
    );
  }
}
