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

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

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

  const menu = {
    items: bodyshop.md_estimators.map((est, idx) => ({
      key: idx,
      label: `${est.est_ct_fn} ${est.est_ct_ln}`,
      value: est
    })),
    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)(JobsDetailChangeEstimator);
