#pragma once
// ── ResourceLoader ───────────────────────────────────────────────────────────
// Loads the splash / cashier / help images.
//
// This used to pull them out of the executable as Win32 RCDATA resources, via
// FindResource / LoadResource / LockResource. That is Windows-only API and was
// the single biggest obstacle to building this codebase on a Mac.
//
// They are now ordinary files, loaded from the platform's resources directory:
//
//   Windows   <install dir>\resources\
//   macOS     TrackDesigner.app/Contents/Resources/resources/
//
// wxStandardPaths::GetResourcesDir() resolves to the right place on each, so
// the same call works everywhere and there is no #ifdef. CMake copies the
// images there at build time and the installer / bundle ships them.
//
// If an image is missing the caller gets an invalid wxImage; every caller
// already checks IsOk() before using it, so a missing file degrades to "no
// picture" rather than a crash.
// ─────────────────────────────────────────────────────────────────────────────
#include <wx/image.h>
#include <wx/stdpaths.h>
#include <wx/filename.h>

// Kept as ints so the existing call sites (LoadImageResource(RES_SPLASH) etc.)
// need no changes.
#define RES_SPLASH    101
#define RES_CASHIER   102
#define RES_HELP      103

inline wxImage LoadImageResource(int resId) {
    const char* file = nullptr;
    switch (resId) {
        case RES_SPLASH:  file = "splash.jpg";  break;
        case RES_CASHIER: file = "cashier.jpg"; break;
        case RES_HELP:    file = "help.jpg";    break;
        default:          return wxImage();
    }

    wxString dir = wxStandardPaths::Get().GetResourcesDir();
    wxString path = dir + wxFileName::GetPathSeparator()
                  + "resources" + wxFileName::GetPathSeparator()
                  + wxString::FromAscii(file);

    if (!wxFileName::FileExists(path)) {
        // Fall back to the executable's own directory. Helps when running
        // straight out of a build tree, where there is no install layout yet.
        wxFileName exe(wxStandardPaths::Get().GetExecutablePath());
        path = exe.GetPath() + wxFileName::GetPathSeparator()
             + "resources" + wxFileName::GetPathSeparator()
             + wxString::FromAscii(file);
        if (!wxFileName::FileExists(path)) return wxImage();
    }

    wxImage img;
    img.LoadFile(path, wxBITMAP_TYPE_JPEG);
    return img;
}
