"use strict";
appCore.controller("EmailTemplateListCtrl", ["$state", "$scope", "$http", "$timeout", "$uibModal", "vServices", function($state, $scope, $http, $timeout, $uibModal, vServices) {
        $scope.$root.page.title = "List of Email templates";
        $scope.testHeroEmail = '';
        const init = function() {
            vServices.callApi("employee/all_email_templates", "GET", {}).then(function(res) {
                if (res && res.length > 0) {
                    $scope.emailtemplates = res;
                    $scope.$root.callDataTable("#emailtemplateList");
                }
            });
        };
        init();
        $scope.openEmailPopup = (jsonQ, idx = null) => {
            let modalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'sendEmailTemp77.html',
                controller: 'sendEmailTempCtrl77',
                size: 'xl',
                controllerAs: "$scope",
                backdrop: "static",
                keyboard: false,
                resolve: {
                    data: () => {
                        return {
                            single: JSON.parse(JSON.stringify(jsonQ))
                        };
                    }
                }
            });
            modalInstance.result.then(function() {
                toastr.success('Mails Send successfully to heroes.');
            }, () => {

            });
        };
    }])
    .controller('sendEmailTempCtrl77', function($scope, $uibModalInstance, data, vServices) {
        $scope.cancel = () => $uibModalInstance.dismiss(false);
        $scope.data = data;
        $scope.mInfo = {
            head_icon: "fas fa-plus-circle",
            head_title: "Sent Email",
            btn_icon: "fas fa-save",
            btn_title: "Send Mail",
            today: new Date()
        };
        $scope.send = () => {
            $scope.data.email = $scope.testHeroEmail;
            vServices.callApi("/employee/emailTestingToHero", "POST", {
                myval: JSON.stringify($scope.data)
            }).then(data => {
                if (data) {
                    toastr.success("Email has been sent successfully.", "Success");
                    $uibModalInstance.dismiss(false);
                }
            });
        }
    })