define(['app'], function (app) {
    'use strict';

    app.factory('$illustration', function ($http, $rootScope) {
        // data format: {'id_cate1': {name: '', list: [item1,item2]}, ...}
        // item format: {name: '', path: ''}
        var DATA = {
            'cate1': {
                name: 'category #1',
                list: [
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 5',
                        path: 'images/illustrations/item6.svg'
                    },
                    {
                        name: 'item 6',
                        path: 'images/illustrations/item7.svg'
                    },
                    {
                        name: 'item 7',
                        path: 'images/illustrations/item8.svg'
                    },
                    {
                        name: 'item 8',
                        path: 'images/illustrations/item9.svg'
                    },
                    {
                        name: 'item 9',
                        path: 'images/illustrations/item10.svg'
                    },
                    {
                        name: 'item 10',
                        path: 'images/illustrations/item11.svg'
                    },
                    {
                        name: 'item 11',
                        path: 'images/illustrations/item12.svg'
                    },
                    {
                        name: 'item 12',
                        path: 'images/illustrations/item12.svg'
                    },
                    {
                        name: 'item 13',
                        path: 'images/illustrations/item13.svg'
                    },
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 6',
                        path: 'images/illustrations/item7.svg'
                    },
                    {
                        name: 'item 7',
                        path: 'images/illustrations/item8.svg'
                    },
                    {
                        name: 'item 8',
                        path: 'images/illustrations/item9.svg'
                    },
                    {
                        name: 'item 9',
                        path: 'images/illustrations/item10.svg'
                    },
                    {
                        name: 'item 10',
                        path: 'images/illustrations/item11.svg'
                    },
                    {
                        name: 'item 11',
                        path: 'images/illustrations/item12.svg'
                    },
                    {
                        name: 'item 12',
                        path: 'images/illustrations/item12.svg'
                    },
                    {
                        name: 'item 13',
                        path: 'images/illustrations/item13.svg'
                    }
                ]
            },
            'cate2': {
                name: 'category #2',
                list: [
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item5.svg'
                    },
                    {
                        name: 'item 5',
                        path: 'images/illustrations/item6.svg'
                    },
                    {
                        name: 'item 6',
                        path: 'images/illustrations/item7.svg'
                    },
                    {
                        name: 'item 7',
                        path: 'images/illustrations/item8.svg'
                    },
                    {
                        name: 'item 8',
                        path: 'images/illustrations/item9.svg'
                    },
                    {
                        name: 'item 9',
                        path: 'images/illustrations/item10.svg'
                    },
                    {
                        name: 'item 10',
                        path: 'images/illustrations/item11.svg'
                    },
                    {
                        name: 'item 11',
                        path: 'images/illustrations/item12.svg'
                    },
                    {
                        name: 'item 12',
                        path: 'images/illustrations/item12.svg'
                    },
                    {
                        name: 'item 13',
                        path: 'images/illustrations/item13.svg'
                    }
                ]
            }
        };

        return {
            loadFromRemote: function (params,successHandle,errorHandle) {
                // return format: { status:0|1 , data:{} }
                var httpObj = $http({
                    url: $rootScope.API_URL+'/apiv1/illustration',
                    method: 'GET',
                    params: params || []
                });
                if (typeof successHandle == 'undefined'){
                    successHandle = function(response){
                        if (response.status==1){
                            DATA = response.data;
                        }
                    }
                }
                httpObj.success(successHandle);
                
                if (typeof errorHandle != 'undefined'){
                    httpObj.error(errorHandle);
                }
            },
            getAll: function(){
                return DATA;
            },
            getList: function(category){
                if (typeof DATA[category] == 'undefined'){
                    return [];
                }
                return DATA[category];
            }
        };
    });
});
