import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { DMS_MAP } from "../../utils/dmsUtils";
import RRPostForm from "./rr-dms-post-form";
import CdkLikePostForm from "./cdklike-dms-post-form";

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

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

/**
 * DMS Post Form component that renders the appropriate post form
 * @param mode
 * @param bodyshop
 * @param socket
 * @param job
 * @param logsRef
 * @returns {JSX.Element|null}
 * @constructor
 */
export function DmsPostForm({ mode, bodyshop, socket, job, logsRef }) {
  switch (mode) {
    case DMS_MAP.reynolds:
      return <RRPostForm bodyshop={bodyshop} socket={socket} job={job} logsRef={logsRef} />;

    // CDK (legacy /ws), Fortellis (CDK-over-WSS), and PBS share the same UI;
    // we pass mode down so the child can choose the correct event name.
    case DMS_MAP.fortellis:
    case DMS_MAP.cdk:
    case DMS_MAP.pbs:
      return <CdkLikePostForm mode={mode} bodyshop={bodyshop} socket={socket} job={job} logsRef={logsRef} />;

    default:
      return null;
  }
}
