import { ActionType, ApprovalList } from "@/components";
import { useShareAppMessage } from "@tarojs/taro";
import { useRef, useState } from "react";
import hocAuth from "@/hocs/auth";
import { CommonComponent } from "@/types/typings";
import audit from "@/constant/audit";

export default hocAuth(function Page(props: CommonComponent) {
  const { shareOptions } = props;

  const [state, setState] =
    useState<BusinessAPI.AuditPageQry["state"]>("WAITING_AUDIT");

  const actionRef = useRef<ActionType>();

  useShareAppMessage((res) => {
    console.log("useShareAppMessage1", res, shareOptions);
    // 如果是按钮触发的转发，使用默认配置
    if (res.from === "button") {
      return shareOptions;
    }
    // 页面转发使用设置的配置
    return {};
  });

  return (
    <ApprovalList
      actionRef={actionRef}
      toolbar={{
        tabs: {
          activeKey: "state",
          defaultActiveKey: state!,
          items: audit.approvalStateList,
          onChange: (item) => {
            setState(item as BusinessAPI.AuditPageQry["state"]);
            actionRef.current?.reload();
          },
        },
      }}
      params={{
        state: state,
        type: "BOSS_AUDIT",
      }}
    />
  );
});
