const COPY = {
  ko: {
    description: "모든 원격 기능은 무료이며 계정 1개를 사용할 수 있습니다. Pro는 최대 5개 계정을 지원하는 비소모성 일회성 구매입니다. Google Play에서 표시된 가격으로 결제하며 구매 복원을 지원합니다.",
    pending: "결제 확인 중입니다.", canceled: "구매가 취소되었습니다.", unavailable: "Google Play를 사용할 수 없습니다.", activated: "Pro가 활성화되었습니다.",
    title: "Pro 다계정", purchaseLabel: "구매", restoreLabel: "구매 복원", manageLabel: "Google Play에서 관리", expiresLabel: "만료",
    free: "무료", grace: "Pro 유예", warning: "검증 서비스에 다시 연결해야 합니다.",
  },
  en: {
    description: "All remote features remain free with one account. Pro supports up to five accounts through a one-time non-consumable purchase billed by Google Play, with purchase restore available.",
    pending: "We are confirming your payment.", canceled: "The purchase was canceled.", unavailable: "Google Play is unavailable.", activated: "Pro is active.",
    title: "Pro multi-account", purchaseLabel: "Purchase", restoreLabel: "Restore purchase", manageLabel: "Manage in Google Play", expiresLabel: "Expires",
    free: "Free", grace: "Pro grace period", warning: "Reconnect to the verification service.",
  },
};

function copy(language) { return COPY[language === "ko" ? "ko" : "en"]; }

export function purchaseSheetModel({ product = {}, entitlement = {}, outcome, language = "ko" } = {}) {
  const text = copy(language);
  const messages = { pending:text.pending, canceled:text.canceled, unavailable:text.unavailable };
  return {
    title:text.title, closeLabel:language === "ko" ? "닫기" : "Close", purchaseLabel:text.purchaseLabel, restoreLabel:text.restoreLabel,
    description:text.description, price:product.localizedPrice ?? null,
    message:entitlement.tier === "pro" ? text.activated : messages[outcome] ?? null,
    canPurchase:product.available === true && entitlement.tier !== "pro",
  };
}

export function settingsModel({ entitlement = {}, accountCount = 0, language = "ko" } = {}) {
  const text = copy(language);
  const label = entitlement.tier === "pro" ? "Pro" : entitlement.tier === "grace" ? text.grace : text.free;
  return {
    label, count:`${accountCount} / ${entitlement.maxAccounts ?? 1}`,
    warning:entitlement.tier === "grace" ? text.warning : null, expiresAt:entitlement.expiresAt ?? null,
    restoreLabel:text.restoreLabel, manageLabel:text.manageLabel, expiresLabel:text.expiresLabel,
  };
}
