window.angularApp.factory("ProductWarrantyInfoModal", ["API_URL", "window", "jQuery", "$http", "$uibModal", "$sce", "$rootScope", function (API_URL, window, $, $http, $uibModal, $sce, $scope) {
    return function($scope) {
        var uibModalInstance = $uibModal.open({
            animation: true,
            ariaLabelledBy: "modal-title",
            ariaDescribedBy: "modal-body",
            template: '<div class="modal-header">\
            <h5 class="modal-title" id="exampleModalLabel">Warranty Details</h5>\
            <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="closeAddNoteModal();">\
            <span aria-hidden="true">&times;</span>\
            </button>\
            </div>\
            <div class="modal-body">\
            <div class="row form-group">\
            <label for="period" class="col-sm-3 control-label">Waranty Period</label>\
            <div class="col-sm-9">\
            <input type="text" id="period" value="'+$scope.warrantyText+'" class="form-control" disabled>\
            </div>\
            </div>\
            <div class="row form-group">\
            <label for="warrantySerialText" class="col-sm-3 control-label">Product Serial</label>\
            <div class="col-sm-9">\
            <input type="text" Placeholder="Enter Product Serial Numbers Ex: 123456789,987654321,-----"  value="'+$scope.warrantySerialText+'" id="warrantySerialText" class="form-control">\
            </div>\
            </div>\
            </div>\
            <div class="modal-footer">\
            <button type="button" class="btn btn-primary" ng-click="closeAddNoteModal();">Submit</button>\
            </div>',
            controller: function ($scope, $uibModalInstance) {
                
                var warrantySerialText;
                $(document).on("change keyup blur", "#warrantySerialText", function () {
                    var $this=$(this);
                    warrantySerialText=$this.val();
                    //console.log('warrantySerialText')
                    //console.log(warrantySerialText)
                    var id=$scope.warrantyTarget;
                    var find = window._.find($scope.itemArray, function (item) {
                        return item.id==id;
                    });
                    if(find){
                        window._.map($scope.itemArray,function(item){
                            if (item.id==id){
                                item.warrantySerialText=warrantySerialText;
                            }
                        });
                    }


                });
                $scope.closeAddNoteModal = function () {
                    $uibModalInstance.dismiss("cancel");
                };
                $scope.clear = function () {
                    //$("#invoice-note").data("note", "");
                    $uibModalInstance.dismiss("cancel");
                };
            },
            scope: $scope,
            size: "md",
            backdrop  : "static",
            keyboard: true,
        });
        uibModalInstance.result.catch(function () { 
            uibModalInstance.close(); 
        });
    };
}]);