import { View, Text, Image, Button, Icon } from "@tarojs/components";
import { useLoad } from "@tarojs/taro";
import Taro from "@tarojs/taro";
import {
  AtAvatar,
  AtTag,
  AtIcon,
  AtTabBar,
  AtButton,
  AtAccordion,
  AtList,
  AtListItem,
  AtSteps,
  AtForm,
  AtInput,
  AtToast,
  AtMessage,
} from "taro-ui";
import "./index.scss";
import beijing from "@/images/city/beijing.jpg";
import guangzhou from "@/images/city/guangzhou.jpg";
import shanghai from "@/images/city/shanghai.jpg";
import shenzhen from "@/images/city/shenzhen.jpg";
import touxiang from "@/images/index/touxiang.jpg";
import TabbarCom from "@/componments/TabbarCom";
import { useEffect, useState } from "react";
import { set } from "lodash";
const KeywordJoin = () => {
  const [current, setcurrent] = useState(0);
  const [value, setvalue] = useState(null);
  const [disabled, setdisabled] = useState(false);
  const [btntext, setbtntext] = useState('立即加入');


  const [localuserInfo, setlocaluserInfo] = useState(
    Taro.getStorageSync("userInfo")
  );

  // 获取用户标识符
  useEffect(() => {
    // 获取路由参数
    const params = Taro.getCurrentInstance().router.params;
    console.log("params", params);
    // const [wxid, openId] = params;

    if (params.wxid) {
      setuserInfo({
        wxid: params?.wxid, //个人号wxid
        // openId: params?.openId, //小程序openid
      });
      // 本地存储

      try {
        Taro.setStorageSync("wxid", params?.wxid ?? "");
      } catch (e) {}
    }
  }, []);

  // useEffect(() => {
  //   // 更新分享-minipro
  //   Taro.updateShareMenu({
  //     withShareTicket: true,
  //     success() {},
  //   });

  //   // 显示分享按钮-minipro
  //   Taro.showShareMenu({
  //     withShareTicket: true,
  //     // showShareItems:true,
  //   });

  // }, []);

  const handleClick = (text, type) => {
    Taro.atMessage({
      message: text,
      type: type,
    });
  };

  return (
    <View className="KeywordJoin">
      {/* 步骤栏 */}
      {/* <AtSteps
        items={[
          {
            title: "人群公告",
            // desc: "这里是额外的信息，最多两行",
            // status: "success",
          },
          {
            title: "声明",
            // desc: "这里是额外的信息，最多两行",
          },
          {
            title: "再次确认",
            // desc: "这里是额外的信息，最多两行",
            // status: "error",
          },
        ]}
        current={current}
        onChange={(target) => {
          console.log("target", target);
          setcurrent(target);
        }}
      /> */}

      <View className="at-article">
        {/* H1文章标题 */}
        <View className="at-article__h1">欢迎加入微信群</View>
        {/* <View className="at-article__info">
          2024-03-24&nbsp;&nbsp;&nbsp;异度星球
        </View> */}

        {/* 内容区域 */}
        <View className="at-article__content">
          <View className="at-article__section">
            <Image
              style={{
                width: "200px",
                height: "200px",
                background: " #fff",
                borderRadius: "10px",
              }}
              className="at-article__img"
              src={touxiang}
              mode="widthFix"
            />
            {/* 二级标题 */}
            {/* <View className="at-article__h2">这是二级标题</View> */}
            {/* 三级标题 */}
            <View className="at-article__h3">群公告</View>
            {/* 文本段落 */}
            <View className="at-article__p">
              交流自由职业/副业,数字游民等话题
            </View>
            <View className="at-article__p">请不要打广告</View>
          </View>
        </View>
      </View>
      <AtMessage />
      <AtButton
        type="primary"
        className="jsonWechatBtn"
        disabled={disabled}
        onClick={() => {
          // 通过hook加入微信群邀请
          //发起网络请求
          Taro.request({
            // url: "http://127.0.0.1:28369/joingroup",
            url: "https://kunpeng.hackrobot.cn/joingroup",
            data: {
              wxid: localuserInfo?.wxid ?? null, //debug eric 的wxid
            },
            success: function (resUser) {
              console.log("resUser--", resUser);
              console.log("加入微信群成功");
              if (resUser?.data?.success == "fail") {
                //已经在群聊中
                handleClick("已经在群聊中", "warning");
                setbtntext("已经在群聊中")

              } else if (resUser?.data?.success == "ok") {
                // 发送群聊邀请
                handleClick("已发送群聊邀请", "warning");
                setbtntext("已发送群聊邀请")
              }
              setdisabled(true);
              
            },
          });
        }}
      >
        {btntext}
      </AtButton>
    </View>
  );
};

export default KeywordJoin;
