// Desktop kernel header
#pragma once

#include "service_interface.h"
#include <RmlUi/Core/Types.h>
#include <memory>
#include <string>

// Forward declarations
namespace Rml {
class Context;
class ElementDocument;
}
struct lua_State;

namespace mosis {

// Desktop kernel implementation
class DesktopKernel : public IKernel {
public:
    explicit DesktopKernel(const KernelConfig& config);
    ~DesktopKernel() override;

    // IKernel implementation
    void AddListener(std::shared_ptr<IServiceListener> listener) override;
    void RemoveListener(std::shared_ptr<IServiceListener> listener) override;
    void OnTouchDown(float x, float y) override;
    void OnTouchMove(float x, float y) override;
    void OnTouchUp(float x, float y) override;
    void OnBackButton() override;
    void OnHomeButton() override;
    void OnRecentsButton() override;
    void RequestReload() override;
    void LoadDocument(const std::string& path) override;
    void Start() override;
    void Stop() override;
    bool IsRunning() const override;
    void Update() override;
    void Render() override;

    // Desktop-specific methods
    void SetContext(Rml::Context* context);
    Rml::Context* GetContext() const;
    void SetDocument(Rml::ElementDocument* doc);
    Rml::ElementDocument* GetDocument() const;
    void SetCurrentDocumentPath(const std::string& path);

    // Static Lua function registration
    static int LuaLoadScreen(lua_State* L);
    static void RegisterLuaFunctions();

private:
    class Impl;
    std::unique_ptr<Impl> m_impl;
};

} // namespace mosis
