import 'package:ambito/src/extensions/extensions.dart';
import 'package:flutter/material.dart';

import '../actions/actions_page.dart';

class StartPage extends StatefulWidget {
  const StartPage({super.key});

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

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

  @override
  void initState() {
    setState(() {
      activeLink = 'database';
      content = const ActionsPage();
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading: Row(
            children: [
              const SizedBox(
                width: 30,
              ),
              Hero(
                tag: 'logo',
                child: Image.asset(
                  'assets/images/logo_trans.png',
                  width: 50,
                  height: 50,
                ),
              ),
              const SizedBox(
                width: 30,
              ),
              _linkButton('database'),
            ],
          ),
          leadingWidth: 400,
          toolbarHeight: 100,
          backgroundColor: Colors.white,
          actions: [
            IconButton(onPressed: () {}, icon: const Icon(Icons.person)),
            const SizedBox(
              width: 30,
            )
          ],
        ),
        body: const Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(height: 50),
            Expanded(
              child: ActionsPage(),
            ),
          ],
        ));
  }

  Widget getContent() {
    if (activeLink == 'database') {
      return const ActionsPage();
    }
    return Text(activeLink);
  }

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