import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sigap/src/utils/constants/colors.dart';
import 'package:sigap/src/utils/popups/loaders.dart';

class LikeButton extends StatefulWidget {
  final String postId;

  const LikeButton({super.key, required this.postId});

  @override
  LikeButtonState createState() => LikeButtonState();
}

class LikeButtonState extends State<LikeButton> {
  bool isLiked = false; // Status awal tombol like

  void toggleLike() async {
    bool newIsLiked = !isLiked; // Ubah status like sementara

    try {
      // Panggil API untuk like atau unlike

      // Jika berhasil, baru ubah status like
      setState(() {
        isLiked = newIsLiked;
      });
    } catch (e) {
      TLoaders.errorSnackBar(title: 'Error', message: e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return IconButton(
      icon: Icon(
        isLiked ? CupertinoIcons.heart_fill : CupertinoIcons.heart,
        color: isLiked ? TColors.primary : Colors.grey,
      ),
      onPressed: toggleLike,
    );
  }
}
