{% extends base_template %}
{% load djblets_extensions djblets_js pipeline %}

{% block review_ui_css %}
{%  if not skip_static_media %}
{%   for bundle_name in review_ui.css_bundle_names %}
{%    comment %}
NOTE: On Review Board local development servers, rendering review UI static
      media from installed extension packages is broken when running with
      Djblets <4.1 and <5.3. Using development setups of extension
      packages works fine, and this is not an issue on production servers.

      Using `ext_css_bundle` here and `ext_js_bundle` below fixes the issue
      when running with Djblets >=4.1 and >=5.3. If in any case this is
      being run with a lower Djblets version, then the `bundle_output` will
      be empty and we'll fall back on using the `javascript` template tag
      which will do the right thing on production servers.
{%    endcomment %}
{%    if review_ui.extension %}
{%     ext_css_bundle review_ui.extension bundle_name as bundle_output %}
{%    endif %}
{%    if bundle_output %}
{{bundle_output}}
{%    else %}
{%     stylesheet bundle_name %}
{%    endif %}
{%   endfor %}
{%  endif %}
{% endblock %}

{% block review_ui_scripts %}
{%  if not skip_static_media %}
{%   for bundle_name in review_ui.js_bundle_names %}
{%    if review_ui.extension %}
{%     ext_js_bundle review_ui.extension bundle_name as bundle_output %}
{%    endif %}
{%    if bundle_output %}
{{bundle_output}}
{%    else %}
{%     javascript bundle_name %}
{%    endif %}
{%   endfor %}
{%   for js_file in review_ui.js_files %}
<script src="{{js_file}}"></script>
{%   endfor %}
{%  endif %}

<script>
    $(document).ready(function() {
        RB.PageManager.ready(function(page) {
{%  block review_ui_setup %}
            var view = new {{review_ui.js_view_class}}({
{%   block review_ui_view_params %}{% endblock %}
{%   for key, value in review_ui.get_js_view_data.items %}
                {{key|json_dumps}}: {{value|json_dumps}},
{%   endfor %}
                model: new {{review_ui.js_model_class}}({
{%   for key, value in review_ui.get_js_model_data.items %}
                    {{key|json_dumps}}: {{value|json_dumps}},
{%   endfor %}
                    caption: '{{caption|escapejs}}',
                    reviewRequest: page.model.get('reviewRequest'),
                    serializedCommentBlocks: {{review_ui.get_comments_json|safe}}
                })
            });

{%   block review_ui_render %}
            $('#review_ui_{{review_ui_uuid}}').append(view.$el);
            view.render();
{%   endblock %}
{%  endblock %}
        });
    });
</script>
{% endblock %}

{% block review_ui_box_content %}
<div id="review_ui_{{review_ui_uuid}}">
{%  block review_ui_box_content_inner %}{% endblock %}
</div>
{% endblock %}
