import { describe, it, expect } from 'vitest';
import { screen, fireEvent } from '@testing-library/react';
import { renderWithProviders } from '../../test/utils';
import SettingsLayout, { SETTINGS_MENU } from './SettingsLayout';

describe('SettingsLayout', () => {
  it('renders every settings menu item and the section content', () => {
    renderWithProviders(
      <SettingsLayout active="subscription">
        <div>محتوای اشتراک</div>
      </SettingsLayout>,
    );

    for (const item of SETTINGS_MENU) {
      expect(screen.getByText(item.label)).toBeInTheDocument();
    }
    expect(screen.getByText('محتوای اشتراک')).toBeInTheDocument();
  });

  it('marks the active item with aria-current=page', () => {
    renderWithProviders(
      <SettingsLayout active="subscription"><div /></SettingsLayout>,
    );
    const active = screen.getByText('خرید اشتراک').closest('a');
    expect(active).toHaveAttribute('aria-current', 'page');
    expect(active).toHaveAttribute('href', '/admin/subscription');
  });

  it('renders not-yet-implemented items as disabled placeholders', () => {
    renderWithProviders(
      <SettingsLayout active="subscription"><div /></SettingsLayout>,
    );
    // "حساب کاربری" has no route → disabled button with "به‌زودی"
    const account = screen.getByText('حساب کاربری').closest('button');
    expect(account).toBeDisabled();
    expect(screen.getAllByText('به‌زودی').length).toBeGreaterThan(0);
  });

  it('filters the menu by the search query', () => {
    renderWithProviders(
      <SettingsLayout active="subscription"><div /></SettingsLayout>,
    );
    fireEvent.change(screen.getByLabelText('جستجو در تنظیمات'), { target: { value: 'اشتراک' } });
    expect(screen.getByText('خرید اشتراک')).toBeInTheDocument();
    expect(screen.queryByText('خدمات')).not.toBeInTheDocument();
  });
});
