/*
 * Author: 黎永顺
 * name: 报表查看-左侧tab标题
 * Description:
 * Date: 2023/4/20
 */
import React, { Component } from "react";
import { WeaLocaleProvider } from "ecCom";
import { Menu } from "antd";
import * as API from "../../../apis/declare";
import { getQueryString } from "../../../util/url";

const { getLabel } = WeaLocaleProvider;

class LeftTab extends Component {
  constructor(props) {
    super(props);
    this.state = {
      reportName: "",
      selectedKeys: "",
      dataSource: []
    };
  }

  componentDidMount() {
    this.getTaxReports();
  }

  getTaxReports = () => {
    const { onChangeTab, onCollapse } = this.props;
    API.getTaxReports({ id: getQueryString("id") }).then(({ status, data: dataSource }) => {
      if (status) this.setState({
        dataSource, selectedKeys: !_.isEmpty(dataSource) ? _.head(dataSource).id + "" : ""
      }, () => {
        !_.isEmpty(this.state.dataSource) && onChangeTab(_.head(this.state.dataSource).reportType);
        onCollapse(!_.isEmpty(this.state.dataSource) && this.state.dataSource.length > 1);
      });
    });
  };

  render() {
    const { selectedKeys, dataSource } = this.state;
    const { onChangeTab } = this.props;
    const reportTypeNameMap = {
      1: getLabel(111, "综合所得"),
      2: getLabel(111, "分类所得"),
      3: getLabel(111, "非居民所得"),
      4: getLabel(111, "限售股所得")
    };
    return (
      <div className="leftTabWrapper">
        <Menu mode="inline" selectedKeys={selectedKeys}
              onClick={({ key }) => {
                this.setState({ selectedKeys: key }, () => {
                  onChangeTab(_.find(dataSource, o => String(o.id) === key).reportType, true);
                });
              }}
        >
          {
            _.map(dataSource, item => {
              const { reportType, id } = item;
              return <Menu.Item key={id + ""}>{reportTypeNameMap[reportType]}</Menu.Item>;
            })
          }
        </Menu>
      </div>
    );
  }
}

export default LeftTab;
