var HuSNS = window.HuSNS || {};
HuSNS.Url = {
    _themeUrl: window.THEME_URL || '',
    _baseUrl: window.API_BASE_URL || '',
    
    page: function(name, params) {
        var base = this._getPageUrl(name);
        if (params && typeof params === 'object') {
            var queryString = new URLSearchParams(params).toString();
            if (queryString) {
                base += (base.indexOf('?') === -1 ? '?' : '&') + queryString;
            }
        }
        return base;
    },
    
    api: function(endpoint, params) {
        var base = this._baseUrl + '/' + endpoint.replace(/^\//, '');
        if (params && typeof params === 'object') {
            var queryString = new URLSearchParams(params).toString();
            if (queryString) {
                base += '?' + queryString;
            }
        }
        return base;
    },
    
    asset: function(path) {
        return this._themeUrl + '/' + path.replace(/^\//, '');
    },
    
    _getPageUrl: function(name) {
        var urlMap = {
            'mobile': '/mobile',
            'mobile/login': '/mobile/login',
            'mobile/register': '/mobile/register',
            'mobile/detail': '/mobile/detail',
            'mobile/profile': '/mobile/profile',
            'mobile/publish': '/mobile/publish',
            'mobile/hot': '/mobile/hot',
            'mobile/user': '/mobile/user',
            'mobile/chat': '/mobile/chat',
            'mobile/messages': '/mobile/messages',
            'mobile/settings': '/mobile/settings',
            'mobile/favorites': '/mobile/favorites',
            'mobile/notification': '/mobile/notification'
        };
        return urlMap[name] || '/' + name;
    }
};

if (typeof module !== 'undefined' && module.exports) {
    module.exports = HuSNS.Url;
}