// SPDX-FileCopyrightText: 2025 KylinSoft Co., Ltd.
//
// SPDX-License-Identifier: GPL-1.0-or-later

#pragma once

#include "ukuishell.h"

namespace QtWaylandClient
{

class XdgDialogV1;

class Toplevel : public QtWayland::xdg_toplevel
{
public:
    Toplevel(UkuiShellSurface *ukuiShellSurface);
    Toplevel(UkuiShellSurfaceV1 *ukuiShellSurfaceV1);
    ~Toplevel() override;

    void applyConfigure();
    bool wantsDecorations();

    void xdg_toplevel_configure(int32_t width, int32_t height, wl_array *states) override;
    void xdg_toplevel_close() override;

    void requestWindowFlags(Qt::WindowFlags flags);
    void requestWindowStates(Qt::WindowStates states);

    static resize_edge convertToResizeEdges(Qt::Edges edges);

private:
    struct
    {
        QSize size = {0, 0};
        Qt::WindowStates states = Qt::WindowNoState;
    } m_pending, m_applied;
    QSize m_normalSize;

    UkuiShellSurface *m_ukuiShellSurface = nullptr;
    UkuiShellSurfaceV1 *m_ukuiShellSurfaceV1 = nullptr;
    XdgToplevelDecorationV1 *m_decoration = nullptr;
    std::unique_ptr<XdgDialogV1> m_xdgDialog;
};

} // namespace QtWaylandClient
