import 'package:agrilink_vocpro/core/constant/app_color.dart';
import 'package:agrilink_vocpro/core/constant/app_theme.dart';
import 'package:agrilink_vocpro/core/state/result_state.dart';
import 'package:agrilink_vocpro/features/control/provider/control_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

class PumpStatusWidget extends StatelessWidget {
  const PumpStatusWidget({
    super.key,
    required this.title,
    required this.subtitle,
    required this.isActive,
    required this.onTap,
  });

  final String title;
  final String subtitle;
  final bool isActive;
  final Function() onTap;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100.h,
      padding: EdgeInsets.all(16.r),
      margin: EdgeInsets.symmetric(horizontal: 16.r),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16.r),
        boxShadow: [
          BoxShadow(
            color: isActive
                ? AppColor.secondary.withValues(alpha: 0.2)
                : Colors.grey.withValues(alpha: 0.2),
            spreadRadius: 1.r,
            blurRadius: 16.r,
            offset: Offset(0, 12.r),
          ),
        ],
      ),
      child: Row(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(title, style: AppTheme.labelMedium),
              Text(subtitle, style: AppTheme.labelSmall),
            ],
          ),
          Spacer(),
          Consumer<ControlProvider>(
            builder: (context, provider, child) {
              switch (provider.relayState) {
                case ResultState.loading:
                  return Image.asset(
                    'assets/images/water_pump.png',
                    width: 80.r,
                    color: AppColor.textDisable,
                  );
                default:
                  return Image.asset(
                    'assets/images/water_pump.png',
                    width: 80.r,
                    color: isActive ? AppColor.secondary : AppColor.textDisable,
                  );
              }
            },
          )
        ],
      ),
    );
  }
}
