import { DownOutlined } from "@ant-design/icons";
import { Dropdown, Menu } from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";

const mapStateToProps = createStructuredSelector({
  //currentUser: selectCurrentUser
  bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
});

export function NotesPresetButton({ bodyshop, form }) {
  const { t } = useTranslation();

  const handleSelect = (item) => {
    form.setFieldsValue({ text: item.text });
  };

  const menu = (
    <Menu
      style={{
        columnCount: Math.floor(bodyshop.md_notes_presets.length / 10) + 1,
      }}
    >
      {bodyshop.md_notes_presets.map((i, idx) => (
        <Menu.Item
          onClick={() => handleSelect(i)}
          key={idx}
          style={{ breakInside: "avoid" }}
        >
          {i.label}
        </Menu.Item>
      ))}
    </Menu>
  );

  return (
    <div>
      <Dropdown trigger={["click"]} overlay={menu}>
        <a
          className="ant-dropdown-link"
          href="# "
          onClick={(e) => e.preventDefault()}
        >
          {t("messaging.labels.presets")} <DownOutlined />
        </a>
      </Dropdown>
    </div>
  );
}

export default connect(mapStateToProps, mapDispatchToProps)(NotesPresetButton);
