import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:nm/nm.dart';

import '../../../../../common/routing/routes.dart';
import 'wifi_bar_icon.dart';

class AccessPointTile extends ConsumerWidget {
  const AccessPointTile({
    required this.accessPoint,
    required this.client,
    required this.device,
    super.key,
  });

  final NetworkManagerAccessPoint accessPoint;
  final NetworkManagerClient client;
  final NetworkManagerDevice device;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Card(
      child: InkWell(
        borderRadius: Theme.of(context).useMaterial3
            ? const BorderRadius.all(Radius.circular(12.0))
            : const BorderRadius.all(Radius.circular(4.0)),
        onTap: () {
          context.pushNamed(
            RoutesSettings.accesspoint.name,
            extra: accessPoint,
          );
        },
        child: ListTile(
          leading: Row(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              WifiBarIcon(strength: accessPoint.strength),
              if (accessPoint.rsnFlags.isNotEmpty)
                const Icon(
                  Icons.lock,
                  size: 14,
                )
            ],
          ),
          title: Text(String.fromCharCodes(accessPoint.ssid)),
          trailing: device.activeConnection?.id ==
                  String.fromCharCodes(accessPoint.ssid)
              ? const Text('Connected')
              : null,
        ),
      ),
    );
  }
}
