'use strict';

angular.module('qusion.cms.layout.services', [])
    .service('PageLayoutService', [
        '$q',
        function ($q) {

            function getGroup(arr, val) {
                for (var i = 0; i < arr.length; i++) {
                    if (arr[i].Name === val)
                        return arr[i];
                }
                return null;
            }

            return {
                getToolboxWidgets: function () {
                    var items = [
                            { group: 'Content', title: 'Html/Text', controller: 'html', action: 'index' , className: '' },
                            { group: 'Content', title: 'Miroslav', controller: 'html', action: 'miro' , className: '' },
                            { group: 'Content', title: 'Image', controller: 'image', action: 'index', className: '' },
                            { group: 'Content', title: 'Image gallery', ID: '003', className: '' },
                            { group: 'Content', title: 'Video', ID: '003', className: '' },
                            { group: 'Content', title: 'Video gallery', ID: '003', className: '' },
                            { group: 'Content', title: 'Document', ID: '003', className: '' },
                            { group: 'Content', title: 'Document library', ID: '003', className: '' },
                            { group: 'Content', title: 'News list', ID: '003', className: '' },
                            { group: 'Content', title: 'News details', ID: '004', className: '' },
                            { group: 'Content', title: 'Blogs list', ID: '001', className: '' },
                            { group: 'Content', title: 'Blog post', ID: '002', className: '' },
                            { group: 'Content', title: 'Events', ID: '002', className: '' },
                            { group: 'Navigation', title: 'Site map', ID: '002', className: '' },
                            { group: 'Navigation', title: 'Menu', ID: '002', className: '' },
                            { group: 'Navigation', title: 'Breadcrumb', ID: '002', className: '' },
                            { group: 'Storage', title: 'Google Drive', ID: '002', className: '' },
                            { group: 'Storage', title: 'Sky Drive', ID: '002', className: '' },
                            { group: 'Storage', title: 'Dropbox', ID: '002', className: '' },
                            { group: 'Social', title: 'Facebook', ID: '002', className: '' },
                            { group: 'Social', title: 'Google +', ID: '002', className: '' },
                            { group: 'Social', title: 'Twitter', ID: '002', className: '' },
                            { group: 'Social', title: 'Pinterest', ID: '002', className: '' },
                            { group: 'Classification', title: 'Categories', ID: '002', className: '' },
                            { group: 'Classification', title: 'Tags', ID: '002', className: '' },
                            { group: 'Classification', title: 'Other', ID: '002', className: '' },
                            { group: 'Search', title: 'Search form', ID: '002', className: '' },
                            { group: 'Search', title: 'Search results', ID: '002', className: '' }
                    ];

                    //var widgets = [];

                    var deferred = $q.defer();
                    var promise = deferred.promise;

                    //for (var i = 0; i < resource.length; i++) {
                    //    var group = getGroup(widgets, resource[i].Group);
                    //    if (!group) {
                    //        group = { Name: resource[i].Group, Items: [] };
                    //        widgets.push(group);
                    //    }
                    //    group.Items.push(resource[i]);
                    //}

                    deferred.resolve(items);
                    return promise;
                }
            };

        }
    ]);