import React from "react";
import { WeaFormItem, WeaHelpfulTip, WeaSearchGroup } from "ecCom";
import { WeaSwitch } from "comsMobx";

export const renderSalaryFilesForm = (form, condition, setHasBeenModify) => {
  const { isFormInit } = form;
  const formParams = form.getFormParams();
  let group = [];
  isFormInit && condition && condition.map(c => {
    let items = [];
    c.items.map(fields => {
      items.push({
        com: (
          <WeaFormItem
            label={`${fields.label}`} labelCol={{ span: `${fields.labelcol}` }}
            wrapperCol={{ span: `${fields.fieldcol}` }} error={form.getError(fields)}
            tipPosition="bottom"
          >
            <WeaSwitch fieldConfig={fields} form={form} formParams={formParams}
                       onChange={() => setHasBeenModify(true)}/>
          </WeaFormItem>),
        colSpan: 1,
        hide: fields.hide
      });
    });
    !_.isEmpty(items) && group.push(
      <WeaSearchGroup col={c.col} needTigger={true} showGroup={c.defaultshow} items={items} center={false}
                      className={c.col === 3 ? "basic-salary-file-wrapper" : (c.col === 2 || c.col === 1) ? "twoColumns-salary-file-wrapper" : ""}
                      title={
                        <span>
                          <span>{c.title}</span>
                          {
                            c.titleHelpful &&
                            <WeaHelpfulTip width={200} title={c.titleHelpful} placement="topLeft"
                                           style={{ marginLeft: 8 }}/>
                          }
                      </span>
                      }
      />);
  });
  return group;
};
