/*
Crafter®.Graphics
Copyright (C) 2026 Catcrafts®
catcrafts.net

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 3.0 as published by the Free Software Foundation;

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
*/

// DOM event POD structs delivered by dom-env.js into the per-listener
// callback set in :Dom. The set of fields and their semantics mirror the
// equivalent W3C event interfaces — the JS bridge marshals each field
// individually as a primitive over the wasm boundary (no struct passing,
// no JSON), so the layouts here are merely what the C++ side reconstructs
// before invoking the user's std::function.

export module Crafter.Graphics:DomEvents;
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
import std;

// The Dom* namespace mirrors CppDOM's flat `Crafter::*` event types but is
// re-homed under Crafter::Dom to avoid clashing with anything :Types or
// :Input may later add at the bare Crafter:: scope.
export namespace Crafter::Dom {
    struct KeyboardEvent {
        std::string key;
        std::uint_fast8_t keyCode;
        bool altKey;
        bool ctrlKey;
        bool shiftKey;
        bool metaKey;
        KeyboardEvent(const char* key, std::int32_t keyCode,
                      bool altKey, bool ctrlKey, bool shiftKey, bool metaKey)
            : key(key), keyCode(keyCode),
              altKey(altKey), ctrlKey(ctrlKey),
              shiftKey(shiftKey), metaKey(metaKey) {}
    };

    struct FocusEvent {
        // Opaque JS handle cookies — round-trip back into env.js as the
        // identity of the related element. No C++ API attaches semantics
        // to them today; held for forward-compat with later helpers.
        void* target;
        void* relatedTarget;
        FocusEvent(void* target, void* relatedTarget)
            : target(target), relatedTarget(relatedTarget) {}
    };

    struct MouseEvent {
        double clientX;
        double clientY;
        double screenX;
        double screenY;
        std::uint_fast32_t button;
        std::uint_fast32_t buttons;
        bool altKey;
        bool ctrlKey;
        bool shiftKey;
        bool metaKey;
        MouseEvent(double clientX, double clientY, double screenX, double screenY,
                   std::int32_t button, std::int32_t buttons,
                   bool altKey, bool ctrlKey, bool shiftKey, bool metaKey)
            : clientX(clientX), clientY(clientY),
              screenX(screenX), screenY(screenY),
              button(button), buttons(buttons),
              altKey(altKey), ctrlKey(ctrlKey),
              shiftKey(shiftKey), metaKey(metaKey) {}
    };

    struct InputEvent {
        std::string data;
        bool isComposing;
        InputEvent(const char* data, bool isComposing)
            : data(data), isComposing(isComposing) {}
    };

    struct WheelEvent : public MouseEvent {
        double deltaX;
        double deltaY;
        double deltaZ;
        WheelEvent(double clientX, double clientY, double screenX, double screenY,
                   std::int32_t button, std::int32_t buttons,
                   bool altKey, bool ctrlKey, bool shiftKey, bool metaKey,
                   double deltaX, double deltaY, double deltaZ)
            : MouseEvent(clientX, clientY, screenX, screenY,
                         button, buttons, altKey, ctrlKey, shiftKey, metaKey),
              deltaX(deltaX), deltaY(deltaY), deltaZ(deltaZ) {}
    };

    struct ResizeEvent {
        std::uint_fast32_t width;
        std::uint_fast32_t height;
        ResizeEvent(std::uint_fast32_t width, std::uint_fast32_t height)
            : width(width), height(height) {}
    };

    struct ScrollEvent {
        double scrollX;
        double scrollY;
        ScrollEvent(double scrollX, double scrollY)
            : scrollX(scrollX), scrollY(scrollY) {}
    };

    struct ChangeEvent {
        std::string value;
        ChangeEvent(const char* value) : value(value) {}
    };
}
#endif // CRAFTER_GRAPHICS_WINDOW_DOM
