import React from "react";
import { inject, observer } from "mobx-react";
import { toJS } from "mobx";
import { Button, Menu, Tabs, TopTitle, Tree } from "antd";
import {
  WeaLocaleProvider,
  WeaLeftRightLayout,
  WeaTop,
  WeaTab,
  WeaRightMenu,
  WeaFormItem,
  WeaTools,
  WeaSearchGroup
} from "ecCom";

import { WeaTableNew, WeaSwitch } from "comsMobx";

const { WeaTable } = WeaTableNew;
const { getKey } = WeaTools;

import * as IntegrationUtil from "../../util/IntegrationUtil";
const getFormSearchs = (form, datas, needTigger = true, lableCol, fieldcol) => {
  const {isFormInit} = form;
  let group = [];
  const formParams = form.getFormParams();
  isFormInit && datas && datas.map(c =>{
    let items = [];
    c.items.map(fields => {
      items.push({
        com:(
          <WeaFormItem
            label={`${fields.label}`}
            labelCol={{span: lableCol ? lableCol : `${fields.labelcol}`}}
            wrapperCol={{span: fieldcol ? fieldcol : `${fields.fieldcol}`}}
            error={form.getError(fields)}
            tipPosition="bottom"
          >
            <WeaSwitch fieldConfig={fields} form={form} formParams={formParams}/>
          </WeaFormItem>),
        colSpan: 1,
        hide: form.isHide(fields, (keys, allParams) => {
          let bool = false;
          getKey(fields) === 'clusterNodes' && allParams.is_cluster != '1' && (bool = true);
          return bool;
        })
      })
    });
    if(needTigger){
      group.push(<WeaSearchGroup center col={1} needTigger={needTigger} title={c.title} showGroup={c.defaultshow} items={items}/>)
    }else {
      group.push(<WeaSearchGroup center col={1} needTigger={needTigger} showGroup={c.defaultshow} items={items}/>)
    }
  });
  return group;
}

const getLabel = WeaLocaleProvider.getLabel;
@inject("cas")
@observer
export default class Cas extends React.Component {
  componentDidMount() {
    const { cas } = this.props;
    cas.doInit();
  }

  onRightMenuClick = (type, recordId) => {
    const { cas } = this.props;
    const { save } = cas;
    switch (type) {
      case "save":
        save();
        break;
    }
  };

  getBtns = () => {
    const { cas } = this.props;
    let btns = [];
    btns = [
      <Button
        type="primary"
        onClick={() => {
          {
            // this.add(1)
            this.onRightMenuClick("save");
          }
        }}
      >
        {getLabel("31691,82986", "保存")}
      </Button>,
      <Button
        onClick={() => {
          {
            // this.add(3)
            this.onRightMenuClick("test");
          }
        }}
      >
        {getLabel("31691,82988", "完成")}
      </Button>
    ];
    return btns;
  };

  getRightMenu() {
    const { imrtx } = this.props;
    // const { selectedKey, rightMenus, rightMenus1 } = toJS(
    //   workflowFlowStore.status
    // );
    let btnArr = [];

    return btnArr;
  }

  render() {
    const { cas } = this.props;
    const { newBaseForm, status } = cas;
    const { newBaseFormFields } = toJS(status);
    return (
      <div>
        <WeaTop
          title={getLabel(131795, "CAS集成")}
          icon={<i className={IntegrationUtil.GeneralTitleColor.icon} />}
          iconBgcolor={IntegrationUtil.GeneralTitleColor.iconBgcolor}
          buttons={this.getBtns()}
          showDropIcon={true}
          dropMenuDatas={this.getRightMenu()}
          dropMenuProps={{
            collectParams: {
              favname: `${getLabel(131795, "CAS集成")}`,
              favouritetype: 1,
              objid: 0,
              link: "wui/engine.html#/inteengine/imrtx",
              importantlevel: 1
            }
          }}
        />
        {getFormSearchs(newBaseForm, newBaseFormFields)}
      </div>
    );
  }
}
