import { WeaSwitch } from "comsMobx";
import { WeaFormItem, WeaHelpfulTip, WeaSearchGroup, WeaTextarea, WeaTools } from "ecCom";

const getKey = WeaTools.getKey;
//工资单模板表格渲染函数
export const payrollFormRender = (form, condition, onChange = () => void (0), onFocus = () => void (0), smsVal) => {
  const { isFormInit } = form;
  const formParams = form.getFormParams();
  let group = [];
  isFormInit && condition && condition.map(c => {
    let items = [];
    c.items.map(fields => {
      //自定义多行文本输入框
      if (getKey(fields) === "smsSetting") {
        items.push({
          com: (
            <WeaFormItem label={`${fields.label}`} labelCol={{ span: `${fields.labelcol}` }}
                         wrapperCol={{ span: `${fields.fieldcol}` }} error={form.getError(fields)}
                         tipPosition="bottom"
            >
              <div onClick={onFocus} className="customSm-wrapper"><WeaTextarea value={smsVal}/></div>
            </WeaFormItem>),
          colSpan: 1,
          hide: fields.hide
        });
      } else {
        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={onChange}/>
              {
                fields.helpfulTitle &&
                <WeaHelpfulTip title={fields.helpfulTitle}
                               style={{ position: "absolute", right: "-20px", top: "25%" }}/>
              }
            </WeaFormItem>),
          colSpan: 1,
          hide: fields.hide
        });
      }
    });
    group.push(
      <WeaSearchGroup col={1} needTigger={true} title={c.title}
                      showGroup={c.defaultshow} items={items}
      />);
  });
  return group;
};
