var plasma = getApiVersion(1);

// Remove all existing panels first
var existingPanels = panels();
for (var i = 0; i < existingPanels.length; i++) {
    existingPanels[i].remove();
}

// ── Top Left bar ──────────────────────────────────────────────────────────────────
var topBar = new Panel;
topBar.location = "top";
topBar.alignment = "left";
topBar.height   = 56;
topBar.hiding   = "dodgewindows";
topBar.floating = true;

var launcher = topBar.addWidget("org.kde.plasma.kickerdash");
launcher.currentConfigGroup = ["/"];
launcher.writeConfig("PreloadWeight", "100");
launcher.currentConfigGroup = ["General"];
launcher.writeConfig("favoritesPortedToKAstats", "true");
launcher.writeConfig("icon", "start-here");

var spacer = topBar.addWidget("org.kde.plasma.panelspacer");
spacer.currentConfigGroup = ["General"];
spacer.writeConfig("expanding", "true");

var systray = topBar.addWidget("org.kde.plasma.systemtray");
systray.currentConfigGroup = ["General"];
systray.writeConfig("iconSize", "2");

topBar.alignment = 4;

// ── Bottom dock (floating, content-sized, centered) ───────────────────────────
var dock = new Panel;
dock.location = "bottom";
dock.height   = 56;
dock.hiding   = "dodgewindows";
dock.floating = true;

var tasks = dock.addWidget("org.kde.plasma.icontasks");
tasks.currentConfigGroup = ["General"];
tasks.writeConfig("launchers",
    "applications:chromium-browser.desktop," +
    "applications:io.elementary.files.desktop," +
    "applications:org.kde.discover.desktop," +
    "applications:org.kde.konsole.desktop," +
    "applications:systemsettings.desktop"
);
tasks.writeConfig("iconSize",     "3");
tasks.writeConfig("iconSpacing",  "1");
tasks.writeConfig("maxStripes",   "1");
tasks.writeConfig("forceStripes", "true");
tasks.writeConfig("fill",         "false"); // ← stop icontasks expanding to full width

dock.alignment = 4; // Qt::AlignHCenter = 4

// ── Desktop wallpaper ────────────────────────────────────────────────────────
var desktops = desktopsForActivity(currentActivity());
for (var i = 0; i < desktops.length; i++) {
    desktops[i].wallpaperPlugin = "org.kde.image";
    desktops[i].currentConfigGroup = ["Wallpaper", "org.kde.image", "General"];
    desktops[i].writeConfig("Image",
        "file:///usr/share/wallpapers/Linux4Switch/images/Linux4Switch.bmp");
}
