part of 'dialog.dart';

class VariantDialog extends StatelessWidget {
  final Product product;
  const VariantDialog({super.key, required this.product});

  @override
  Widget build(BuildContext context) {
    return CustomModalDialog(
      title: 'Pilih Varian',
      subtitle: 'Silahkan pilih varian yang sesuai',
      minWidth: context.deviceWidth * 0.4,
      contentPadding: const EdgeInsets.all(16),
      child: Wrap(
        spacing: 12,
        runSpacing: 12,
        crossAxisAlignment: WrapCrossAlignment.start,
        runAlignment: WrapAlignment.start,
        alignment: WrapAlignment.start,
        children: product.variants.map((variant) {
          return GestureDetector(
            onTap: () {
              // Aksi saat varian dipilih
              context.maybePop();
              context.read<CheckoutFormBloc>().add(
                CheckoutFormEvent.addItem(product, variant),
              );
            },
            child: Container(
              width: (context.deviceWidth * 0.4 - 12 - 32) / 2 - 6, // 2 per row
              padding: const EdgeInsets.all(12),
              decoration: BoxDecoration(
                border: Border.all(color: Colors.grey.shade300),
                borderRadius: BorderRadius.circular(12),
                color: Colors.white,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    variant.name,
                    style: const TextStyle(fontWeight: FontWeight.bold),
                  ),
                  const SizedBox(height: 4),
                  Text(
                    variant.priceModifier.currencyFormatRpV2,
                    style: const TextStyle(color: AppColor.black),
                  ),
                ],
              ),
            ),
          );
        }).toList(),
      ),
    );
  }
}
