<%! from django.utils.translation import ugettext as _ %>
<%namespace name='static' file='../../static_content.html'/>
<%page args="tabName"/>

<%
import json
%>

## include js templates:

% for template_name in ["metadata-videolist-entry", "file-upload"]:
    <script type="text/template" id="${template_name}">
        <%static:include path="js/transcripts/${template_name}.underscore" />
    </script>
% endfor

% for template_name in ["transcripts-found", "transcripts-uploaded", "transcripts-use-existing", "transcripts-not-found", "transcripts-replace", "transcripts-import", "transcripts-choose"]:
    <script type="text/template" id="${template_name}">
        <%static:include path="js/transcripts/messages/${template_name}.underscore" />
    </script>
% endfor

<div class="wrapper-comp-settings basic_metadata_edit" data-metadata='${json.dumps(transcripts_basic_tab_metadata) | h}'></div>

<script type="text/javascript">
    require(
        [
            "domReady!",
            "jquery",
            "js/views/transcripts/editor"
        ],

        function(doc, $, Editor) {
            var transcripts = new Editor({
                    el: $('#editor-tab-${html_id}').find('.basic_metadata_edit')
                }),
                storage = TabsEditingDescriptor.getStorage();

            TabsEditingDescriptor.Model.addModelUpdate(
                '${html_id}',
                '${tabName}',
                function () {
                    // Advanced, Save
                    metadataEditor = storage.MetadataEditor;

                    if (metadataEditor) {
                        transcripts.syncAdvancedTab(metadataEditor.collection, metadataEditor);
                    }
                }
            );

            TabsEditingDescriptor.Model.addOnSwitch(
                '${html_id}',
                '${tabName}',
                function () {
                    // Basic
                    metadataEditor = storage.MetadataEditor;

                    if (metadataEditor) {
                        transcripts.syncBasicTab(metadataEditor.collection, metadataEditor);
                    }
                }
            );
        }
    );
</script>
