class ForgotPassword extends Directive('hn.enterprise')
    constructor: ($modal) ->
        success_modal = () ->
            $modal.open({
                templateUrl: '/modules/marketing/views/partials/forgot_password_success_modal.html'
                windowClass: 'forgot-password'
            })

        forgot_password_modal = (email) ->
            $modal.open({
                templateUrl: '/modules/marketing/views/partials/forgot_password_modal.html'
                ### @ngInject ###
                controller: (Flash, $scope, User) ->
                    vm = @

                    vm.request = {
                        email: email || ''
                    }

                    vm.submit = () ->
                        User.forgotPassword(vm.request)
                        .$promise
                        .then( () ->
                            success_modal()
                        , () ->
                            Flash('Oops! There was a problem with the server. Try again later.', 'error')
                        )
                        $scope.$close()
                    return
                controllerAs: 'vm'
                windowClass: 'forgot-password'
            })

        return {
            scope: {
                email: '=forgotPassword'
            },
            link: (scope, elem) ->
                elem.on('click', () ->
                    forgot_password_modal(scope.email))
        }


class RequestAccess extends Directive('hn.enterprise')
    constructor: ($modal) ->
        return {
            link: (scope, elem) ->
                elem.on('click', () ->
                    modal = $modal.open({
                        templateUrl: '/modules/marketing/views/partials/request_access_modal.html'
                        ### @ngInject ###
                        controller: ($scope, Flash, App) ->
                            vm = @

                            vm.request = {}

                            vm.submit = () ->
                                App.requestAccess(vm.request)
                                    .$promise
                                    .then( () ->
                                        Flash('Request sent!', 'success')
                                    , () ->
                                        Flash('Oops! There was a problem with the server. Try again later.', 'error')
                                    )

                                $scope.$close()
                            return
                        controllerAs: 'vm'
                        windowClass: 'request-access'
                    })
                )
        }
