const fs = require('fs');
const path = require('path');


const settingsPath = path.join(__dirname, 'settings.json');
const settingsContent = fs.readFileSync(settingsPath, 'utf8');

const settings = JSON.parse(settingsContent);

// Toggle editor.glyphMargin
if (settings['editor.glyphMargin'] === undefined) {
  console.log(settings['editor.glyphMargin']);
  settings['editor.glyphMargin'] = false;
} else {
  delete settings['editor.glyphMargin'];
}

// Toggle editor.lineNumbers
if (settings['editor.lineNumbers'] === undefined) {
  settings['editor.lineNumbers'] = 'off';
} else {
  delete settings['editor.lineNumbers'];
}

// Toggle vim.smartRelativeNumber
if (settings['vim.smartRelativeLine'] === undefined || settings['vim.smartRelativeLine'] === false) {
  settings['vim.smartRelativeLine'] = true;
} else {
  delete settings['vim.smartRelativeLine'];
}

fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
console.log('Settings toggled successfully.');

//node C:\Users\st96481.ttl\AppData\Roaming\Code\User\toggleSettings.js

// Along with both the below combo this script changes the setting.json to toggle zen mode with glyphMargin, lineNumbers and vim.smartRelativeLine

// this is the setting.json snippet
{
  "multiCommand.commands": [
    {
      "command": "extension.toggleZenModeAndSettings",
      "sequence": [
        "workbench.action.toggleZenMode",
        {
          "command": "workbench.action.terminal.sendSequence",
          "args": {
            "text": "node C:\\Users\\st96481.ttl\\AppData\\Roaming\\Code\\User\\toggleSettings.js\n"
          }
        }
      ]
    }
  ],
}
// this is key binding from keybindings.json
{
    "key": "alt+shift+z alt+shift+m",
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        "extension.toggleZenModeAndSettings"
      ]
    }
  }