#include "Settings.h"

Settings::Settings(QObject *parent)
    : QObject(parent)
    , m_settings(QSettings::IniFormat, QSettings::UserScope, "BareCode", "BareCode")
{
}

// ---------------------------------------------------------------------------
// Editor font
// ---------------------------------------------------------------------------
QFont Settings::editorFont() const
{
    QFont defaultFont("Monospace", 11);
    defaultFont.setStyleHint(QFont::Monospace);
    return m_settings.value("editor/font", defaultFont).value<QFont>();
}

void Settings::setEditorFont(const QFont &font)
{
    m_settings.setValue("editor/font", font);
    emit settingsChanged();
}

// ---------------------------------------------------------------------------
// Tab size
// ---------------------------------------------------------------------------
int Settings::tabSize() const
{
    return m_settings.value("editor/tabSize", 4).toInt();
}

void Settings::setTabSize(int size)
{
    m_settings.setValue("editor/tabSize", size);
    emit settingsChanged();
}

// ---------------------------------------------------------------------------
// Spaces vs. tabs
// ---------------------------------------------------------------------------
bool Settings::useSpacesForTabs() const
{
    return m_settings.value("editor/useSpacesForTabs", true).toBool();
}

void Settings::setUseSpacesForTabs(bool use)
{
    m_settings.setValue("editor/useSpacesForTabs", use);
    emit settingsChanged();
}

// ---------------------------------------------------------------------------
// File tree width
// ---------------------------------------------------------------------------
int Settings::fileTreeWidth() const
{
    return m_settings.value("layout/fileTreeWidth", 240).toInt();
}

void Settings::setFileTreeWidth(int width)
{
    m_settings.setValue("layout/fileTreeWidth", width);
}

// ---------------------------------------------------------------------------
// Dark mode
// ---------------------------------------------------------------------------
bool Settings::darkMode() const
{
    return m_settings.value("appearance/darkMode", false).toBool();
}

void Settings::setDarkMode(bool dark)
{
    m_settings.setValue("appearance/darkMode", dark);
}

// ---------------------------------------------------------------------------
// Last project path
// ---------------------------------------------------------------------------
QString Settings::lastProjectPath() const
{
    return m_settings.value("project/lastPath", QString()).toString();
}

void Settings::setLastProjectPath(const QString &path)
{
    m_settings.setValue("project/lastPath", path);
}

// ---------------------------------------------------------------------------
// Session – geöffnete Dateien
// ---------------------------------------------------------------------------
QStringList Settings::lastOpenFiles() const
{
    return m_settings.value("session/openFiles", QStringList()).toStringList();
}

void Settings::setLastOpenFiles(const QStringList &files)
{
    m_settings.setValue("session/openFiles", files);
}

QString Settings::lastActiveFile() const
{
    return m_settings.value("session/activeFile", QString()).toString();
}

void Settings::setLastActiveFile(const QString &file)
{
    m_settings.setValue("session/activeFile", file);
}
