import 'package:flutter/material.dart';
import 'package:softplayer_web/api/grpc/environments.dart';
import 'package:softplayer_web/helpers/providers/common.dart';

class EnvirnomentCard extends StatelessWidget {
  final EnvironmentLocalData env;

  const EnvirnomentCard({
    super.key,
    required this.env,
  });

  @override
  Widget build(BuildContext context) {
    Provider provider = ProviderHelper().getProvider(env.provider);

    String serverType;
    String serverLocation;
    try {
      serverType = ProviderHelper().getServerType(env.serverType);
      serverLocation = provider.getServerLocation(env.serverLocation);
    } catch (e) {
      rethrow;
    }

    return Card(
      child: SelectionArea(
        child: Column(
          children: [
            Text(env.name),
            const Divider(),
            Table(
              border: const TableBorder(
                bottom: BorderSide.none,
                left: BorderSide.none,
                right: BorderSide.none,
                top: BorderSide.none,
              ),
              children: [
                TableRow(children: [
                  Text("Description"),
                  Text(env.description),
                ]),
                TableRow(children: [
                  Text("Provider"),
                  Text(provider.getProviderName()),
                ]),
                TableRow(children: [
                  Text("Server Type"),
                  Text(serverType),
                ]),
                TableRow(children: [
                  Text("Location"),
                  Text(serverLocation),
                ]),
              ],
            )
          ],
        ),
      ),
    );
  }
}
