import 'package:boilerplate/core/utils/authentication_util.dart';
import 'package:flutter/material.dart';

import '../../core/i18n/translations.g.dart';
import '../../core/styles/my_colors.dart';
import '../../core/styles/my_dimensions.dart';
import '../../core/styles/my_font.dart';

class IPMCartButton extends StatefulWidget {
  final bool initialValue;
  final Function(bool) onChanged;

  IPMCartButton({
    Key? key,
    required this.initialValue,
    required this.onChanged,
  }) : super(key: key);

  @override
  State<IPMCartButton> createState() => _IPMCartButtonState();
}

class _IPMCartButtonState extends State<IPMCartButton> {
  bool isInCart = false;

  @override
  void initState() {
    super.initState();

    isInCart = widget.initialValue;
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        AuthenticationUtil.checkHasUser(() {
          widget.onChanged(isInCart);
          setState(() {
            isInCart = !isInCart;
          });
        });
      },
      child: Row(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Icon(
            isInCart ? Icons.shopping_cart : Icons.shopping_cart_outlined,
            color: isInCart ? MyColor.orange : MyColor.grey,
            size: MyDimens.dimen14,
          ),
          SizedBox(width: MyDimens.dimen4),
          Text(
            AppLocalizations.products.add_to_cart,
            style: MyFont.regular12.copyWith(
              color: MyColor.grey,
              height: 1.8,
            ),
            textAlign: TextAlign.center,
          )
        ],
      ),
    );
  }
}
