 Menu = remote.Menu
 
 acceleratorMap = {
-    hideyakyak:           {others: 'Control+H', osx: 'Command+H'}
-    hideothers:           {others: '', osx: 'Command+Shift+H'}
-    showall:              {others: '', osx: ''}
-    openinspector:        {others: 'Control+Alt+I', osx: 'Command+Alt+I'}
-    quit:                 {others: 'Control+Q', osx: 'Command+Q'}
-    undo:                 {others: 'Control+Z', osx: 'Command+Z'}
-    redo:                 {others: 'Control+Shift+Z', osx: 'Command+Shift+Z'}
-    cut:                  {others: '', osx: 'Command+X'}
-    copy:                 {others: '', osx: 'Command+C'}
-    paste:                {others: '', osx: 'Command+V'}
-    selectall:            {others: '', osx: 'Command+A'}
-    togglefullscreen:     {others: 'Control+Alt+F', osx: 'Command+Control+F'}
-    zoomin:               {others: 'Control+Plus', osx: 'Command+Plus'}
-    zoomout:              {others: 'Control+-', osx: 'Command+-'}
-    resetzoom:            {others: 'Control+0', osx: 'Command+0'}
-    previousconversation: {others: 'Control+K', osx: 'Command+Shift+Tab'}
-    nextconversation:     {others: 'Control+J', osx: 'Command+Tab'}
-    conversation1:        {others: 'Alt+1', osx: 'Command+1'}
-    conversation2:        {others: 'Alt+2', osx: 'Command+2'}
-    conversation3:        {others: 'Alt+3', osx: 'Command+3'}
-    conversation4:        {others: 'Alt+4', osx: 'Command+4'}
-    conversation5:        {others: 'Alt+5', osx: 'Command+5'}
-    conversation6:        {others: 'Alt+6', osx: 'Command+6'}
-    conversation7:        {others: 'Alt+7', osx: 'Command+7'}
-    conversation8:        {others: 'Alt+8', osx: 'Command+8'}
-    conversation9:        {others: 'Alt+9', osx: 'Command+9'}
-    minimize:             {others: '', osx: 'Command+M'}
-    close:                {others: '', osx: 'Command+W'}
+    hideyakyak:           {others: 'Control+H', darwin:'Command+H'}
+    hideothers:           {others: '', darwin:'Command+Shift+H'}
+    showall:              {others: '', darwin:''}
+    openinspector:        {others: 'Control+Alt+I', darwin:'Command+Alt+I'}
+    quit:                 {others: 'Control+Q', darwin:'Command+Q'}
+    undo:                 {others: 'Control+Z', darwin:'Command+Z'}
+    redo:                 {others: 'Control+Shift+Z', darwin:'Command+Shift+Z'}
+    cut:                  {others: '', darwin:'Command+X'}
+    copy:                 {others: '', darwin:'Command+C'}
+    paste:                {others: '', darwin:'Command+V'}
+    selectall:            {others: '', darwin:'Command+A'}
+    togglefullscreen:     {others: 'Control+Alt+F', darwin:'Command+Control+F'}
+    zoomin:               {others: 'Control+Plus', darwin:'Command+Plus'}
+    zoomout:              {others: 'Control+-', darwin:'Command+-'}
+    resetzoom:            {others: 'Control+0', darwin:'Command+0'}
+    previousconversation: {others: 'Control+K', darwin:'Command+Shift+Tab'}
+    nextconversation:     {others: 'Control+J', darwin:'Command+Tab'}
+    conversation1:        {others: 'Alt+1', darwin:'Command+1'}
+    conversation2:        {others: 'Alt+2', darwin:'Command+2'}
+    conversation3:        {others: 'Alt+3', darwin:'Command+3'}
+    conversation4:        {others: 'Alt+4', darwin:'Command+4'}
+    conversation5:        {others: 'Alt+5', darwin:'Command+5'}
+    conversation6:        {others: 'Alt+6', darwin:'Command+6'}
+    conversation7:        {others: 'Alt+7', darwin:'Command+7'}
+    conversation8:        {others: 'Alt+8', darwin:'Command+8'}
+    conversation9:        {others: 'Alt+9', darwin:'Command+9'}
+    minimize:             {others: '', darwin:'Command+M'}
+    close:                {others: '', darwin:'Command+W'}
 }
 
-templateYakYak = (viewstate, os) ->
+templateYakYak = (viewstate, platform) ->
     tmpl = []
