﻿app.controller('documentController', function ($scope, $http, $window) {
    var lang = ($('#langPath_2').val() == "vi") ? 'VN' : $('#langPath_2').val();
    $scope.rowbg = null;
    $scope.Data = {};
    $scope.Url = '';
    $scope.language = lang;

    $scope.Search = function (type = 1, ele, url) {
        if (url != '') { $('#' + ele).attr('href', url); }
        $scope.IsVisible = false;
        var data = {
            type: type,
            token: $('input[name=access_token]').val()
        };
        var post = $http({
            method: "POST",
            url: "https://api.thuvienphapluat.com/Document/HomeDocument",
            dataType: 'json',
            data: data,
            headers: { "Content-Type": "application/json" }
        }).then(function (rs, status) {
            $scope.Data = rs.data;
            $scope.IsVisible = true;
            setTimeout(function () {
                $('[data-toggle="popover"]').popover({ html: true });
            }, 200)
        }, function (data, status) {
            $scope.IsVisible = true;
            //$window.alert(data.Message);
        });
    }
    $scope.Datahomedoc = {};
    $scope.Urlhomedoc = '';
    $scope.Init = function (type) {
        $scope.isvisible = false;
        var data = {
            type: type,
            token: $('#token').val()
        };
        var post = $http({
            method: "post",
            url: $('#domain').val() + "/home-document" + "?type=" + data.type + "&language=" + lang + "&top=5&token=" + data.token + "&secretkey=" + $('#secretkey').val(),
            datatype: 'json',
            data: data,
            headers: { "content-type": "application/json" }
        }).then(function (rs, status) {
            $scope.Datahomedoc = rs.data;
            $scope.IsVisible = true;
            //settimeout(function () {
            //    $('[data-toggle="popover"]').popover({ html: true });
            //}, 200)
        }, function (data, status) {
            $scope.isvisible = true;
            //$window.alert(data.message);
        });
    }
    $scope.tab1 = 2;
    $scope.tab2 = 8;
    $scope.tab3 = 6;
    $scope.Changetab = function (index, tab) {
        if (index == 1) {
            $scope.tab1 = tab;
        }
        if (index == 2) {
            $scope.tab2 = tab;
        }
        if (index == 3) {
            $scope.tab3 = tab;
        }
    }
    $scope.showmore = function (index) {
        var tab = -1;
        //chia thành 3 componet
        if (index == 1) {
            tab = $scope.tab1;
        }
        if (index == 2) {
            tab = $scope.tab2;
        }
        if (index == 3) {
            tab = $scope.tab3;
        }
        var isEN = window.location.href.includes("/en") || window.location.href.includes("/en/") ? 1 : 0;
        //var url = isEN ? "en/Home/ShowMore?DocType=" + $scope.tab + "" : "/Home/ShowMore?DocType=" + $scope.tab + "";
        var url = "/Home/ShowMore?DocType=" + tab + "&EN="+isEN+"";
        window.location.href = url;
        
    };
});

