import 'package:flutter/material.dart';
import 'package:flutter_pos_ecommerce/module/ecommerce/data/models/responses/discount_response_model.dart';
import '../../../../../core/assets/assets.gen.dart';
import '../../../../../core/constants/colors.dart';

class ManageDiscountCard extends StatelessWidget {
  final Discount data;
  final VoidCallback onEditTap;
  final VoidCallback onDeleteTap; // Tambahkan callback untuk onDeleteTap

  const ManageDiscountCard({
    super.key, // Ganti super.key dengan Key? key
    required this.data,
    required this.onEditTap,
    required this.onDeleteTap, // Tambahkan parameter dan assign ke field
  }); // Ganti super.key dengan key

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(8.0),
      decoration: ShapeDecoration(
        shape: RoundedRectangleBorder(
          side: const BorderSide(width: 1, color: AppColors.card),
          borderRadius: BorderRadius.circular(19),
        ),
      ),
      child: Stack(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Spacer(),
              Container(
                alignment: Alignment.center,
                padding: const EdgeInsets.all(10.0),
                margin: const EdgeInsets.only(top: 15.0),
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: AppColors.disabled.withOpacity(0.4),
                ),
                child: Text(
                  '${data.value!.replaceAll('.00', '')}%',
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w900,
                  ),
                ),
              ),
              const Spacer(),
              Center(
                child: RichText(
                  text: TextSpan(
                    text: 'Nama Promo : ',
                    children: [
                      TextSpan(
                        text: data.name,
                        style: const TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                    ],
                    style: const TextStyle(
                      fontSize: 12,
                      fontWeight: FontWeight.w400,
                      color: AppColors.black,
                    ),
                  ),
                ),
              ),
              const Spacer(),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              GestureDetector(
                onTap:
                    onDeleteTap, // Panggil onDeleteTap saat tombol delete ditekan
                child: Container(
                  padding: const EdgeInsets.all(8.0),
                  decoration: const BoxDecoration(
                    shape: BoxShape.circle,
                    color:
                        Colors.red, // Ganti warna dengan warna yang diinginkan
                  ),
                  child: const Icon(Icons.delete,
                      color: Colors.white), // Tambahkan ikon delete
                ),
              ),
              const SizedBox(
                  width: 8), // Berikan jarak antara tombol edit dan delete
              GestureDetector(
                onTap: onEditTap,
                child: Container(
                  padding: const EdgeInsets.all(8.0),
                  decoration: const BoxDecoration(
                    shape: BoxShape.circle,
                    color: AppColors.primary,
                  ),
                  child: Assets.icons.edit.svg(),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
