import 'package:flutter/material.dart';

import '../../../models/lookup.dart';
import '../../app_style/colors.dart';
import '../../app_style/sizing.dart';

class FilterItem extends StatelessWidget {
  final bool isSelected;
  final Lookup? status;
  final VoidCallback onSelected;

  const FilterItem({
    Key? key,
    this.status,
    required this.isSelected,
    required this.onSelected,
  }) : super(key: key);

  Color getStatusColor() {
    switch (status?.id) {
      case 0:
        return AColors.green;
      case 4:
        return AColors.deepRed;
      case 6:
        return AColors.green;
      case 5:
        return AColors.orange;
      case 8:
        return AColors.green;
      case 9:
        return AColors.orange;
      default:
        return AColors.grey;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Opacity(
      opacity: isSelected ? 1 : .5,
      child: SizedBox(
        height: 30,
        child: ElevatedButton(
          style: ElevatedButton.styleFrom(
            padding: const EdgeInsets.symmetric(horizontal: 8),
            backgroundColor: getStatusColor(),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(
                AppStyle.getBorderRadius(context),
              ),
            ),
          ),
          onPressed: onSelected,
          child: Text(
            status?.label ?? "",
            style: Theme.of(context).textTheme.bodyLarge?.copyWith(
                  color: getStatusColor().computeLuminance() > 0.5 ? AColors.black : Colors.white,
                ),
            textScaleFactor: AppStyle.getScaleFactor(context),
          ),
        ),
      ),
    );
  }
}
