import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:gap/gap.dart';
import 'package:pharmacy_mobile/blocs/guest/functions/bloc_setgueston.dart';
import 'package:pharmacy_mobile/widgets/button_widget.dart';
import 'package:pharmacy_mobile/widgets/image_widget.dart';
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
import 'package:pharmacy_mobile/widgets/slogan_widget.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:pharmacy_mobile/widgets/title_widget.dart';

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

  @override
  Widget build(BuildContext context) {
    void gotoLogin() {
      context.push('/login');
    }

    void gotoRegister() {
      context.push('/register');
    }

    void loginAsGuest() async {
      final setGuest = await blocSetGuestOn(context);
      if (setGuest) {
        // ignore: use_build_context_synchronously
        context.push('/customer');
      }
    }

    return Scaffold(
        resizeToAvoidBottomInset: false,
        body: PageBackgroundWidget(
          child: Column(
            children: [
              const Gap(88),
              const TitleWidget(
                firstTextSize: 24,
                secondTextSize: 40,
                logoSize: 124,
              ),
              const Gap(32),
              Padding(
                padding: const EdgeInsets.fromLTRB(0, 0, 38, 0),
                child: const ImageWidget(imagePath: 'assets/ph_logo.webp', size: 168, measureByHeight: false),
              ),
              const Gap(64),
              ButtonWidget(text: 'Login', onPressed: gotoLogin),
              const Gap(8),
              ButtonWidget(text: 'Register', onPressed: gotoRegister, outline: true),
              const Gap(32),
              GestureDetector(
                onTap: loginAsGuest,
                child: const TextWidget(
                  text: "Login as Guest",
                  size: 12,
                  underlined: true,
                  color: Color.fromRGBO(198, 133, 232, 1),
                  bold: true,
                ),
              ),
              const Gap(32),
              const SloganWidget(),
              const Gap(32),
              const MaxGap(500),
              const TextWidget(
                text: '© 2025 - Ofelia Franco-Alcala Pharmacy',
                size: 10,
              ),
              const Gap(4),
              const TextWidget(
                text: 'Developed By: Pat Alcala',
                size: 8,
                opacity: 0.8,
              ),
              const Gap(8)
            ],
          ),
        ));
  }
}
