import React, { useState, useEffect } from 'react';
import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Radio, Tag, Tooltip, Tabs, notification } from 'antd';
import moment from 'moment';
import request from '../../../../../utils/request';
import apis from '../../../../../services/apis';
import { router } from 'umi';

import House from './house'
import HouseAdd from './houseAdd'
import HouseBatch from './HouseBatch'
import PreselectionRecord from './preselectionRecord'



function EditHouse(props) {
  const [tab, setTab] = useState('house')
  const [houseId, setHouseId] = useState('')

  function changeTab(e) {
    if(e.type === "preselection"){
      props.onSuccess(e)
    }
    setTab(e.type)
    if(e.type === "add"){
      setHouseId(e.houseId)
    }
  }

  return (
    <>
      <div style={{ marginTop: '20px' }}>
        { (tab === 'house' && <House salesBatchId={props.salesBatchId} buildingId={props.buildingId} onSuccess={e => changeTab(e)}/>)} 
        { (tab === 'add' && <HouseAdd salesBatchId={props.salesBatchId} buildingId={props.buildingId} houseId={houseId} onSuccess={e => changeTab(e)}/>)} 
        { (tab === 'batch' && <HouseBatch salesBatchId={props.salesBatchId} buildingId={props.buildingId} onSuccess={e => changeTab(e)}/>)} 
      </div>
    </>
  )
}

const WrappedEditHouseForm = Form.create({ name: 'editHouse' })(EditHouse);

export default WrappedEditHouseForm