-    if os == 'darwin'
-        tmpl.push [
+    if platform == 'darwin'
+        tmpl.concat [
             { label: 'About YakYak', selector: 'orderFrontStandardAboutPanel:' }
             #{ type: 'separator' }
             # { label: 'Preferences...', accelerator: 'Command+,',
             # click: => delegate.openConfig() }
             { type: 'separator' }
         ]
-    tmpl.push [
-        {
-            label: 'Hide YakYak'
-            accelerator: acceleratorMap['hideyakyak'][os]
-            selector: 'hide:'
-        }
-    ]
-
-    if os == 'darwin'
+    tmpl.push {
+        label: 'Hide YakYak'
+        accelerator: acceleratorMap['hideyakyak'][platform]
+        selector: 'hide:' if platform == 'darwin'
+        role: 'minimize' if platform == 'others'
+    }
+
+    if platform == 'darwin'
         tmpl.push [{
-              label: 'Hide Others'
-              accelerator: acceleratorMap['hideother'][os]
-              selector: 'hideOtherApplications:'
-        }
-        { label: 'Show All', selector: 'unhideAllApplications:' }
+                label: 'Hide Others'
+                accelerator: acceleratorMap['hideother'][platform]
+                selector: 'hideOtherApplications:' if platform == 'darwin'
+            }
+            {
+                label: 'Show All'
+                selector: 'unhideAllApplications:' if platform == 'darwin'
+            }
         ]
     tmpl.push [
-      { type: 'separator' }
-      {
-          label: 'Open Inspector'
-          accelerator: acceleratorMap['openinspector'][os]
-          click: -> action 'devtools'
-      }
-      { type: 'separator' }
-      {
-          label: 'Logout',
-          click: -> action 'logout'
-          enabled: viewstate.loggedin
-      }
-      {
-          label: 'Quit'
-          accelerator: acceleratorMap['quit'][os]
-          click: -> action 'quit'
-      }
-  ]
-
-templateEdit = (viewstate, os) ->
+        { type: 'separator' }
+        {
+            label: 'Open Inspector'
+            accelerator: acceleratorMap['openinspector'][platform]
+            click: -> action 'devtools'
+        }
+        { type: 'separator' }
+        {
+            label: 'Logout',
+            click: -> action 'logout'
+            enabled: viewstate.loggedin
+        }
+        {
+            label: 'Quit'
+            accelerator: acceleratorMap['quit'][platform]
+            click: -> action 'quit'
+        }
+    ]
+    tmpl
+
+templateEdit = (viewstate, platform) ->
     tmpl = [
-        { label: 'Undo', accelerator: acceleratorMap['undo'][os], selector: 'undo:' }
-        { label: 'Redo', accelerator: acceleratorMap['redo'][os], selector: 'redo:' }
+        {
+          label: 'Undo'
+          accelerator: acceleratorMap['undo'][platform]
+          selector: 'undo:' if platform == 'darwin'
+        }
+        {
+          label: 'Redo'
+          accelerator: acceleratorMap['redo'][platform]
+          selector: 'redo:' if platform == 'darwin'
+        }
     ]
-    if os == 'darwin'
+    if platform == 'darwin'
         tmpl.push [
           { type: 'separator' }
-          { label: 'Cut', accelerator: acceleratorMap['cut'][os], selector: 'cut:' }
-          { label: 'Copy', accelerator: acceleratorMap['copy'][os], selector: 'copy:' }
-          { label: 'Paste', accelerator: acceleratorMap['paste'][os], selector: 'paste:' }
-          { label: 'Select All', accelerator: acceleratorMap['selectall'][os], selector: 'selectAll:' }
+          {
+            label: 'Cut'
+            accelerator: acceleratorMap['cut'][platform]
+            selector: 'cut:' if platform == 'darwin'
+          }
+          {
+            label: 'Copy'
+            accelerator: acceleratorMap['copy'][platform]
+            selector: 'copy:' if platform == 'darwin'
+          }
+          {
+            label: 'Paste'
+            accelerator: acceleratorMap['paste'][platform]
+            selector: 'paste:' if platform == 'darwin'
+          }
+          {
+            label: 'Select All'
+            accelerator: acceleratorMap['selectall'][platform]
+            selector: 'selectAll:' if platform == 'darwin'
+          }
         ]
     tmpl
 
-templateView = (viewstate, os) ->
+templateView = (viewstate, platform) ->
     tmpl = [
         {
             label: 'Conversation List'

            click: -> action 'toggleshowtray'
        }
    ]
    if os == 'darwin'
        tmpl.push {
            label: 'Hide Dock icon'
            type: 'checkbox'

        }
    tmpl

templateWindow = (viewstate, platform) -> [
    {
        label: 'Minimize'
        accelerator: acceleratorMap['minimize'][platform]
        selector: 'performMiniaturize:' if platform == 'darwin'
    }, {
        label: 'Close'
        accelerator: acceleratorMap['close'][platform]
        selector: 'performClose:' if platform == 'darwin'
    }, {
        type: 'separator'
    }, {
        label: 'Bring All to Front',
        selector: 'arrangeInFront:' if platform == 'darwin'
    }
]

templateMenu = (viewstate) ->
    platform = if require('os').platform() == 'darwin' then 'darwin' else 'others'
    tmpl = [{
            label: 'YakYak'
            submenu: templateYakYak viewstate, platform
        }, {
            label: 'Edit'
            submenu: templateEdit viewstate, platform
        },{
            label: 'View'
            submenu: templateView viewstate, platform
        }
    ]
    if platform == 'darwin'
        tmpl.push {
            label: 'Window'
            submenu: templateWindow viewstate, platform
        }
    tmpl

module.exports = (viewstate) ->
    console.log "b4"
    Menu.setApplicationMenu Menu.buildFromTemplate templateMenu(viewstate)
    console.log "done!"
