"""Tests for the converter module."""

import tempfile
from pathlib import Path

import pytest

from mkdocs_md_to_pdf import __version__, convert
from mkdocs_md_to_pdf.converter import _extract_linked_files, _get_template_content


def test_version():
    assert __version__ == "0.1.0"


def test_get_template_content():
    content = _get_template_content()
    assert "{{site_name}}" in content
    assert "{{docs_dir}}" in content
    assert "mkdocs-material" in content or "material" in content


def test_extract_linked_files():
    with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
        f.write("""
# Test Document

![Image](image.png)
[Link](other.md)
[External](https://example.com)
[Anchor](#section)
<img src="photo.jpg" alt="Photo">
<img src="https://example.com/img.png" alt="External">
""")
        f.flush()

        linked = _extract_linked_files(Path(f.name))

    assert "image.png" in linked
    assert "other.md" in linked
    assert "photo.jpg" in linked
    assert "https://example.com" not in linked
    assert "#section" not in linked


def test_convert_file_not_found():
    with pytest.raises(FileNotFoundError):
        convert("/nonexistent/path/to/file.md")
