import 'package:flutter/material.dart';
import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:flutter/services.dart';

import '../../models/invite.dart';
import '../../theme/theme_extension.dart';

class InviteRow extends StatelessWidget {
  const InviteRow({
    super.key,
    required this.invite,
    required this.onRevoke,
  });

  final Invite invite;
  final VoidCallback onRevoke;

  @override
  Widget build(BuildContext context) {
    final fs = Theme.of(context).extension<FabledSwordTheme>()!;
    return ListTile(
      title: Row(
        children: [
          Expanded(
            child: SelectableText(
              invite.token,
              style: TextStyle(
                color: fs.parchment,
                fontFamily: 'JetBrainsMono',
                fontSize: 13,
              ),
            ),
          ),
          IconButton(
            icon: Icon(LucideIcons.copy, color: fs.ash, size: 18),
            tooltip: 'Copy',
            onPressed: () =>
                Clipboard.setData(ClipboardData(text: invite.token)),
          ),
        ],
      ),
      subtitle: Wrap(
        spacing: 8,
        crossAxisAlignment: WrapCrossAlignment.center,
        children: [
          Text('expires ${invite.expiresAt}',
              style: TextStyle(color: fs.ash, fontSize: 12)),
          if (invite.note != null)
            Text('· ${invite.note}',
                style: TextStyle(color: fs.ash, fontSize: 12)),
          if (invite.isRedeemed)
            Container(
              padding:
                  const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
              decoration: BoxDecoration(
                color: fs.ash,
                borderRadius: BorderRadius.circular(6),
              ),
              child: Text(
                'redeemed',
                style: TextStyle(color: fs.obsidian, fontSize: 10),
              ),
            ),
        ],
      ),
      trailing: IconButton(
        icon: Icon(LucideIcons.trash_2, color: fs.oxblood),
        tooltip: 'Revoke',
        onPressed: onRevoke,
      ),
    );
  }
}
