import { EventBus, useEventBus } from '@/Engine/EventBus/EventBus';
import { LocalService, SessionService } from '@/Engine/Storage';
import { MessageType } from '@/Frameworks/MessageType';
import { SysStorage } from '@/Frameworks/SysStorage';
import { FuncMainState } from '@/Project/Functions/FuncMain';
import { PageContainer } from '@ant-design/pro-components';
import { Access, useAccess } from '@umijs/max';
import { Button } from 'antd';
import { useState } from 'react';

const AccessPage: React.FC<GT.IPageProps> = (props) => {
  const access = useAccess();
  console.log(props);

  const ComponentA = () => {
    return (
      <Button
        onClick={() => {
          EventBus.emit(MessageType.a, 'hahahah');
        }}
      >
        向B传递参数
      </Button>
    );
  };
  const ComponentB = () => {
    const [text, setText] = useState('');
    const func = (text: string) => {
      setText(text);
    };
    useEventBus(MessageType.a, func);
    return <Button>参数为：{text}</Button>;
  };

  return (
    <PageContainer
      ghost
      header={{
        title: '权限示例',
      }}
    >
      1231213123213123
      {/* <Access accessible={access.canSeeAdmin}>
        <Button>只有 Admin 可以看到这个按钮</Button>
      </Access> */}
      ACCESS Page
      <Button
        onClick={() => window.GT_APP.funcMain.changeState(FuncMainState.Login)}
      >
        push
      </Button>
      <Button
        onClick={() => {
          SessionService.setItem(SysStorage.token, 'token11111');
        }}
      >
        存Session地址
      </Button>
      <Button
        onClick={() => {
          LocalService.setItem(SysStorage.token, 'token11111');
        }}
      >
        存Local地址
      </Button>
      <ComponentA />
      <ComponentB />
    </PageContainer>
  );
};

export default AccessPage;
