class window.UserCtrl extends BaseCtrl
    constructor: (@$scope, @$state, @Dock, @Constants, @$injector) ->
        super()

        if not @Dock.hasBoard()
            @$state.go(@Constants.routes.home)
        @hasError = false
        @termsAgree = false

    continue: ->
        if @$scope.usernameForm.$valid
            @hasError = false;
            @formatName()
        else
            @hasError = true

    formatName: ->
        names = @Dock.data.userInfo.full_name.split(" ")
        if @isArray(names)
            @Dock.data.userInfo.first_name = names[0]
            @Dock.data.userInfo.last_name = ""

            for name in names.slice(1)
                @Dock.data.userInfo.last_name += name + " "
            if @Dock.data.board.item_type == 'video'
                @$state.go(@Constants.routes.videoupload, {boardId: @boardId})
            else
                if @isAndroidNative()
                    console.log 'Going to transloadit page'
                    @$state.go(@Constants.routes.upload_photo_transloadit, {boardiId: @boardId})
                else
                    @$state.go(@Constants.routes.upload, {boardId: @boardId})
        else
            @hasError = true

    isAndroidNative: ->
        # Someone could say: use feature detection blablabla
        # but android native browser pretends to support FileAPI
        # Problem is it has BUG in this feature!
        nua = navigator.userAgent
        (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1)




UserCtrl.$inject = ["$scope", "$state", "Dock", "Constants", "$injector"]

angular.module("shuttlerockApp").controller("UserCtrl", UserCtrl)
