// src/utils/password.js
export const hasUpper = (s = "") => /[A-Z]/.test(s);
export const hasSymbol = (s = "") => /[^A-Za-z0-9]/.test(s);
export const hasMinLen = (s = "") => (s || "").length >= 8;

export function passwordRulesStatus(pw = "") {
  return {
    minLen: hasMinLen(pw),
    upper: hasUpper(pw),
    symbol: hasSymbol(pw),
  };
}

export function passwordStrength(pw = "") {
  let score = 0;
  if (hasMinLen(pw)) score += 1;
  if (hasUpper(pw)) score += 1;
  if (hasSymbol(pw)) score += 1;
  if (/[0-9]/.test(pw)) score += 1;
  if ((pw || "").length >= 12) score += 1;

  if (!pw) return { label: "خالی", level: 0, percent: 0 };
  if (score <= 2) return { label: "ضعیف", level: 1, percent: 33 };
  if (score === 3) return { label: "متوسط", level: 2, percent: 66 };
  return { label: "قوی", level: 3, percent: 100 };
}
