(function () {
    "use strict";

    angular
        .module("header.component", [])
        .component("header", {
            templateUrl: "app/widgets/header/header.component.html",
            controller: HeaderComponent,
            controllerAs: "vm"
        });

    HeaderComponent.$inject = [
        "$scope",
        "$mdSidenav",
        "common"
    ];

    function HeaderComponent($scope, $mdSidenav, common) {
        var vm = this;
        vm.openSideMenu = openSideMenu;
        vm.menuGoToLink = menuGoToLink;
        vm.title = "韵逸轩·中茶汇北美总代理";
        vm.engTitle = "China Tea";
        vm.email = "sales@zctea.ca";
        vm.logoUrl = "img/logo.png";

        vm.currentNavItem = "products";
        $scope.$watch(common.getUrlHash, function (newVal) {
            switch (newVal) {
                case "#!/aboutPuErh":
                    vm.currentNavItem = "about-pu-erh";
                    break;
                case "#!/aboutUs":
                    vm.currentNavItem = "about-us";
                    break;
                case "#!/contactUs":
                    vm.currentNavItem = "contact-us";
                    break;
                case "#!/products":
                    vm.currentNavItem = "products";
                    break;
                default:
                    vm.currentNavItem = "";
            }
        });

        function openSideMenu() {
            $mdSidenav("nav-menu").toggle();
        }

        function menuGoToLink(link) {
            common.openLink(link);
            $mdSidenav("nav-menu").close();
        }
    }
})();
