import React from "react";
import { WeaSwitch } from "comsMobx";
import { WeaButtonIcon, WeaFormItem, WeaLocaleProvider, WeaSearchGroup, WeaTools } from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;
const getKey = WeaTools.getKey;
export const payrollTempNormalSetForm = (form, condition, background, onChange = () => void (0), insertVar = () => void (0)) => {
  const { isFormInit } = form;
  const formParams = form.getFormParams();
  const img1Props = {
    src: background,
    width: 100,
    height: 100
  };
  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"
          >

            {
              (getKey(fields) === "background" && background) ?
                <React.Fragment>
                  <WeaButtonIcon buttonType="del" type="primary" onClick={() => insertVar("background", "")}/>
                  <img {...img1Props} alt=""/>
                </React.Fragment>
                :
                <WeaSwitch
                  fieldConfig={fields}
                  form={form}
                  formParams={formParams}
                  onChange={onChange}
                />
            }
            {
              getKey(fields) === "theme" && fields.viewAttr === 3 &&
              <div className="sft-variables">
                <span className="sftv-tip">{getLabel(500143, "插入变量")}：</span>
                <a className="sftv-item"
                   onClick={() => insertVar("theme", "${companyName}")}>{getLabel(1976, "公司名称")}</a>
                <a className="sftv-item"
                   onClick={() => insertVar("theme", "${salaryYear}")}>{getLabel(111, "薪资所属年")}</a>
                <a className="sftv-item"
                   onClick={() => insertVar("theme", "${salaryMonth}")}>{getLabel(542604, "薪资所属月")}</a>
              </div>
            }
          </WeaFormItem>),
        colSpan: 1,
        hide: fields.hide
      });
    });
    group.push(
      <WeaSearchGroup
        col={1}
        needTigger={true}
        title={c.title}
        showGroup={c.defaultshow}
        items={items}
        center={false}
      />);
  });
  return group;
};
