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

const getKey = WeaTools.getKey;
const getLabel = WeaLocaleProvider.getLabel;
export const logConditions = [
  {
    items: [
      {
        conditionType: "RANGEPICKER",
        domkey: ["date"],
        fieldcol: 18,
        label: "操作时间",
        lanId: 111,
        labelcol: 6,
        value: "",
        viewAttr: 2
      },
      {
        conditionType: "INPUT",
        domkey: ["operator"],
        fieldcol: 18,
        label: "操作人",
        lanId: 17482,
        labelcol: 6,
        value: "",
        viewAttr: 2
      },
      {
        conditionType: "INPUT",
        domkey: ["targetname"],
        fieldcol: 18,
        label: "对象",
        lanId: 106,
        labelcol: 6,
        value: "",
        viewAttr: 2
      },
      {
        conditionType: "INPUT",
        domkey: ["operatetypename"],
        fieldcol: 18,
        label: "操作类型",
        lanId: 111,
        labelcol: 6,
        value: "",
        viewAttr: 2
      }
    ],
    defaultshow: true,
    title: ""
  }
];

export const renderLogSearchsForm = (form, condition, onSearch = () => void (0), onReset = () => void (0)) => {
  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}/>
            {
              getKey(fields) === "operatetypename" &&
              <div style={{ position: "absolute", right: "-148px", top: "0" }}>
                <Button type="ghost" onClick={onReset} style={{ marginRight: 10 }}>{getLabel(2022, "重置")}</Button>
                <Button type="primary" onClick={onSearch}>{getLabel(388113, "搜索")}</Button>
              </div>
            }
          </WeaFormItem>),
        colSpan: 1
      });
    });
    group.push(
      <WeaSearchGroup col={3} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items} center={false}
      />);
  });
  return group;
};
