/* eslint-disable no-undef */

/**
 * @return {string}
 */

import { Button, Popconfirm } from 'antd'
import EditModal from '../../components/Edit/EditModal';
import {message} from "antd/lib/index";

import FormPage from '../../components/FormPage'
import FormQueryShowPage from '../../components/PageConfig/Common/FormQueryShowPage';
import FormRelationShowPage from '../../components/PageConfig/Common/FormRelationShowPage';
import TableShowPage from '../../components/PageConfig/Table/TableShowPage';
import EditShowPage from '../../components/PageConfig/Edit/EditShowPage';
import EditFormShowPage from '../../components/PageConfig/Edit/EditFormShowPage';
import TreeShowPage from '../../components/PageConfig/Tree/TreeShowPage';
import CustomEditPage from '../../components/PageConfig/Custom/CustomEditPage';
import ChartShowPage from '../../components/PageConfig/Chart/ChartShowPage';




export default {
  colOp: ({record, onLoadData,onLoadAllData, onHandleDel}) => {
    return <div className='btn_margin'>
      <EditModal id={record.ID} title="编辑" onSave={onLoadData} formCode="PF002">
        <Button type="primary" size="small" icon="tool" title="编辑" />
      </EditModal>
      <Popconfirm title="是否确定删除?" onConfirm={() => onHandleDel(record.ID)}>
        <Button type="danger" size="small" icon="delete" title="删除" />
      </Popconfirm>
    </div>;
  },
  // colOp1: (e) => {
  //   return <p>xxxx</p>;
  // },
  btnAdd: () => {
  },
  colPageConfig:({record, onLoadData, onLoadAllData, onHandleDel})=> {
    if (record.FORM_TYPE == 99) {
      return <CustomEditPage formId={record.ID} orgId={record.ORG_ID}>
        <Button type="primary" size="small" icon="setting" title="页面配置" />
      </CustomEditPage>
    }
    else if (record.FORM_TYPE == 1) {
      return <EditShowPage formId={record.ID} orgId={record.ORG_ID}>
        <Button type="primary" size="small" icon="setting" title="页面配置" />
      </EditShowPage>
    }
    else if (record.FORM_TYPE == 2) {
      return <div>
        <FormQueryShowPage formId={record.ID} orgId={record.ORG_ID}>
          <Button icon="setting" size="small" title="查询配置"/>
        </FormQueryShowPage>
        <TreeShowPage formId={record.ID} orgId={record.ORG_ID}>
          <Button icon="switcher" size="small" title="树配置"/>
        </TreeShowPage>
        <EditShowPage formId={record.ID} orgId={record.ORG_ID}>
          <Button type="primary" size="small" icon="setting" title="页面配置"/>
        </EditShowPage>
      </div>
    }
    else if (record.FORM_TYPE == 3) {
      return <div>
        <FormQueryShowPage formId={record.ID} orgId={record.ORG_ID}>
          <Button icon="search" size="small" title="查询配置"/>
        </FormQueryShowPage>
        <ChartShowPage formId={record.ID} orgId={record.ORG_ID} key={'chart'+record.ID}>
          <Button type="primary" size="small" icon="setting" title="图表配置"/>
        </ChartShowPage>
      </div>
    }
    return <div>
      <FormQueryShowPage formId={record.ID} orgId={record.ORG_ID}>
        <Button icon="search" size="small" title="查询配置"/>
      </FormQueryShowPage>
      <TableShowPage formId={record.ID} orgId={record.ORG_ID}>
        <Button icon="table" size="small" title="列表配置"/>
      </TableShowPage>
    </div>;
  },
  onLoadParam:({loadParam,parantRow,tableIndex})=>{

  },

  btnFormConfigSql:({record,close,loadData,custom,dispatch,getSelectedRecords})=> {
    const closeF=()=>{
      close();
      loadData();
    };
    const regClick= async function() {
      var selectRecords=getSelectedRecords();
      let ids=[];
      if(selectRecords){
        selectRecords.map(item=>{
          ids.push(item.ID);
        });
      };
      await dispatch({
        type: 'custom/save',
        payload: {
          formConfigSqlClick: true,
          formConfigSqlSelectIds:ids.join(',')
        },
      });
    };
    const data={
      close:closeF,
      formConfigSqlClick:custom.formConfigSqlClick,
      ids:custom.formConfigSqlSelectIds,
    };
    return {
      content: <FormPage formCode={'PF015'} data={data}/>,
      click: regClick
    }
  },
  btnEntitySql:({record,close,loadData,custom,dispatch,getSelectedRecords})=> {
    const closeF=()=>{
      close();
      loadData();
    };
    const regClick= async function() {
      await dispatch({
        type: 'custom/save',
        payload: {
          entitySqlClick: true,
        },
      });
    };
    const data={
      close:closeF,
    };
    return {
      content: <FormPage formCode={'PF017'} data={data}/>,
      click: regClick
    }
  },

  btnQueryShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==0&&record.FORM_TYPE!==2&&record.FORM_TYPE!==3&&record.FORM_TYPE!==6&&record.FORM_TYPE!==8&&record.FORM_TYPE!==99;
    return {
      content: <FormQueryShowPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID} >
        <Button icon={"search"} size={"small"} title={"查询配置"} disabled={disabled}/>
      </FormQueryShowPage>,
    }
  },
  btnTableShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==0&&record.FORM_TYPE!==8&&record.FORM_TYPE!==99;
    return {
      content: <TableShowPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID}>
        <Button icon={"table"} size={"small"} title={"列表配置"}  disabled={disabled}/>
      </TableShowPage>,
    }
  },
  btnEditShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==1&&record.FORM_TYPE!==99&&record.FORM_TYPE!==2&&record.FORM_TYPE!==6;
    return {
      content:  <EditShowPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID}>
        <Button  size={"small"} icon={"setting"} title={"编辑配置"} disabled={disabled} />
      </EditShowPage>,
    }
  },
  btnTreeShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==2&&record.FORM_TYPE!==99&&record.FORM_TYPE!==6;
    return {
      content:  <TreeShowPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID}>
        <Button icon={"switcher"} size={"small"} title={"树配置"} disabled={disabled}/>
      </TreeShowPage>,
    }
  },
  btnChartShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==3&&record.FORM_TYPE!==99;
    return {
      content:  <ChartShowPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID}>
        <Button  size={"small"} icon={"pie-chart"} title={"图表配置"} disabled={disabled}/>
      </ChartShowPage>,
    }
  },
  btnCustomShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==99;
    return {
      content:   <CustomEditPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID}>
        <Button  size={"small"} icon={"snippets"} title={"自定义配置"} disabled={disabled} />
      </CustomEditPage>,
    }
  },
  btnFormShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==7;
    return {
      content: <EditFormShowPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID}>
        <Button  size={"small"} icon={"form"} title={"组合配置"} disabled={disabled} />
      </EditFormShowPage>,
    }
  },
  btnRelationShowPage:({record,btn})=> {
    const disabled=record.FORM_TYPE!==0&&record.FORM_TYPE!==2&&record.FORM_TYPE!==3&&record.FORM_TYPE!==6&&record.FORM_TYPE!==99;
    return {
      content: <FormRelationShowPage formId={record.ID} orgId={record.ORG_ID} key={record?(record.ID+btn.ID):btn.ID} >
        <Button icon={"link"} size={"small"} title={"权限关联表单"} disabled={disabled}/>
      </FormRelationShowPage>,
    }
  },
}
