import 'dart:math';

import 'package:flutter/material.dart';

import 'package:puissance4/cpu.dart';
import 'package:puissance4/match_page.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blue,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            TextButton(
              style: TextButton.styleFrom(
                backgroundColor: Colors.green,
                padding: const EdgeInsets.all(15),
              ),
              child: Text(
                '🧑 2 JOUEURS 🧑',
                style:
                    Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.white),
              ),
              onPressed: () {
                Navigator.pushNamed(
                  context,
                  '/match',
                  arguments: {
                    'mode': Mode.pvp,
                  },
                );
              },
            ),
            TextButton(
              style: TextButton.styleFrom(
                backgroundColor: Colors.orange,
                padding: const EdgeInsets.all(15),
              ),
              child: Text(
                '🧑 1 JOUEUR 🤖',
                style:
                    Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.white),
              ),
              onPressed: () {
                Navigator.pushNamed(
                  context,
                  '/cpu-level',
                  arguments: {
                    'mode': Mode.pvc,
                  },
                );
              },
            ),
            TextButton(
              style: TextButton.styleFrom(
                backgroundColor: Colors.white,
                padding: const EdgeInsets.all(15),
              ),
              child: Text(
                '🤖 DEMO 🤖',
                style:
                    Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.black),
              ),
              onPressed: () {
                final harderCpu = HarderCpu(Random().nextBool() ? Color.red : Color.yellow);
                Navigator.pushNamed(
                  context,
                  '/match',
                  arguments: {
                    'mode': Mode.demo,
                    'cpu': harderCpu,
                    'cpu2': HardestCpu(harderCpu.otherPlayer),
                  },
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}