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

const mapStateToProps = createStructuredSelector({
  bodyshop: selectBodyshop
});

export function JobsDetailChangeFilehandler({ disabled, form, bodyshop }) {
  const handleClick = ({ item, key, keyPath }) => {
    const est = item.props.value;
    form.setFieldsValue(est);
  };

  const menu = {
    items: bodyshop.md_filehandlers.map((est, idx) => ({
      key: idx,
      label: `${est.ins_ct_fn} ${est.ins_ct_ln}`,
      value: est,
      style: { breakInside: "avoid" }
    })),
    style: {
      columnCount: Math.floor(bodyshop.md_filehandlers.length / 10) + 1
    },
    onClick: handleClick
  };

  return (
    <Dropdown menu={menu} disabled={disabled}>
      <a className="ant-dropdown-link" href=" #" onClick={(e) => e.preventDefault()}>
        <DownOutlined />
      </a>
    </Dropdown>
  );
}

export default connect(mapStateToProps, null)(JobsDetailChangeFilehandler);
