import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:krow_domain/krow_domain.dart';
import 'package:core_localization/core_localization.dart';

/// A card displaying information about a single hub.
class HubCard extends StatelessWidget {
  /// The hub to display.
  final Hub hub;

  /// Callback when the NFC button is pressed.
  final VoidCallback onNfcPressed;

  /// Callback when the delete button is pressed.
  final VoidCallback onDeletePressed;

  /// Creates a [HubCard].
  const HubCard({
    required this.hub,
    required this.onNfcPressed,
    required this.onDeletePressed,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    final bool hasNfc = hub.nfcTagId != null;

    return Container(
      margin: const EdgeInsets.only(bottom: UiConstants.space3),
      decoration: BoxDecoration(
        color: UiColors.white,
        borderRadius: BorderRadius.circular(UiConstants.radiusBase),
        boxShadow: const <BoxShadow>[
          BoxShadow(
            color: UiColors.popupShadow,
            blurRadius: 10,
            offset: Offset(0, 4),
          ),
        ],
      ),
      child: Padding(
        padding: const EdgeInsets.all(UiConstants.space4),
        child: Row(
          children: <Widget>[
            Container(
              width: 52,
              height: 52,
              decoration: BoxDecoration(
                color: UiColors.tagInProgress,
                borderRadius: BorderRadius.circular(UiConstants.radiusBase),
              ),
              child: Icon(
                hasNfc ? UiIcons.success : UiIcons.nfc,
                color: hasNfc ? UiColors.iconSuccess : UiColors.iconThird,
                size: 24,
              ),
            ),
            const SizedBox(width: UiConstants.space4),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(hub.name, style: UiTypography.body1b.textPrimary),
                  if (hub.address.isNotEmpty)
                    Padding(
                      padding: const EdgeInsets.only(top: UiConstants.space1),
                      child: Row(
                        children: <Widget>[
                          const Icon(
                            UiIcons.mapPin,
                            size: 12,
                            color: UiColors.iconThird,
                          ),
                          const SizedBox(width: UiConstants.space1),
                          Expanded(
                            child: Text(
                              hub.address,
                              style: UiTypography.footnote1r.textSecondary,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ],
                      ),
                    ),
                  if (hasNfc)
                    Padding(
                      padding: const EdgeInsets.only(top: UiConstants.space1),
                      child: Text(
                        t.client_hubs.hub_card.tag_label(id: hub.nfcTagId!),
                        style: UiTypography.footnote1b.copyWith(
                          color: UiColors.textSuccess,
                          fontFamily: 'monospace',
                        ),
                      ),
                    ),
                ],
              ),
            ),
            Row(
              children: <Widget>[
                IconButton(
                  onPressed: onDeletePressed,
                  icon: const Icon(
                    UiIcons.delete,
                    color: UiColors.destructive,
                    size: 20,
                  ),
                  padding: EdgeInsets.zero,
                  constraints: const BoxConstraints(),
                  splashRadius: 20,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
