"""PyInstaller hook for pypdfium2.

``pypdfium2`` ships the native PDFium shared library as a data file
inside its package directory (``pdfium``-prefixed ``.dll`` on
Windows, ``.so`` on Linux, ``.dylib`` on macOS). PyInstaller's
default discovery picks up Python ``.py``/``.pyc`` but can miss
the binary if the package is wheel-installed and the shared lib
isn't on the ``__init__``'s module-level path it scans.

This hook is belt-and-braces — the main spec already calls
``collect_data_files("pypdfium2")`` and ``collect_submodules``,
but PyInstaller's hook-discovery-by-name is the documented
escape hatch for native-bundled libraries. Without this, the
visual picker (which renders PDF pages via
``pypdfium2.PdfDocument(...).render(...)``) silently fails on
installed builds with a ``FileNotFoundError`` for the PDFium
shared library.
"""

from PyInstaller.utils.hooks import (
    collect_all,
    collect_data_files,
    collect_dynamic_libs,
)

datas, binaries, hiddenimports = collect_all("pypdfium2")
# Make absolutely sure the bundled PDFium .dll/.so/.dylib is
# carried over — PyInstaller treats it as a dynamic lib, not data.
binaries += collect_dynamic_libs("pypdfium2")
# And its raw data files (the type stubs + metadata file).
datas += collect_data_files("pypdfium2", include_py_files=False)
