import { describe, it, expect } from 'vitest';
import { sharingPreview, visibilityTooltip } from './sharingScope';

describe('sharingPreview', () => {
  it('private shares nothing and names only the owner', () => {
    const p = sharingPreview('private');
    expect(p.audience).toContain('あなたのみ');
    expect(p.items.every((i) => !i.shared)).toBe(true);
  });

  it('org shares task/files/subtasks but NOT AGENTS.md/memory/calendar', () => {
    const p = sharingPreview('org', 'マーケ部');
    expect(p.audience).toContain('マーケ部');
    const shared = (label: string) => p.items.find((i) => i.label.includes(label))?.shared;
    expect(shared('タスク')).toBe(true);
    expect(shared('ファイル')).toBe(true);
    expect(shared('サブタスク')).toBe(true);
    // The crux of #008: these stay private regardless of scope.
    expect(shared('AGENTS.md')).toBe(false);
    expect(shared('カレンダー')).toBe(false);
  });

  it('public means logged-in users, explicitly not unauthenticated', () => {
    const p = sharingPreview('public');
    expect(p.audience).toContain('ログイン済み');
    expect(p.audience).toContain('未ログインには非公開');
  });

  it('viewers are read-only for shared scopes', () => {
    expect(sharingPreview('org').accessNote).toContain('読み取り専用');
    expect(sharingPreview('public').accessNote).toContain('読み取り専用');
  });

  it('falls back to a generic org label when no name is given', () => {
    expect(sharingPreview('org', null).audience).toContain('この組織');
  });
});

describe('visibilityTooltip', () => {
  it('gives a one-line tooltip per scope', () => {
    expect(visibilityTooltip('private')).toContain('あなたのみ');
    expect(visibilityTooltip('org')).toContain('組織');
    expect(visibilityTooltip('public')).toContain('未ログインには非公開');
  });
});
