#pragma once

#include <QWidget>
#include <QVBoxLayout>
#include <QPointer>
#include "../UserRowWidget/user-row-widget.h"
#include "../../core/user_types.h"

class UserListPanel : public QWidget {
    Q_OBJECT
public:
    explicit UserListPanel(QWidget* parent = nullptr);

    void setUsers(const QList<UserRecord>& users);
    void updateUser(const UserRecord& user);
    void addUser(const UserRecord& user);
    void removeUser(const QString& username);

    // 设置或刷新表头显示（列标题：用户ID, 登录名, 全名, 操作）
    void ensureHeader();
    
    // Set whether the current user has admin privileges (sudo group)
    void setCurrentUserIsAdmin(bool isAdmin) { m_currentUserIsAdmin = isAdmin; }

signals:
    void changePasswordRequested(const QString& username);
    void deleteUserRequested(const QString& username);
    void changeTypeRequested(const QString& username);

private:
    QPointer<QVBoxLayout> m_layout;
    QPointer<QWidget> m_header;
    bool m_currentUserIsAdmin = false;
};
