// #region SplitViewTest [C:2] [TYPE Module] [SEMANTICS test, datasets, split-view, layout, component]
// @BRIEF Contract-focused unit tests for split-view layout in +page.svelte.
// @LAYER Test
import { describe, it, expect } from 'vitest';
import fs from 'node:fs';
import path from 'node:path';

const PAGE_PATH = path.resolve(process.cwd(), 'src/routes/datasets/+page.svelte');

describe('Split-View Layout', () => {
  it('page file exists', () => {
    expect(fs.existsSync(PAGE_PATH)).toBe(true);
  });

  it('uses Tailwind grid for split-view layout', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('grid-cols-[40%_60%]');
  });

  it('has mobile slide-over behavior', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('isMobile');
    expect(src).toContain('mobileSlideOpen');
    expect(src).toContain('closeDetail');
    expect(src).toContain('fixed inset-0 bg-black/30');
  });

  it('closes slide-over on Escape', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('Escape');
    expect(src).toContain('handleEscape');
  });

  it('wires environmentContextStore', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('environmentContextStore');
    expect(src).toContain('initializeEnvironmentContext');
    expect(src).toContain('setSelectedEnvironment');
  });

  it('renders StatsBar, DatasetList, DatasetPreview', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('StatsBar');
    expect(src).toContain('DatasetList');
    expect(src).toContain('DatasetPreview');
  });

  it('has bulk action panel for >=2 selected', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('selectedIds.size >= 2');
    expect(src).toContain('bulk_map_columns');
    expect(src).toContain('showMapColumnsModal');
    expect(src).toContain('showGenerateDocsModal');
  });

  it('uses Svelte 5 runes pattern', () => {
    const src = fs.readFileSync(PAGE_PATH, 'utf-8');
    expect(src).toContain('$state(');
    expect(src).toContain('$effect(');
    // Page is a route, not a component, so it doesn't use $props()
  });
});
