"use strict";

appCore.controller("heroReopeningBookingCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", '$filter',"filterFilter", "$uibModal", function ($state, $scope, $http, $timeout, vServices, $filter,filterFilter, $uibModal) {
    $scope.params = $state.params;
    $scope.$root.page.title = "Hero Feedback";
    $scope.createButton = {heading: "Add", text: "Save", icon: "fa-save", today: new Date()};
    $scope.reopeningBooking = {'booking_info': '', 'booking_date': '', booking_team_members:'','emp_id': $scope.params.employeeid};
    $scope.heroFeedbackList = null;
    $scope.heroProjectReleaseFeedbackList = null;
    $scope.hero = null;
    $scope.today = $filter('date')(new Date(), 'yyyy-MM-dd');

// Disable weekend selection
    $scope.disabled = function (date, mode) {
        return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
    };
    $scope.Save = () => {
        let data = $scope.reopeningBooking;
        if (data.booking_date !== '' && data.booking_info !== '' && data.emp_id !== null) {
            vServices.callApi("employee/addHeroOfficeReopeningBooking", "POST", data).then((res) => {
                if (res) {
                    $state.go("heroReopeningBooking", {}, {reload: true});
                }
            });
        } else toastr.error('Unable to submit partially filled data, kindly validate.');
    }, (e) => {
        console.log(e);
    };
    const init = () => {
        vServices.callApi("employee/" + $scope.params.employeeid, "GET", {}).then((res) => {
            if (res) {
                $scope.hero = res;
            }
        });
        vServices.callApi("employee/hero_office_reopening_booking/" + $scope.params.employeeid, "GET", {}).then((res) => {
            if (res) {
                $scope.heroFeedbackList = res;
                $scope.$root.callDataTable("#heroFeedbackList", 1000);
            }
        });
    };
    init();

    /* Model code start*/
    $scope.openheroFeedbackDeleteDeleteModal = (obj) => {
        let modalInstance = $uibModal.open({
            animation: true,
            ariaLabelledBy: "modal-title",
            ariaDescribedBy: "modal-body",
            templateUrl: "heroFeedbackDelete.html",
            controller: "heroFeedbackDeleteCtrl",
            controllerAs: "$scope",
            size: "md",//sm md lg
            backdrop: "static",
            resolve: {
                data: obj
            }
        });
        modalInstance.result.then((data) => {
            $scope.heroFeedbackDelete(data);
        }, () => {
            toastr.warning("Action has been canceled", "Cancel");
        });
    };
    /* Model code end*/
    $scope.heroFeedbackDelete = (e) => {
        vServices.callApi("employee/hero_office_reopening_booking/" + e.employeeofficereopeningbookingid, "DELETE", {}).then((res) => {
            toastr.success(res, "Success");
            $state.go($state.current, {}, {reload: true});
        });
    };
}]).controller("heroFeedbackDeleteCtrl", function ($uibModalInstance, data, $scope) {
    $scope.data = data;
    $scope.delHeroFeedback = (d) => $uibModalInstance.close(d);
    $scope.cancel = () => $uibModalInstance.dismiss("cancel");
});

;
