 {Preflight} = require "../membrane/preflight"
 {GoogleFonts} = require "../exposure/fonting"
 
-# This is an abstract base class compound that exhibist the zombie
+# This is an abstract base class compound that exhibits the zombie
 # behavior. It is intended as the abstraction to build window-ish
-# auxiliary services upon it. Basically, if you have thhe service
-# that needs to be presented as a window (modal) and is used like
-# zombie, then this class can be used to reduce the boilerplate.
+# auxiliary services upon it. Basically, if you have the service
+# that needs to be presented as the modal window and is used like
+# a zombie, then this class can be used to reduce the boilerplate.
 module.exports.WithinModal = class WithinModal extends Zombie
 
     # This is a marker that indicates to some internal subsystems

        this.positive.prepend $("<span>").text "confirm"
        assert @positive.addClass "right labeled icon"
        assert @actions.append @negative, @positive
        this.emit "actions", @actions, @window; @

    # This method creates the basic window skeleton with all parts
    # required being assembled inside of it. The method is being
    # invoked when the instance emits the `dcoument` event that is
    # being fired once the DOM is ready to be used. You can bind
    # this same method to any other events you may wish to trap.
    modalWindow: @awaiting "document", ->
        assert @header = $ "<div>", class: "header"
        assert @content = $ "<div>", class: "content"
        assert @actions = $ "<div>", class: "actions"
        assert @window = $ "<div>", class: "ui modal"
        assert @closer = $ "<i>", class: "close icon"
        this.on "toggle", => this.window.modal "toggle"
        this.on "show", => return @window.modal "show"
        this.on "hide", => return @window.modal "hide"
        this.window.append @closer, @header, @content
        this.window.appendTo $(document.body) or null
        @modalActions(); this.window.append @actions
        @emit "configure-window", @window; return @

    # with a couple of default buttons/actions: the positive and the
    # negative, with the respectful semantics. See the coding about
    # the signals emited. Override this is you need custom buttons.
    assembleModalActions: external ->
        assert stop = (e) -> e.stopImmediatePropagation()
        @negative = $ "<div>", class: "ui negative button"
        @positive = $ "<div>", class: "ui positive button"
