import { View, Button, ButtonProps, BaseEventOrig } from "@tarojs/components";

import { EBindKind } from "@/consts/enum";
interface Props {
  text?: string
  getPhoneNumber:(phone: string) => void
  bindKind: EBindKind
  contentStyle?: React.CSSProperties
}
export default function  Index({getPhoneNumber,text='授权登陆', bindKind, contentStyle}:Props){
  
  const handleGetPhoneNumber = async (
    e: BaseEventOrig<ButtonProps.onGetPhoneNumberEventDetail>
  ) => {
    const code = e.detail.code;
    if (!code) {
      return;
    }
    const res = await authBind(bindKind, code);
    if (res.data) {
      getPhoneNumber(res.data)
      return 
    }
    getPhoneNumber('')
  };

  return (
    <View className="relative primary-color-dark text-14 font-normal w-full h-full flex items-center justify-center" style={contentStyle}>
      {text}
      <Button
        openType="getPhoneNumber"
        onGetPhoneNumber={handleGetPhoneNumber}
        className="absolute left-0 top-0 right-0 bottom-0 opacity-0"
      ></Button>
    </View>
  );
};
