import 'package:flutter/material.dart';

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

class NetpcSpaceApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Netpc.Space Dashboard',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primaryColor: Color(0xFF532E41),
        scaffoldBackgroundColor: Color(0xFF09090A),
        fontFamily: 'Roboto', // Default font
        textTheme: TextTheme(
          bodyLarge: TextStyle(color: Colors.white),
          bodyMedium: TextStyle(color: Colors.white),
        ),
      ),
      home: DashboardScreen(),
    );
  }
}

class DashboardScreen extends StatefulWidget {
  @override
  State<DashboardScreen> createState() => _DashboardScreenState();
}

class _DashboardScreenState extends State<DashboardScreen> {
  String selectedTab = 'Главное';

  @override
  Widget build(BuildContext context) {
    // Fixed screen size assumption
    return Scaffold(
      body: SizedBox(
        width: 1920,
        height: 1080,
        child: Stack(
          children: [
            // Sidebar
            Positioned(
              left: 0,
              top: 0,
              child: Sidebar(
                selectedTab: selectedTab,
                onTabSelected: (tab) {
                  setState(() {
                    selectedTab = tab;
                  });
                },
              ),
            ),
            // Main Content
            Positioned(
              left: 400, // Sidebar width
              top: 0,
              child: MainContent(
                selectedTab: selectedTab,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class Sidebar extends StatelessWidget {
  final String selectedTab;
  final Function(String) onTabSelected;

  Sidebar({required this.selectedTab, required this.onTabSelected});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 400, // Fixed width
      height: 1080, // Fixed height
      color: Color(0xFF09090A), // Background color
      child: Stack(
        children: [
          // "netpc.space" Text
          Positioned(
            left: 128,
            top: 63,
            child: Text(
              'netpc.space',
              style: TextStyle(
                color: Colors.white,
                fontSize: 24,
                fontWeight: FontWeight.bold,
                fontFamily: 'NeueMachina', // Ensure this font is added
              ),
            ),
          ),
          // User Card
          Positioned(
            left: 128,
            top: 120,
            child: Container(
              width: 240, // Adjusted width to fit within sidebar
              padding: EdgeInsets.all(16),
              decoration: BoxDecoration(
                color: Colors.white.withOpacity(0.1),
                border: Border.all(color: Colors.white30),
                borderRadius: BorderRadius.circular(12),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Row(
                    children: [
                      // Static User Icon
                      Icon(
                        Icons.person,
                        color: Colors.white,
                        size: 40,
                      ),
                      SizedBox(width: 16),
                      // Username and Logout Button
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              'username',
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 18,
                                fontFamily: 'Roboto',
                              ),
                            ),
                            SizedBox(height: 4),
                            GestureDetector(
                              onTap: () {
                                // Handle logout
                              },
                              child: Row(
                                children: [
                                  Icon(
                                    Icons.logout,
                                    color: Colors.white,
                                    size: 16,
                                  ),
                                  SizedBox(width: 4),
                                  Text(
                                    'Logout',
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 14,
                                      fontFamily: 'Roboto',
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                  SizedBox(height: 16),
                  // User Balance
                  Row(
                    children: [
                      Icon(
                        Icons.account_balance_wallet,
                        color: Colors.white,
                        size: 24,
                      ),
                      SizedBox(width: 8),
                      Text(
                        '10000',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 16,
                          fontFamily: 'Roboto',
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
          // Spacer after User Card
          Positioned(
            left: 128,
            top: 220,
            child: SizedBox(
              width: 240,
              height: 40, // Adjust as needed for spacing
              child: Container(), // Transparent space
            ),
          ),
          // "Основное" Text
          Positioned(
            left: 128,
            top: 280,
            child: Text(
              'Основное',
              style: TextStyle(
                color: Color(0xFF532E41), // Purple color
                fontSize: 20,
                fontWeight: FontWeight.bold,
                fontFamily: 'Roboto',
              ),
            ),
          ),
          // Navigation Buttons
          Positioned(
            left: 128,
            top: 320,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                NavButton(
                  icon: Icons.dashboard,
                  label: 'Главное',
                  isSelected: selectedTab == 'Главное',
                  onTap: () => onTabSelected('Главное'),
                ),
                NavButton(
                  icon: Icons.settings,
                  label: 'Настройки',
                  isSelected: selectedTab == 'Настройки',
                  onTap: () => onTabSelected('Настройки'),
                ),
                // Add more navigation buttons here as needed
              ],
            ),
          ),
        ],
      );
    }
}

class NavButton extends StatelessWidget {
  final IconData icon;
  final String label;
  final bool isSelected;
  final VoidCallback onTap;

  NavButton({
    required this.icon,
    required this.label,
    this.isSelected = false,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        width: 240, // Adjusted width to fit within sidebar
        height: 48, // Fixed height for uniformity
        margin: EdgeInsets.only(bottom: 16),
        padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
        decoration: BoxDecoration(
          color: isSelected ? Colors.black.withOpacity(0.7) : Colors.transparent,
          borderRadius: BorderRadius.circular(8),
        ),
        child: Row(
          children: [
            Icon(
              icon,
              color: Colors.white,
            ),
            SizedBox(width: 16),
            Text(
              label,
              style: TextStyle(
                color: Colors.white,
                fontSize: 16,
                fontFamily: 'Roboto',
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class MainContent extends StatelessWidget {
  final String selectedTab;

  MainContent({required this.selectedTab});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 1520, // 1920 - 400 (sidebar) = 1520
      height: 1080,
      child: Stack(
        children: [
          // Welcome Image Container
          Positioned(
            left: 123, // 523 - 400
            top: 74,
            child: Container(
              width: 1176,
              height: 184,
              decoration: BoxDecoration(
                color: Colors.grey[800],
                borderRadius: BorderRadius.circular(12),
                image: DecorationImage(
                  image: AssetImage('assets/images/welcome_background.png'),
                  fit: BoxFit.cover,
                  colorFilter: ColorFilter.mode(
                    Colors.black.withOpacity(0.3),
                    BlendMode.darken,
                  ), // Ensures text readability
                ),
              ),
              child: Stack(
                children: [
                  // Welcome Texts
                  Positioned(
                    left: 58, // x578 - x523 = 55 (Adjusted within container)
                    top: 58, // y132 - y74 = 58
                    child: Container(
                      width: 800,
                      height: 50,
                      child: Text(
                        'Добро пожаловать, username',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 28,
                          fontFamily: 'Unbounded', // Ensure this font is added
                        ),
                      ),
                    ),
                  ),
                  Positioned(
                    left: 54, // x577 - x523 = 54
                    top: 117, // y191 - y74 = 117
                    child: Container(
                      width: 1084,
                      height: 40,
                      child: Text(
                        'Приветствуем в панели хостинга netpc.space, тут вы можете управлять вашими услугами',
                        style: TextStyle(
                          color: Colors.grey[300],
                          fontSize: 16,
                          fontFamily: 'Roboto',
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          // My Servers Text
          Positioned(
            left: 123, // 523 - 400
            top: 314,
            child: Text(
              'My Servers',
              style: TextStyle(
                color: Colors.white,
                fontSize: 24,
                fontWeight: FontWeight.bold,
                fontFamily: 'Roboto',
              ),
            ),
          ),
          // Server List
          Positioned(
            left: 123, // 523 - 400
            top: 380,
            child: ServerList(),
          ),
          // Settings Tab Content
          if (selectedTab == 'Настройки')
            Positioned.fill(
              child: SettingsTab(),
            ),
        ],
      ),
    );
  }
}

class ServerList extends StatelessWidget {
  // Mock server data
  final List<Map<String, String>> servers = [
    {
      'name': 'Server One',
      'address': '192.168.1.1',
      'cpu': '4 cores',
      'ram': '16GB',
      'disk': '512GB SSD',
      'flag': '🇩🇪', // Germany flag as emoji
    },
    {
      'name': 'Server Two',
      'address': '192.168.1.2',
      'cpu': '8 cores',
      'ram': '32GB',
      'disk': '1TB SSD',
      'flag': '🇺🇸', // USA flag as emoji
    },
    // Add more servers as needed
  ];

  @override
  Widget build(BuildContext context) {
    return Column(
      children: servers
          .map((server) => Padding(
                padding: const EdgeInsets.only(bottom: 16),
                child: ServerCard(server: server),
              ))
          .toList(),
    );
  }
}

class ServerCard extends StatelessWidget {
  final Map<String, String> server;

  ServerCard({required this.server});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 1176,
      height: 139,
      decoration: BoxDecoration(
        color: Colors.white.withOpacity(0.05),
        border: Border.all(color: Colors.white30),
        borderRadius: BorderRadius.circular(12),
      ),
      child: Padding(
        padding: EdgeInsets.fromLTRB(
            54, 16, 16, 16), // Adjusted padding based on positions
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            // Flag
            Container(
              width: 34,
              height: 37,
              decoration: BoxDecoration(
                // Replace with Image.asset if using image flags
                image: DecorationImage(
                  image: AssetImage(_getFlagAsset(server['flag']!)),
                  fit: BoxFit.cover,
                ),
              ),
            ),
            SizedBox(width: 16), // Adjusted spacing
            // Server Name and Address
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: 334,
                  height: 28,
                  child: Text(
                    server['name'] ?? 'Unnamed Server',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                      fontFamily: 'Unbounded', // Ensure this font is added
                    ),
                  ),
                ),
                SizedBox(height: 8),
                Container(
                  width: 221,
                  height: 24,
                  child: Text(
                    'Address: ${server['address'] ?? 'N/A'}',
                    style: TextStyle(
                      color: Colors.grey,
                      fontSize: 16,
                      fontFamily: 'Roboto',
                    ),
                  ),
                ),
                SizedBox(height: 8),
                // Server Info Buttons
                Row(
                  children: [
                    InfoButton(label: 'CPU: ${server['cpu'] ?? 'N/A'}'),
                    SizedBox(width: 8),
                    InfoButton(label: 'RAM: ${server['ram'] ?? 'N/A'}'),
                    SizedBox(width: 8),
                    InfoButton(label: 'Disk: ${server['disk'] ?? 'N/A'}'),
                  ],
                ),
              ],
            ),
            Spacer(),
            // Manage Button
            ElevatedButton.icon(
              onPressed: () {
                // Handle management action
              },
              icon: Icon(
                Icons.settings,
                color: Color(0xFF532E41),
                size: 20,
              ),
              label: Text(
                'Управление',
                style: TextStyle(color: Colors.white, fontFamily: 'Unbounded'),
              ),
              style: ElevatedButton.styleFrom(
                backgroundColor: Colors.grey, // Grey background
                padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(8),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // Helper method to get flag asset based on emoji
  String _getFlagAsset(String emojiFlag) {
    // Map emoji to asset paths
    // Ensure these images are added to assets/images/flags/
    switch (emojiFlag) {
      case '🇩🇪':
        return 'assets/images/flags/germany.png';
      case '🇺🇸':
        return 'assets/images/flags/usa.png';
      // Add more cases as needed
      default:
        return 'assets/images/flags/default.png';
    }
  }
}

class InfoButton extends StatelessWidget {
  final String label;

  InfoButton({required this.label});

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: () {
        // OnClick info is zero as per specification
      },
      child: Text(
        label,
        style: TextStyle(
          fontSize: 14,
          fontFamily: 'Roboto',
        ),
      ),
      style: ElevatedButton.styleFrom(
        foregroundColor: Colors.white,
        backgroundColor: Colors.grey.withOpacity(0.5), // Grey with transparency
        padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(8),
        ),
        elevation: 0,
      ),
    );
  }
}

class SettingsTab extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Placeholder for Settings
    return Container(
      color: Colors.black54, // Semi-transparent background
      child: Center(
        child: Text(
          'Настройки',
          style: TextStyle(
            fontSize: 24,
            color: Colors.white,
            fontFamily: 'Roboto',
          ),
        ),
      ),
    );
  }
}


238 line ; error excepted