// Copyright (C) 2026 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "profiler_global.h"

#include <utils/filepath.h>

#include <QObject>
#include <QWidgetList>

#include <chrono>

namespace Timeline { class RangeDetailsWidget; }

namespace Profiler::Internal {

// Hosts the Instruments-like views for traces recorded by a call-stack sampler
// backend (macOS mach-based or Linux perf-based): a CPU usage timeline and the
// merged call-stack tree. Counterpart to the plain view managers in the
// qmlprofiler plugin, but specific to the standalone viewer's sampler trace
// format.
class PROFILER_EXPORT SamplerViewManager : public QObject
{
    Q_OBJECT

public:
    // `details` is the range details panel this manager's views fill. It is owned
    // by the caller, which lets every profiler backend share a single one.
    explicit SamplerViewManager(Timeline::RangeDetailsWidget *details,
                                QObject *parent = nullptr);
    ~SamplerViewManager() override;

    // True if `dir` contains a sampler trace (cheap: reads only the metadata).
    static bool isSamplerTrace(const Utils::FilePath &dir);

    QWidgetList views(QWidget *parent);
    void load(const Utils::FilePath &dir);
    void clear();
    std::chrono::milliseconds traceDuration() const;

signals:
    void error(const QString &error);
    void loadFinished();
    void gotoSourceLocation(const QString &file, int line, int column,
                            const QString &module, quint64 offset);

private:
    class SamplerViewManagerPrivate *d;
};

} // namespace Profiler::Internal
