import React,{ useState,useEffect,useRef } from 'react';

import {situationList} from "@/api/situation.js";
// // import {getOutpatientList} from "@/api/checkCondition.js";
import { Steps, Button, message } from 'antd';

// import ModalWrap from '@/components/Modal/modal.js';
import './createFlow.less';
import SelectSituation from '../selectSituation/selectSituation';
import Condition from '../condition/condition';

const { Step } = Steps;

const steps = [
    {
      title: '主题',
      content: 'theme',
      tip:'请选择主题！'
    },
    {
      title: '条件',
      content: 'filterCondition',
      tip:'请选择追踪条件！'
    },
    {
      title: '查核组',
      content: 'Last-content',
    },
    {
        title: '地图',
        content: 'Last-content',
    },
    {
        title: '计划',
        content: 'Last-content',
    },
    {
        title: '预览',
        content: 'Last-content',
    },
];

const CreateFlow = ()=>{

    const [current,set_current] = useState(0);
    const [state,set_state] = useState({
        depType:1,//门急诊类型 1-门诊 2-急诊
        isEdit:false, //是否为编辑模式
    });

    // const getSituationList = async ()=>{
    //     let data = await situationList();
        
    //     set_situationArr(data.data.data);
    //     console.log({data});
    // }

    // useEffect(()=>{
    //     getSituationList();
    // },[]);

    const updateCreateFlowState=(stateObj)=>{
        console.log('收到子组件的更新',stateObj);
        const {current,state} = stateObj;
        if(state)set_state({...state,...stateObj});
        if(current)set_current(current);
    }

    const getCreateFlowState = ()=>{
        return state;
    }

    const next=()=>{
        // selectSituationObj&&selectSituationObj.current.selectThemeHandle();
        if(state[steps[current].content]){ //选择主题
            set_current(prev=>prev+1);
        }else if(state[steps[current].content]){ //选择条件
            set_current(prev=>prev+1);
        }else{
            message.warning(steps[current].tip)
        }
    }
    
    const prev=()=>{
        set_current(prev=>prev-1);
    }

    return (
        <div className="situationListMod">
               <div className="content">
                    <Steps className="steps" current={current}>
                            {steps.map(item => (
                                <Step key={item.title} title={item.title} />
                            ))}
                    </Steps>
                    {
                        current==0&&<div style={{width:'80%'}}>
                                <SelectSituation   updateCreateFlowState={updateCreateFlowState} getCreateFlowState={getCreateFlowState} />
                        </div>
                    }
                    {
                        current==1&&<div style={{width:'80%'}}>
                                <Condition   updateCreateFlowState={updateCreateFlowState}  getCreateFlowState={getCreateFlowState}/>
                        </div>
                    }
               </div>


               <div className="bottomBtnGroup">
               {current > 0 && (
                    <Button className="bottomBtn"  size="large" style={{ marginLeft: 8 }} onClick={() =>prev()}>
                     上一步
                    </Button>
                )}
                {current < steps.length - 1 && (
                    <Button className="bottomBtn" size="large" type="primary" onClick={() =>next()}>
                      下一步
                    </Button>
                )}
                {current === steps.length - 1 && (
                    <Button className="bottomBtn"  size="large" type="primary" onClick={() => message.success('Processing complete!')}>
                       确定
                    </Button>
                )}
                
               </div>
        </div>
    )
}


export default CreateFlow;


