<script id="namespace_view-replica-template" type="text/x-handlebars-template">
    <h2 class="title">Replication status</h2>
    <div class="progress_bar_container"></div>
    <div class="replica-status"></div>
    <h2 class="title">Replication settings</h2>
    <div class="alert alert-error no_datacenter_found"><p>The primary datacenter of this table was not found. Please specify another primary datacenter (or Universe).</p></div>
    <div class="alert alert-error ack_greater_than_replicas"></div>
    <div class="cluster_container"></div>
    <a href="#" class="toggle-mdc show-mdc">Show multi-datacenter options</a>
    <a href="#" class="toggle-mdc hide-mdc">Hide multi-datacenter options</a>
    <div class="mdc-options hidden">
        <div class="row-fluid">
            <div class="span3 tabbable tabs-left datacenters_list_container"></div>
            <div class="span9 tab-content datacenter_content"></div>
        </div>
        <div class="primary-dc"></div>
    </div>
</script>

<script id="namespace_view-acks_greater_than_replicas-template" type="text/x-handlebars-template">
    <p>The acks for the {{pluralize_noun "table" num_datacenters_with_issues}} {{links_to_datacenters_inline_for_replica datacenters_with_issues}} are greater than the number of replicas.</p>
</script>

<script id="namespace_view-replica-datacenters_list-template" type="text/x-handlebars-template">
    <div class="datacenter_list_container">
        {{#each datacenters}}
        <div class="datacenter_tab {{#if active}} active {{/if}}{{#if is_universe}} universe{{/if}}">
            <a href="#tables/{{namespace_id}}/{{id}}" data-datacenter_id="{{id}}" class="nav_datacenter">{{name}}</a>
        </div>
        {{/each}}
    </div>
</script>

<script id="namespace_view-universe_replica-template" type="text/x-handlebars-template">
    <div class="cluster-info replica_container">
        <div class="replicas_acks-alert alert alert-error"></div>
        <div class="status-alert alert"></div>
        {{#if editable}}
            <button class="cancel btn">&times;</button>
            <button class="save update-replicas btn">Update</button>
        {{else}}
            <button class="edit btn">Edit</button>
        {{/if}}
        <div class="cluster-replicas">
            {{#if editable}}
                <p>
                    <input type="text" id="replicas_value" value="{{replicas}}" class="inline_edit_input">
                    <span class="caption">replicas</span>
                </p>
                <p class="max-value">max replicas: {{max_replicas}}</p>
            {{else}}
                <p><span class="value">{{replicas}}</span> <span class="caption">replicas</p>
            {{/if}}
        </div>
        <div class="cluster-acks">
            {{#if editable}}
                <p>
                    <input type="text" id="acks_value" value="{{acks}}" class="inline_edit_input">
                    <span class="caption">write acks</span>
                </p>
                <p class="max-value">max acks: {{max_acks}}</p>
            {{else}}
                <p><span class="value">{{acks}}</span> <span class="caption">write acks</span></p>
            {{/if}}
        </div>
    </div>
</script>

<script id="namespace_view-replica-no_datacenter-template" type="text/x-handlebars-template">
    <div class="dc-info">
        <p>You do not have any datacenters.<br/><a href="#servers">Create</a> a datacenter if you want to use this option.</p>
    </div>
</script>

<script id="namespace_view-datacenter_replica-template" type="text/x-handlebars-template">
    <div class="dc-info">
        <p class="value">{{name}}</p>
        <p class="caption">Datacenter</p>
    </div>
    <div class="dc-info replica_container">
        <div class="replicas_acks-alert alert alert-error"></div>
        {{#if editable}}
            <button class="cancel btn">&times;</button>
            <button class="save update-replicas btn">Update</button>
        {{else}}
            <button class="edit btn">Edit</button>
        {{/if}}
        <div class="replica_value">
            {{#if editable}}
                <input type="text" id="replicas_value" value="{{replicas}}" class="inline_edit_input">
            {{else}}
                <p class="value">{{replicas}}</p>
            {{/if}}
            <p class="caption">Replicas</p>
            {{#if editable}}
            <p class="max-value">max replicas: {{max_replicas}}</p>
            {{/if}}
        </div>
        <div class="ack_value">
            {{#if editable}}
                <input type="text" id="acks_value" value="{{acks}}" class="inline_edit_input">
            {{else}}
                <p class="value">{{acks}}</p>
            {{/if}}
            <p class="caption">Write Acks</p>
            {{#if editable}}
            <p class="max-value">max acks: {{max_acks}}</p>
            {{/if}}
        </div>
    </div>
</script>
<script id="namespace_view-edit_datacenter_replica-alert_messages-template" type="text/x-handlebars-template">
    {{#if need_replica_for_primary}}
    You need to set at least one replica before making this datacenter primary.
    {{/if}}
    {{#if too_many_replicas}}
    The number of replicas ({{num_replicas}}) cannot exceed the total number of servers ({{max_machines}}).
    {{/if}}
    {{#if need_at_least_one_replica}}
    The number of replicas must be at least one because {{name}} is the primary datacenter for this table.
    {{/if}}
    {{#if too_many_acks}}
    The number of acks ({{num_acks}}) cannot exceed the total number of replicas ({{num_replicas}}).
    {{/if}}
</script>
<script id="namespace_view-edit_datacenter_replica-replication_status-template" type="text/x-handlebars-template">
    {{num_replicas_ready}}/{{num_replicas}} replicas up to date.
</script>
<script id="namespace_view-edit_datacenter_replica-replication_done-template" type="text/x-handlebars-template">
    <div class="close" href="#">&times;</div>
    <p>Replication complete</p>
</script>

<script id="namespace_view-edit_datacenter_replica-error-template" type="text/x-handlebars-template">
    <p>
    {{#each msg_errors}}
     {{print_safe this}}<br/>
    {{/each}}
    </p>
</script>

<script id="namespace_view-edit_datacenter_replica-success-template" type="text/x-handlebars-template">
    <div class="close" href="#">&times;</div>
    <p>Changing replicas and acks...</p>
</script>

<script id="namespace_view-edit_datacenter_replica-ajax_error-template" type="text/x-handlebars-template">
    <div class="close" href="#">&times;</div>
    <p>Sorry, an AJAX error occurred. Please refresh and try again.</p>
</script>

<script id="need_replicas-template" type="text/x-handlebars-template">
    <p>This datacenter needs at least one replica to become master.</p>
</script>

<script id="changed_primary_dc-replica-template" type="text/x-handlebars-template">
    You successfully set this datacenter as primary.
</script>

<script id="modified_replica-alert-template" type="text/x-handlebars-template">
  <div class="alert" data-alert="alert">
    <a class="close" href="#">&times;</a>
    <p>
      You successfully changed
      {{#if modified_replicas}} the number of replicas from {{old_replicas}} to {{new_replicas}}
      {{#if modified_acks}} and{{/if}}
      {{/if}}
      {{#if modified_acks}} the number of acks from {{old_acks}} to {{new_acks}}{{/if}}
      for datacenter <a href="/#datacenters/{{datacenter_uuid}}">{{datacenter_name}}</a>.
    </p>
  </div>
</script>

<script id="replica_status-template" type="text/x-handlebars-template">
    {{#if operation_active}}
        <div class="progress-status">
            <div class="stages">
                {{#if starting}}
                    <p>Started</p>
                {{/if}}
                {{#if processing}}
                    <p class="completed">Started</p>
                    <p>Replicating</p>
                {{/if}}
                {{#if finished}}
                    <p class="completed">Started</p>
                    <p class="completed">Replicated</p>
                {{/if}}
            </div>
            {{#if starting}}
                <p>0/{{new_value}} replicas completed</p>
                {{else}}
            <p>
            {{current_value}}/{{max_value}} {{pluralize_noun "replica" num_replicas}}{{#if total_blocks}}, 
            {{! Keep the if above so we do not have an extra space before the comma}}
            {{replicated_blocks}}/{{total_blocks}} blocks copied
            {{else}}
            up to date
            {{/if}}
            </p>
            {{/if}}
            <div class="progress"><div class="bar" style="width:{{#if starting}}0{{else}}{{percent_complete}}{{/if}}%"></div></div>
        </div>
    {{else}}
    <p><span class="big">{{current_value}}/{{max_value}}</span> {{pluralize_noun "replica" max_value}} reachable</p>
    {{/if}}
</script>

<script id="namespace_view-primary_datacenter-template" type="text/x-handlebars-template">
    <div class="toggle-primary">
        <div class="switch">
            <input type="radio" class="switch-input" name="view" value="primary-on" id="primary-on"{{#if force_on}} checked{{/if}}>
            <label for="primary-on" class="switch-label switch-label-off">On</label>
            <input type="radio" class="switch-input" name="view" value="primary-off" id="primary-off"{{#unless force_on}} checked{{/unless}}>
            <label for="primary-off" class="switch-label switch-label-on">Off</label>
            <span class="switch-selection"></span>
        </div>
        <p class="caption">Pin masters to a single datacenter</p>
    </div>
    <div class="content"></div>

    <div class="alert alert-error">
        <a class="close" href="#">&times;</a>
        Sorry, something went wrong with the ajax request. Please try again.
    </div>
</script>

<script id="namespace_view-primary_datacenter_content-template" type="text/x-handlebars-template">
    {{#if show_primary}}
    <button class="edit btn">Edit</button>
    <p>Current datacenter used: <a href="#datacenters/{{primary_id}}">{{primary_name}}</a></p>
    {{else}}
    {{#if choose_primary}}
        {{#if primary_isnt_universe}}
        <p>Current datacenter used: <a href="#datacenters/{{primary_id}}">{{primary_name}}</a></p>
        {{/if}}
        <button class="cancel-change-primary btn">&times;</button>
        <button class="save submit-change-primary btn">Change</button>
        <select class="datacenter_uuid_list" name="datacenter_uuid_list">
            {{#each datacenters}}
            <option value="{{this.id}}"{{#if is_primary}} disabled="disabled"{{/if}}>{{this.name}}</option>
            {{/each}}
        </select>
    {{else}}
        {{#if confirm_off}}
        <button class="cancel-confirm-off btn">&times;</button>
        <button class="save submit-confirm-off btn">Confirm</button>
        <p>Are you sure you want not to force masters in <a href="#datacenters/{{primary_id}}">{{primary_name}}</a>?</p>
        {{else}}
        <div class="alert alert-success displayed_alert">
            You can pin the master of each shard for this table to a single datacenter-- designating it as the primary datacenter for this table.
        </div>
        {{/if}}
        {{/if}}
    {{/if}}
</script>
