import 'package:flutter/material.dart';

void main() {
  runApp(NetpcSpaceApp());
}

class NetpcSpaceApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'netpc.space',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        // Set 'Onest' as the default font
        fontFamily: 'Onest',
        primaryColor: Color(0xFFF497C8),
        scaffoldBackgroundColor: Color.fromARGB(255, 8, 0, 17),
        inputDecorationTheme: InputDecorationTheme(
          filled: true,
          fillColor: Colors.grey.withOpacity(0.03), // Semi-transparent grey
          contentPadding: EdgeInsets.symmetric(
            vertical: 24.0, // Increased vertical padding for taller text fields
            horizontal: 12.0,
          ),
          enabledBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10), // Consistent radius
            borderSide: BorderSide(
              color: Colors.grey,
              width: 0.2, // Width remains the same
            ),
          ),
          focusedBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10), // Consistent radius
            borderSide: BorderSide(
              color: Color(0xFFF497C8),
              width: 0.3,
            ),
          ),
          prefixIconColor: Colors.grey,
          hintStyle: TextStyle(
            color: Colors.grey[300], // Lighter grey for hint text
            fontSize: 14, // Restored hint text size
          ),
          labelStyle: TextStyle(
            color: Colors.white,
            fontSize: 12, // Restored label text size
          ),
        ),
        textTheme: TextTheme(
          // Define text styles for different text elements
          labelLarge: TextStyle(
            fontFamily: 'NeueMachina',
            fontSize: 12, // Restored font size for labels
            color: Colors.white,
          ),
          bodyMedium: TextStyle(
            fontFamily: 'NeueMachina',
            fontSize: 12, // Restored font size for body text
            color: Colors.white,
          ),
          titleLarge: TextStyle(
            fontFamily: 'NeueMachina',
            fontSize: 28,
            fontWeight: FontWeight.bold,
            color: Colors.white,
          ),
        ),
      ),
      home: LoginPage(),
    );
  }
}

class LoginPage extends StatefulWidget {
  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  bool isRegister = false;

  // Controllers for text fields
  final TextEditingController loginController = TextEditingController();
  final TextEditingController passwordController = TextEditingController();
  final TextEditingController usernameController = TextEditingController();

  // Function to handle form submission
  void handleSubmit() {
    if (isRegister) {
      // Handle registration API call
      String username = usernameController.text;
      String login = loginController.text;
      String password = passwordController.text;
      // TODO: Implement API call for registration
      print('Register: $username, $login, $password');
    } else {
      // Handle login API call
      String login = loginController.text;
      String password = passwordController.text;
      // TODO: Implement API call for login
      print('Login: $login, $password');
    }
  }

  @override
  Widget build(BuildContext context) {
    // Define static card size
    final double cardWidth = 734;
    final double cardHeight = 600;

    return Scaffold(
      backgroundColor: Color.fromARGB(255, 7, 0, 14),
      body: Center(
        child: Container(
          width: cardWidth, // Fixed width
          height: cardHeight, // Fixed height
          padding: EdgeInsets.all(24),
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage('assets/images/card_background.png'),
              fit: BoxFit.cover,
              colorFilter: ColorFilter.mode(
                const Color.fromARGB(255, 6, 0, 12).withOpacity(0.5),
                BlendMode.darken,
              ), // Optional: Darken the image for better readability
            ),
            borderRadius: BorderRadius.circular(12), // Smooth border radius
            border: Border.all(
              color: Color.fromARGB(255, 41, 40, 42),
              width: 0.2, // Improved border visibility
            ),
          ),
          child: SingleChildScrollView(
            // Added to prevent overflow
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                // Centered Title
                SizedBox(height: 90),
                Text(
                  'netpc.space',
                  style: Theme.of(context).textTheme.titleLarge,
                  textAlign: TextAlign.center,
                ),
                SizedBox(height: 20),
                // Username Field (only in Register)
                if (isRegister) ...[
                  TextField(
                    controller: usernameController,
                    decoration: InputDecoration(
                      hintText: 'введите ваш никнейм',
                      prefixIcon: Icon(Icons.person), // More relevant icon
                    ),
                    style: TextStyle(
                      fontSize: 12, // Restored text size
                      color: Colors.white,
                    ),
                  ),
                  SizedBox(height: 20),
                ],
                // Login Field
                TextField(
                  controller: loginController,
                  decoration: InputDecoration(
                    hintText: 'введите вашу электронную почту',
                    prefixIcon: Icon(Icons.email), // More relevant icon
                  ),
                  keyboardType: TextInputType.emailAddress,
                  style: TextStyle(
                    fontSize: 12, // Restored text size
                    color: Colors.white,
                  ),
                ),
                SizedBox(height: 20),
                // Password Field (always visible)
                TextField(
                  controller: passwordController,
                  decoration: InputDecoration(
                    hintText: 'введите ваш пароль',
                    prefixIcon:
                        Icon(Icons.lock), // Changed to lock icon for relevance
                  ),
                  obscureText: true, // Typically passwords are obscured
                  style: TextStyle(
                    fontSize: 12, // Restored text size
                    color: Colors.white,
                  ),
                ),
                SizedBox(height: 40),
                // Submit Button
                SizedBox(
                  width: double.infinity,
                  height: 50,
                  child: ElevatedButton(
                    onPressed: handleSubmit,
                    style: ElevatedButton.styleFrom(
                      foregroundColor: Color.fromARGB(255, 239, 239, 239),
                      backgroundColor: Colors.transparent,
                      side: BorderSide(
                          color: Color.fromARGB(255, 255, 255, 255),
                          width:
                              0.1), // Increased border width and changed color
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(6),
                      ),
                    ),
                    child: Text(
                      isRegister
                          ? 'зарегистрировать новый аккаунт'
                          : 'перейти в биллинг',
                      style: TextStyle(
                        fontSize: 17, // Kept font size for button text
                        color: Colors.white,
                        fontFamily: 'Onest', // Ensuring font is applied
                      ),
                    ),
                  ),
                ),
                SizedBox(height: 20),
                // Register and Forgot Password Buttons
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    // Register Button
                    TextButton(
                      onPressed: () {
                        setState(() {
                          isRegister = true;
                        });
                      },
                      child: Text(
                        'Зарегистрироваться',
                        style: TextStyle(
                          color: Colors.white,
                          decoration: TextDecoration.underline,
                          fontFamily: 'Onest',
                          fontSize: 17, // Restored font size
                        ),
                      ),
                    ),
                    // Forgot Password Button
                    TextButton(
                      onPressed: () {
                        // Navigate to Forgot Password page or handle accordingly
                        print('Forgot Password tapped');
                      },
                      child: Text(
                        'Забыли пароль?',
                        style: TextStyle(
                          color: Colors.white,
                          decoration: TextDecoration.underline,
                          fontFamily: 'Onest',
                          fontSize: 17, // Restored font size
                        ),
                      ),
                    ),
                  ],
                ),
                // If in Register mode, show an option to switch back to Login
                if (isRegister) ...[
                  SizedBox(height: 10),
                  TextButton(
                    onPressed: () {
                      setState(() {
                        isRegister = false;
                      });
                    },
                    child: Text(
                      'Уже есть аккаунт? Войти',
                      style: TextStyle(
                        color: Colors.white,
                        decoration: TextDecoration.underline,
                        fontFamily: 'Onest',
                        fontSize: 12, // Restored font size
                      ),
                    ),
                  ),
                ],
              ],
            ),
          ),
        ),
      ),
    );
  }
}


text field's and button's need's to have statis w553