import { Tabbar } from "@nutui/nutui-react-taro";
import { useEffect, useState } from "react";
import { navigateTo } from "@tarojs/taro";

const TabbarCom = () => {
  const [activeIndex, setActiveIndex] = useState(0);
  useEffect(() => {
    setActiveIndex(0);
  }, []);
  return (
    <Tabbar
      fixed
      safeArea
      value={activeIndex}
      onSwitch={(value) => {
        console.log(value);
        setActiveIndex(value);
        if (value === 2) {
          navigateTo({ url: "/pages/publish/index" });
        }
      }}
    >
      <Tabbar.Item title="首页" />
      <Tabbar.Item title="消息" />
      <Tabbar.Item title="发布" />
      <Tabbar.Item title="我的" />
    </Tabbar>
  );
};

export default TabbarCom;
