### codetube
    Copyright (C) 2011 payload payload@lavabit.com
    Copyright (C) 2011 dodo dodo.the.last@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
###

@title or= @codetube.name
if @me
    user_links = do =>
        userpage = class: "userpage", href: "/"+@me.id, text: @me.id
        logout   = class: "logout"  , href: "/.logout", text: @_("logout")
        [ userpage, logout ]
else
    user_links = do =>
        login    = class: "login"   , href: "/.login"   , text: @_("login")
        register = class: "register", href: "/.register", text: @_("register")
        [ register, login ]

global_links = do =>
    users    = class: 'users'   , href: '/.users'   , text: @_("users")
    projects = class: 'projects', href: '/.projects', text: @_("projects")
    result = []
    for link, url of @config.links
        result.push class:"link", href:url, text:link
    result.concat [ users, projects ]

list_link = (link) =>
    li class: link.class, -> a href: link.href, -> link.text

@project or= @codetube
doctype 5
p = @appconfig.prefix
html ->
    head ->
        title @title
        link rel: 'stylesheet', href: "/#{p}static/css/normalize.css"
        link rel: 'stylesheet', href: "/#{p}static/css/style.css"
        link rel: 'stylesheet', href: "/#{p}static/css/jquery/jquery.ui.all.css"
        link rel: 'stylesheet', href: "/#{p}static/css/jquery/jquery.ui.base.css"
        link rel: 'stylesheet', href: "/#{p}static/css/jquery/jquery.ui.selectmenu.css"
        script @javascript
        script src: "/#{p}sio/socket.io.js"
        script src: "/#{p}static/js/require.js"
        script src: "/#{p}static/js/lift.js"
        coffeescript ->
            require './jquery'
            { client } = require './client'
            $('document').ready client.start
    body ->
        div id:'body-content', ->
            div class: 'head', -> div class: 'table', ->
                div class: 'left', ->
                    div id:'header-logo', ->
                        div id:'logo', -> '&nbsp;'
                div class: 'center', -> div class: 'title', ->
                    h1 -> a href: @project.href, -> @project.name
                    span class: 'descline', -> @project.descline
                    for name, url of @project.gitline
                        attrs =
                            class: "gitline "+name
                            type: 'text'
                            readonly: 'true'
                            value: url
                        input attrs
                div class: 'right', -> nav ->
                    ul class: 'global-links', ->
                        list_link link for link in global_links
                    div class: 'user-links', -> ul ->
                        list_link link for link in user_links
            div class: 'messages', -> ul ->
                text '&nbsp;'
                for k, msgs of @flash
                    for msg in msgs
                        li -> span class: k, -> msg
            partial(@body) if @body
            div id:'clear-footer'
        footer ->
            a id:"about-button", href: "/#{p}about", "&nbsp;"
    #@partial 'inc/outro', @outro_options or {}, text

