import {
    WzStepDirective
} from './step.directive';
import {
    WizardDirective
} from './wizard.directive';

import './wizard.less';

angular.module('cil-wizard', [])
    .directive('wzStep', WzStepDirective)
    .directive('wizard', WizardDirective)
    .directive('wzNext', function () {
        return {
            restrict: 'A',
            replace: false,
            require: '^wizard',
            link: function ($scope, $element, $attrs, wizard) {
                $element.on("click", function (e) {
                    e.preventDefault();
                    $scope.$apply(function () {
                        $scope.$eval($attrs['wzNext']);
                        wizard['wzNext'.replace("wz", "").toLowerCase()]();
                    });
                });
            }
        };
    })
    .directive('wzPrevious', function () {
        return {
            restrict: 'A',
            replace: false,
            require: '^wizard',
            link: function ($scope, $element, $attrs, wizard) {
                $element.on("click", function (e) {
                    e.preventDefault();
                    $scope.$apply(function () {
                        $scope.$eval($attrs['wzPrevious']);
                        wizard['wzPrevious'.replace("wz", "").toLowerCase()]();
                    });
                });
            }
        };
    })
    .directive('wzFinish', function () {
        return {
            restrict: 'A',
            replace: false,
            require: '^wizard',
            link: function ($scope, $element, $attrs, wizard) {
                $element.on("click", function (e) {
                    e.preventDefault();
                    $scope.$apply(function () {
                        $scope.$eval($attrs['wzFinish']);
                        wizard['wzFinish'.replace("wz", "").toLowerCase()]();
                    });
                });
            }
        };
    })
    .directive('wzCancel', function () {
        return {
            restrict: 'A',
            replace: false,
            require: '^wizard',
            link: function ($scope, $element, $attrs, wizard) {
                $element.on("click", function (e) {
                    e.preventDefault();
                    $scope.$apply(function () {
                        $scope.$eval($attrs['wzCancel']);
                        wizard['wzCancel'.replace("wz", "").toLowerCase()]();
                    });
                });
            }
        };
    })
    .directive('wzReset', function () {
        return {
            restrict: 'A',
            replace: false,
            require: '^wizard',
            link: function ($scope, $element, $attrs, wizard) {
                $element.on("click", function (e) {
                    e.preventDefault();
                    $scope.$apply(function () {
                        $scope.$eval($attrs['wzReset']);
                        wizard['wzReset'.replace("wz", "").toLowerCase()]();
                    });
                });
            }
        };
    })
    .factory('WizardHandler', function () {
        var service = {};
        var wizards = {};
        service.defaultName = "defaultWizard";
        service.addWizard = function (name, wizard) {
            wizards[name] = wizard;
        };

        service.removeWizard = function (name) {
            delete wizards[name];
        };

        service.wizard = function (name) {
            var nameToUse = name;
            if (!name) {
                nameToUse = service.defaultName;
            }

            return wizards[nameToUse];
        };

        return service;
    });
// angular.module('cil-wizard', ['templates-angularwizard']);