/*
 * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*global console */

/**
 * @class Helpers
 */
function Helpers() {
    'use strict';
    return;
}

(function strict() { // strict mode wrapper
    'use strict';

    var extensionsMimeTypes = {
            '.jpg': 'image/*',
            '.png': 'image/*',
            '.gif': 'image/*',
            '.mp4': 'video/*',
            '.ogv': 'video/*',
            '.avi': 'video/*',
            '.mp3': 'audio/*',
            '.txt': 'text/*',
            '.doc': 'text/*',
            '.html': 'text/*',
            '.ppt': 'text/*',
            '.xls': 'text/*',
            '.pdf': 'text/*'
        },

        iconFileByExtension = {
            '.jpg': 'myfile_images.png',
            '.png': 'myfile_images.png',
            '.gif': 'myfile_images.png',
            '.pdf': 'myfile_pdf.png',
            '.mp3': 'myfile_music.png',
            '.avi': 'myfile_video.png',
            '.mp4': 'myfile_video.png',
            '.mkv': 'myfile_video.png',
            '.ppt': 'myfile_ppt.png',
            '.txt': 'myfile_text.png',
            '.doc': 'myfile_word.png',
            '.xls': 'myfile_excel.png',
            '.html': 'myfile_html.png',
            '.htm': 'myfile_html.png',
            '.svg': 'myfile_svg.png',
            '.swf': 'myfile_swf.png'
        };


    Helpers.prototype = {

        getSourceName: function Helpers_getSourceName(url) {
            console.log('Helpers_getSourceName: ' + url);
            return url.split('/').pop();
        },

        getFileExtension: function Helpers_getFileExtension(fileName) {
            var splittedFileName = fileName.split('.'), ext = '';
            if (splittedFileName.length > 1) {
                ext = '.' + splittedFileName.pop();
            }
            return ext;
        },

        resolveMimeType: function Helpers_resolveMimeType(ext) {
            return extensionsMimeTypes[ext.toLowerCase()] || '';
        },

        resolveFileIcon: function Helpers_resolveFileIcon(ext) {
            return iconFileByExtension[ext.toLowerCase()] ||
                'myfile_unsupport.png';
        }

    };
}());
