import { useState } from "react"; const STORAGE_KEY = "nakhodka:safetyNoticeHidden"; // Аккаунт моложе недели — частый признак мошенника, который заводит новые под каждую схему const NEW_ACCOUNT_DAYS = 7; function readHidden() { try { return JSON.parse(localStorage.getItem(STORAGE_KEY) || "[]"); } catch { return []; } } /** Собеседник зарегистрировался меньше недели назад. */ export function isNewAccount(createdAt, now = Date.now()) { if (!createdAt) return false; const created = new Date(createdAt).getTime(); return Number.isFinite(created) && now - created < NEW_ACCOUNT_DAYS * 24 * 60 * 60 * 1000; } /** * Плашка над перепиской: не переводить предоплату, не называть коды. Скрыть * можно в каждом чате отдельно; отметку о новом аккаунте собеседника скрыть * нельзя — она про конкретного человека. */ export default function ChatSafetyNotice({ chatId, otherUserCreatedAt, t }) { const [hidden, setHidden] = useState(() => chatId != null && readHidden().includes(String(chatId))); const newAccount = isNewAccount(otherUserCreatedAt); const hide = () => { setHidden(true); if (chatId == null) return; try { const ids = [...new Set([...readHidden(), String(chatId)])].slice(-200); localStorage.setItem(STORAGE_KEY, JSON.stringify(ids)); } catch { // приватный режим — плашка просто снова появится } }; if (hidden && !newAccount) return null; return (