//身份证校验
export function identityCodeValid(code:string) {
  let m = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/
  return m.test(code)
}

// 手机号校验
export function isPoneAvailable(poneInput:string) {
  var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  if (!myreg.test(poneInput)) {
    return false;
  } else {
    return true;
  }
}
// 身份证号获取出生年月日
export function getBirthdatByIdNo(iIdNo:string) {
  var tmpStr = "";
  iIdNo = iIdNo.replace(/^\s+|\s+$/g, "");

  if (iIdNo.length == 15) {
    tmpStr = iIdNo.substring(6, 12);
    tmpStr = "19" + tmpStr;
    tmpStr = tmpStr.substring(4, 6) + "月" + tmpStr.substring(6) + '日'
  } else {
    tmpStr = iIdNo.substring(6, 14);
    tmpStr = tmpStr.substring(4, 6) + "月" + tmpStr.substring(6) + '日'
  }
  return tmpStr;
}

// 获取性别
export function getSex(idcard:string) {
  let sex = ''
  if (parseInt(idcard.substr(16, 1)) % 2 == 1) {
    sex = '男'
  } else {
    sex = '女'
  }
  return sex
}

// 微信号校验
export function authCode(str:string){
  let length = str.replace(/\s/g,"").length
  return length
}
//星座
export function getConstellation(idCard: string): string {
  // 提取出生日期部分
  const birthDateStr = idCard.substring(6, 14);
  const year = parseInt(birthDateStr.substring(0, 4), 10);
  const month = parseInt(birthDateStr.substring(4, 6), 10);
  const day = parseInt(birthDateStr.substring(6, 8), 10);

  // 定义星座边界
  const constellationBoundaries = [
    { name: '摩羯座', start: new Date(year, 0, 20) },
    { name: '水瓶座', start: new Date(year, 1, 19) },
    { name: '双鱼座', start: new Date(year, 2, 20) },
    { name: '白羊座', start: new Date(year, 3, 20) },
    { name: '金牛座', start: new Date(year, 4, 21) },
    { name: '双子座', start: new Date(year, 5, 21) },
    { name: '巨蟹座', start: new Date(year, 6, 22) },
    { name: '狮子座', start: new Date(year, 7, 23) },
    { name: '处女座', start: new Date(year, 8, 23) },
    { name: '天秤座', start: new Date(year, 9, 23) },
    { name: '天蝎座', start: new Date(year, 10, 23) },
    { name: '射手座', start: new Date(year, 11, 22) },
    { name: '摩羯座', start: new Date(year + 1, 0, 19) } // 用于处理12月23日及之后的情况
  ];

  // 创建输入日期对象
  const inputDate = new Date(year, month - 1, day);

  // 查找对应的星座
  for (let i = 0; i < constellationBoundaries.length - 1; i++) {
    if (inputDate >= constellationBoundaries[i].start && inputDate < constellationBoundaries[i + 1].start) {
      return constellationBoundaries[i].name;
    }
  }
  // 默认返回摩羯座（理论上不会执行到这里）
  return '摩羯座';
}
