import { MailOutlined, PrinterOutlined } from "@ant-design/icons";
import { Space, Spin } from "antd";
import React, { useState } from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { setEmailOptions } from "../../redux/email/email.actions";
import { GenerateDocument } from "../../utils/RenderTemplate";
import { TemplateList } from "../../utils/TemplateConstants";

const mapStateToProps = createStructuredSelector({});

const mapDispatchToProps = (dispatch) => ({
  setEmailOptions: (e) => dispatch(setEmailOptions(e)),
});

export function ChatPrintButton({ conversation }) {
  const [loading, setLoading] = useState(false);

  return (
    <Space wrap>
      <PrinterOutlined
        onClick={() => {
          setLoading(true);
          GenerateDocument(
            {
              name: TemplateList("messaging").conversation_list.key,
              variables: { id: conversation.id },
            },
            {
              subject: TemplateList("messaging").conversation_list.subject,
            },
            "p",
            conversation.id
          );
          setLoading(false);
        }}
      />
      <MailOutlined
        onClick={() => {
          setLoading(true);
          GenerateDocument(
            {
              name: TemplateList("messaging").conversation_list.key,
              variables: { id: conversation.id },
            },
            {
              subject: TemplateList("messaging").conversation_list.subject,
            },
            "e",
            conversation.id
          );
          setLoading(false);
        }}
      />
      {loading && <Spin />}
    </Space>
  );
}
export default connect(mapStateToProps, mapDispatchToProps)(ChatPrintButton);
