import React from "react";
import { Button } from "antd";
import { WeaReqTop } from "ecCom";
import "./index.less";

export default class SlideModalTitle extends React.Component {
  componentWillMount() { // 初始化渲染页面
    this.state = {
      editable: this.props.editable
    };
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      editable: nextProps.editable
    });
  }

  render() {
    const { selectedTab, tabs, subtitle, customOperate, subItemChange, loading = false } = this.props;
    return <div className="reqTopWrapper">
      <WeaReqTop
        title={subtitle}
        buttonSpace={10}
        icon={<i className="icon-coms-fa"/>}
        iconBgcolor="#F14A2D"
        buttons={(this.props.showOperateBtn && this.state.editable && this.props.selectedTab != 1) ? [
          <Button type="primary" className="saveBtn" onClick={this.props.onSave} loading={loading}>保存</Button>
        ] : !_.isEmpty(customOperate) ? customOperate : []}
        showDropIcon={false}
        dropMenuDatas={[]}
        tabDatas={tabs || []}
        selectedKey={String(selectedTab) || ""}
        onChange={key => subItemChange(key)}
      />
    </div>;
  }
}
