import 'package:flutter/material.dart';

import '../../../../../../common/theme/theme.dart';
import '../../../../../../domain/printer/printer.dart';
import '../../../../../components/spaces/space.dart';

class PrinterCard extends StatelessWidget {
  final Printer printer;
  final VoidCallback? onEdit;
  final VoidCallback? onDelete;
  final VoidCallback? onTestPrint;

  const PrinterCard({
    super.key,
    required this.printer,
    this.onEdit,
    this.onDelete,
    this.onTestPrint,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(12),
      margin: const EdgeInsets.only(bottom: 16),
      decoration: BoxDecoration(
        color: AppColor.white,
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 6,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Printer icon
          Container(
            padding: const EdgeInsets.all(8),
            decoration: BoxDecoration(
              color: AppColor.disabled.withOpacity(0.3),
              borderRadius: BorderRadius.circular(8),
            ),
            child: const Icon(Icons.print_outlined),
          ),
          const SpaceWidth(12),
          // Printer info
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  printer.name,
                  style: AppStyle.lg.copyWith(
                    fontWeight: FontWeight.w600,
                    color: AppColor.primary,
                  ),
                ),
                const SpaceHeight(4),
                Text(
                  "${printer.paper} mm | ${printer.type}",
                  style: AppStyle.sm,
                ),
                const SpaceHeight(2),
                Text(
                  printer.address,
                  style: AppStyle.sm.copyWith(color: AppColor.textSecondary),
                ),
              ],
            ),
          ),
          // Popup menu
          PopupMenuButton<String>(
            color: AppColor.white,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(12),
            ),
            onSelected: (value) {
              switch (value) {
                case 'edit':
                  onEdit?.call();
                  break;
                case 'delete':
                  onDelete?.call();
                  break;
                case 'test':
                  onTestPrint?.call();
                  break;
              }
            },
            itemBuilder: (context) => [
              PopupMenuItem(
                value: 'edit',
                child: Text('Edit', style: AppStyle.md),
              ),
              PopupMenuItem(
                value: 'delete',
                child: Text('Hapus', style: AppStyle.md),
              ),
              PopupMenuItem(
                value: 'test',
                child: Text('Test Print', style: AppStyle.md),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
