"use strict";

/*global module, require*/

var modalDialogueFactory = require("./processes/modal-dialogue.js"),
    commentFactory = require("./accordion-comment.js"),

    online = {
	online: true,
	offline: false
    },

    standalone = {
	embedded: false,
	standalone: true
    }; 

module.exports = function(store, specifyButton, closeFileMenu) {
    var modalDialogueProcess = modalDialogueFactory(closeFileMenu);
    
    return specifyButton(
	"Delete",
	null,
	function(wasActive, buttonProcess, onProcessEnd) {
	    if (store.getTitle()) {
		var submit = function() {
		    store.deleteDocument(
			store.getTitle()
		    );

		    // ToDo do something with this.
		    // comment.getComment();
		    
		    dialogue.exit();
		},

		    dialogue = modalDialogueProcess(wasActive, buttonProcess, onProcessEnd, submit),

		    head = dialogue.element.append("h4")
			.text("Delete '" + store.getTitle() + "'"),

		    comment = commentFactory(dialogue.element),
		    
		    action = dialogue.element.append("div")
			.classed("dialogue-action", true)
			.attr("delete-action", true)
			.on("click", submit)
			.text("Delete");

		return dialogue;
	    } else {
		return null;
	    }
	},
	{
	    onlineOffline: online,
	    embeddedStandalone: standalone,
	    search: {}
	}
    );
};

@@ -1266,17 +1266,92 @@
     
-search: %7B
+readWriteSync: %7B%0A%09%09untitled: false,%0A%09%09read: false,%0A%09%09write: true,%0A%09%09sync: true%0A%09    
 %7D%0A%09%7D

Delete button enabled on the right occasions.