import { DownOutlined } from "@ant-design/icons";
import { Dropdown, Menu } 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 JobsDetailChangeEstimator({ disabled, form, bodyshop }) {
  const handleClick = ({ item, key, keyPath }) => {
    const est = item.props.value;
    form.setFieldsValue(est);
  };

  const menu = (
    <div>
      <Menu onClick={handleClick}>
        {bodyshop.md_estimators.map((est, idx) => (
          <Menu.Item value={est} key={idx}>
            {`${est.est_ct_fn} ${est.est_ct_ln}`}
          </Menu.Item>
        ))}
      </Menu>
    </div>
  );

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

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