/**
 * Tracks that a staff user has performed at least one thẩm định (✓/✗) on the evidence dashboard
 * for a given case — unlocks DOCX preview completeness UI on the bundle-review tab (same browser session).
 */
export function evidenceStaffReviewAckStorageKey(caseId: string): string {
  return `sk:evidenceStaffReviewAck:v1:${caseId}`;
}

const storageKey = evidenceStaffReviewAckStorageKey;

export const EVIDENCE_STAFF_REVIEW_ACK_EVENT = "sk:evidence-staff-review-ack";

export function markEvidenceStaffReviewAcknowledged(caseId: string): void {
  const id = caseId.trim();
  if (!id) return;
  try {
    sessionStorage.setItem(storageKey(id), "1");
  } catch {
    /* quota / private mode */
  }
  window.dispatchEvent(
    new CustomEvent<{ caseId: string }>(EVIDENCE_STAFF_REVIEW_ACK_EVENT, { detail: { caseId: id } }),
  );
}

export function hasEvidenceStaffReviewAcknowledged(caseId: string): boolean {
  const id = caseId.trim();
  if (!id) return false;
  try {
    return sessionStorage.getItem(storageKey(id)) === "1";
  } catch {
    return false;
  }
}
