{"size": 1362, "ext": "js", "max_stars_repo_path": "src/js/services/twitter.js", "max_stars_repo_name": "gabel/shariff", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/services/twitter.js", "max_issues_repo_name": "gabel/shariff", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/js/services/twitter.js", "max_forks_repo_name": "gabel/shariff", "max_forks_repo_forks_event_min_datetime": "2018-11-20T13:53:14.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-20T13:53:14.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 32.4285714286, "max_line_length": 110, "alphanum_fraction": 0.577092511}
'use strict';

var url = require('url');

module.exports = function (shariff) {
    var shareUrlFn = function (_url) {
        var shareUrl = url.parse('https://twitter.com/intent/tweet', true);

        // TODO FIXME: remove "encodeURIComponent()" from getShareText()
        shareUrl.query.text = decodeURIComponent(shariff.getShareText());
        shareUrl.query.url = _url ? _url : shariff.getURL();
        if (shariff.options.twitterVia !== null) {
            shareUrl.query.via = shariff.options.twitterVia;
        }
        delete shareUrl.search;

        return shareUrl;
    };

    var twitter = {
        popup: true,
        //TODO: better called "label" instead of shareText, the share text is the content of the tweet message
        shareText: 'tweet',
        name: 'twitter',
        faName: 'fa-twitter',
        title: {
            'de': 'Bei Twitter teilen',
            'en': 'Share on Twitter',
            'es': 'Compartir en Twitter'
        },
        // shareUrl: 'https://twitter.com/intent/tweet?text='+ shariff.getShareText() + '&url=' + url
        shareUrl: url.format(shareUrlFn(null)) + shariff.getReferrerTrack(),
        setShareUrl: function (_url) {
            if (_url) {
                this.shareUrl = url.format(shareUrlFn(_url)) + shariff.getReferrerTrack();
            }
        }
    };

    return twitter;
};
