/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

var Montage =   require("montage/core/core").Montage,
    Component = require("montage/ui/component").Component;

exports.MenuData = Montage.create(Component, {

    _currentDocument: {
            value : null
    },

    currentDocument : {
        get : function() {
            return this._currentDocument;
        },
        set : function(value) {
            if (value === this._currentDocument) {
                return;
            }

            this._currentDocument = value;

            if(!this._currentDocument) {
                this.documentEnabledIndices.forEach(function(index) {
                    index.enabled = false;
                });
            } else {
                this.documentEnabledIndices.forEach(function(index) {
                    index.enabled = true;
                });
            }

        }
    },

    didCreate: {
        value: function() {
            var self = this;

            this.topLevelMenu.forEach(function(item) {
                item.entries.forEach(function(entry) {
                    if(entry.depend && entry.depend === "document") {
                        self.documentEnabledIndices.push(entry);
                    }
                });
            });
        }
    },

    documentEnabledIndices: {
        value: []
    },

    topLevelMenu: {
        value: [
                {
                    "header": "File",
                    "entries": [
                        {
                            "displayText" : "New Project",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "action":   "executeNewProject"
                        },
                        {
                            "displayText" : "New File",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executeNewFile"
                        },
                        {
                            "displayText" : "Open File",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action": "executeFileOpen"
                        },
                        {
                            "displayText" : "Close File",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "action": "executeFileClose"
                        },
                        {
                            "displayText" : "Close All",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "action": "executeFileCloseAll"
                        },
                        {
                            "displayText" : "",
                            "separator":    true,
                            "enabled": true
                        },
                        {
                            "displayText" : "Save",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "action": "executeSave"
                        },
                        {
                            "displayText" : "Save As",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "action":"executeSaveAs"
                        },
                        {
                            "displayText" : "Save All",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "action": "executeSaveAll"
                        },
                        {
                            "displayText" : "",
                            "separator":    true,
                            "enabled": true
                        },
                        {
                            "displayText" : "Open Project",
                            "hasSubMenu" : false,
                            "enabled": false
                        },
                        {
                            "displayText" : "Open Recent",
                            "hasSubMenu" : false,
                            "enabled": false
                        },
                        {
                            "displayText" : "Close Project",
                            "hasSubMenu" : false,
                            "enabled": false
                        }
                    ]
                },
                {
                    "header": "Edit",
                    "entries": [
                        {
                            "displayText" : "Undo",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "newenabled": {
                                "value": false,
                                "boundObj": "undocontroller",
                                "boundProperty": "canUndo",
                                "oneway": true
                            },
                            "action":   "executeUndo"
                        },
                        {
                            "displayText" : "Redo",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "newenabled": {
                                "value": false,
                                "boundObj": "undocontroller",
                                "boundProperty": "canRedo",
                                "oneway": true
                            },
                            "action":   "executeRedo"
                        },
                        {
                            "displayText" : "Cut",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executeCut"
                        },
                        {
                            "displayText" : "Copy",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executeCopy"
                        },
                        {
                            "displayText" : "Paste",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executePaste"
                        }
                    ]
                },
                {
                    "header": "View",
                    "entries": [
                        {
                            "displayText" : "Live Preview",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "checked": {
                                "value": false,
                                "boundProperty": "livePreview"
                            }
                        },
                        {
                            "displayText" : "Chrome Preview",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "checked": {
                                "value": false,
                                "boundProperty": "chromePreview"
                            }
                        },
                        {
                            "displayText" : "Layout View",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "submenu": true,
                            "entries": [
                                {
                                    "displayText" : "View All",
                                    "hasSubMenu" : false,
                                    "radio": true,
                                    "enabled": true,
                                    "checked": {
                                        "value": true,
                                        "boundProperty": "layoutAll"
                                    }
                                },
                                {
                                    "displayText" : "View Items Only",
                                    "hasSubMenu" : false,
                                    "radio": true,
                                    "enabled": true,
                                    "checked": {
                                        "value": false,
                                        "boundProperty": "layoutItems"
                                    }
                                },
                                {
                                    "displayText" : "Off",
                                    "hasSubMenu" : false,
                                    "radio": true,
                                    "enabled": true,
                                    "checked": {
                                        "value": false,
                                        "boundProperty": "layoutOff"
                                    }
                                }
                            ]
                        },
                        {
                            "displayText" : "Snap",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "checked": {
                                "value": true,
                                "boundProperty": "snap"
                            }

                        },
                        {
                            "displayText" : "Snap To",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "newenabled": {
                                "value": true,
                                "boundObj": "appModel",
                                "boundProperty": "snap",
                                "oneway": true
                            },
                            "submenu": true,
                            "entries": [
                                {
                                    "displayText" : "Grid",
                                    "hasSubMenu" : false,
                                    "enabled": true,
                                    "checked": {
                                        "value": true,
                                        "boundProperty": "snapGrid"
                                    }
                                },
                                {
                                    "displayText" : "Objects",
                                    "hasSubMenu" : false,
                                    "enabled": true,
                                    "checked": {
                                        "value": true,
                                        "boundProperty": "snapObjects"
                                    }
                                },
                                {
                                    "displayText" : "Snap Align",
                                    "hasSubMenu" : false,
                                    "enabled": true,
                                    "checked": {
                                        "value": true,
                                        "boundProperty": "snapAlign"
                                    }
                                }
                            ]
                        },
                        {
                            "displayText" : "Show 3D Grid",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "checked": {
                                "value": false,
                                "boundProperty": "show3dGrid"
                            }
                        },
                        {
                            "displayText" : "",
                            "separator":    true,
                            "enabled": true
                        },
                        {
                            "displayText" : "Front View",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "radio": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "frontStageView"
                            }
                        },
                        {
                            "displayText" : "Top View",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "radio": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "topStageView"
                            }
                        },
                        {
                            "displayText" : "Side View",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "depend": "document",
                            "newenabled": {
                                "value": false,
                                "boundObj": "documentController",
                                "boundProperty": "activeDocument",
                                "oneway": true,
                                "boundValueMutator": function(activeDocument){
                                    return (activeDocument !== null) && (activeDocument.currentView === "design");
                                }
                            },
                            "radio": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "sideStageView"
                            }
                        },
                        {
                            "displayText" : "",
                            "separator":    true,
                            "enabled": true
                        },
                        {
                            "displayText" : "Debug",
                            "hasSubMenu" : false,
                            "enabled": false,
                            "checked": {
                                "value": true,
                                "boundProperty": "debug"
                            }
                        }
                    ]
                },
                {
                    "header": "Window",
                    "entries": [
                        {
                            "displayText" : "Tools",
                            "hasSubMenu" : false,
                            "enabled": true
                        },
                        {
                            "displayText" : "Timeline",
                            "hasSubMenu" : false,
                            "enabled": true
                        },
                        {
                            "displayText" : "Properties",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "PropertiesPanel"
                            }
                        },
                        {
                            "displayText" : "Project",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "ProjectPanel"
                            }
                        },
                        {
                            "displayText" : "Color",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "ColorPanel"
                            }
                        },
                        {
                            "displayText" : "Components",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "ComponentsPanel"
                            }
                        },
                        {
                            "displayText" : "CSS",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "CSSPanel"
                            }
                        },
                        {
                            "displayText" : "Materials",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "MaterialsPanel"
                            }
                        },
                        {
                            "displayText" : "Presets",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "checked": {
                                "value": true,
                                "boundProperty": "PresetsPanel"
                            }
                        },
                        {
                            "displayText" : "Code",
                            "hasSubMenu" : false,
                            "enabled": true
                        }
                    ]
                },
                {
                    "header": "Help",
                    "entries": [
                        {
                            "displayText" : "Ninja FAQ",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executeHelpFAQ"
                        },
                        {
                            "displayText" : "Ninja Forums",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executeHelpForums"
                        },
                        {
                            "displayText" : "Help Topics",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executeHelpTopics"
                        },
                        {
                            "displayText" : "About Ninja...",
                            "hasSubMenu" : false,
                            "enabled": true,
                            "action":   "executeHelpAbout"
                        }
                    ]
                }
            ]
    }
});