"use client";
import { useState } from 'react';
import { MdOutlineDone } from "react-icons/md";
import { MdContentCopy } from 'react-icons/md';
import { GrPowerReset } from 'react-icons/gr';

const MessageOptions = ({ message, regenerateMessage }) => {
  const [icon, setIcon] = useState(<MdContentCopy />);

  const handleCopy = () => {
    if (message.role === 'assistant') { // Ensure only assistant messages are copied
      navigator.clipboard.writeText(message.content);
      setIcon(<MdOutlineDone />);

      setTimeout(() => {
        setIcon(<MdContentCopy />);
      }, 1000);
    }
  };

  return (
    <div className="message-options">
      <button onClick={handleCopy}>{icon}</button>
      <button onClick={() => regenerateMessage(message)}><GrPowerReset /></button>
    </div>
  );
};

export default MessageOptions;

