import React, { useEffect, useState } from "react";
import { Card, Steps, Table, Tabs } from "antd";
import { PageHeaderWrapper } from "@ant-design/pro-layout";
import { createStore } from "@/hooks/moz";
import store from "./useStore";
import SelectCorrespondenceUnits from "./components/SelectCorrespondenceUnits";
import RelationshipSettings from "./components/RelationshipSettings";
import { CompanyRelationListVO } from "@/pages/finance/CompanyRelationAuth/api";

const { Column } = Table;
const { TabPane } = Tabs;

export const { Provider, useStore } = createStore(store);

function CompanyRelationCreate(props) {
  const pathParams = props.location.state || {};
  const { Step } = Steps;
  const [current, setCurrent] = useState<number>(0);
  const {
    selected,
    // loading,
    selectedRelation,
    setSelectedRelation,
    submitLoading,
    setSubmitLoading,
    // setLoading,
    companyParams,
    setCompanyParams,
  } = useStore();

  useEffect(() => {
    setCompanyParams({ ...pathParams });
  }, []);

  const rowSelection = {
    onChange: (selectedRowKeys: React.Key[], selectedRows: CompanyRelationListVO[]) => {
      setSelectedRelation([...selectedRows]);
    },
    getCheckboxProps: (record: CompanyRelationListVO) => ({
      name: String(record.compId),
    }),
  };

  return (
    <PageHeaderWrapper title="往来单位关系设置">
      <Card>
        <Steps type="navigation" current={current} className="site-navigation-steps">
          <Step title="选择往来单位" />
          <Step title="关系设置" />
        </Steps>
        <Tabs
          style={{ marginTop: 40 }}
          activeKey={String(current)}
          tabBarStyle={{ display: "hidden" }}
          renderTabBar={() => <div />}
        >
          <TabPane key="0">
            <SelectCorrespondenceUnits onNext={() => setCurrent(current + 1)} />
          </TabPane>
          <TabPane key="1">
            <RelationshipSettings onPrevious={() => setCurrent(0)} />
          </TabPane>
        </Tabs>
      </Card>
    </PageHeaderWrapper>
  );
}

export default (props) => (
  <Provider>
    <CompanyRelationCreate {...props} />
  </Provider>
);
