define('bitbucket/internal/widget/list-branches-help-dialog', [
    'aui',
    'jquery',
    'lodash'
], function (
    AJS,
    $,
    _
) {

    var dialog;

    function createListBranchesHelpDialog(commitId) {
        var dialog = new AJS.Dialog({
            width: 600,
            height: 480,
            id: "list-branches-dialog",
            closeOnOutsideClick: true
        }).addHeader(AJS.I18n.getText('feature.stash.branchInfo.commit.help.header'));

        dialog.addPanel('',
            feature.stash.branchInfo.commit.listBranchesHelp({
                commitId: commitId
            }));

        dialog.addCancel(AJS.I18n.getText('bitbucket.web.button.close'), _.bind(dialog.hide, dialog));

        return dialog;
    }

    function removeDialog() {
        $(document).off('hideLayer', removeDialog);
        if (dialog) {
            dialog.remove();
            dialog = null;
        }
    }

    return {
        showFor: function (commitId) {
            removeDialog();
            $(document).on('hideLayer', removeDialog);
            dialog = createListBranchesHelpDialog(commitId);
            dialog.show();
            dialog.updateHeight();
        }
    };
});
