import { useShareAppMessage } from '@tarojs/taro';

import { Tabs } from '@taroify/core';
import { useState } from 'react';

import PartnerIntro from '@/components/partner-intro';
import PartnerInviteList from '@/components/partner-invite-list';
import PartnerProfit from '@/components/partner-profit';
import useInviteCode from '@/hooks/use-invite-code';
import { getCommonShareMessage } from '@/utils/share';
import './index.less';

const PREFIX = 'partner';

export default function Partner() {
  const inviteCode = useInviteCode();
  const [tab, setTab] = useState<number>(0);
  const handleChange = v => {
    setTab(v);
  };
  useShareAppMessage(() => {
    console.log('Partner inviteCode', inviteCode);
    return getCommonShareMessage({ useCapture: false, inviteCode });
  });

  return (
    <div className={PREFIX}>
      <Tabs className={`${PREFIX}__tabs`} value={tab} onChange={handleChange}>
        <Tabs.TabPane value={0} title="简介">
          <PartnerIntro />
        </Tabs.TabPane>
        <Tabs.TabPane value={1} title="邀请名单">
          <PartnerInviteList refreshDisabled={tab !== 1} visible={tab === 1} />
        </Tabs.TabPane>
        <Tabs.TabPane value={2} title="我的收益">
          <PartnerProfit />
        </Tabs.TabPane>
      </Tabs>
    </div>
  );
}
