<div class="layout-header">
    {{> common_header}}
    {{#if Layout.migration_list.result.length}}
    <table class="migration-list paged-list">
    <thead>
        <tr>
            <td data-id="status">
                {{i18n "migration.header.status"}}
            </td>
            <td data-id="domain_status"></td>
            <td data-id="org">
                {{i18n "migration.header.organization"}}
            </td>
            <td data-id="admin">
                {{i18n "migration.header.admin"}}
            </td>
            <td data-id="age"></td>
            <td data-id="last_update">
                {{i18n "migration.header.last_update"}}
            </td>
            <td data-id="id">
                {{i18n "migration.header.id"}}
            </td>
            <td data-id="actions"></td>
        </tr>
    </thead>
    </table>
    {{/if}}
</div>

<div class="layout-body">
    {{#if Layout.migration_list.result.length}}
    <table class="migration-list paged-list">
    <tbody>
    {{#each Layout.migration_list.result}}
        <tr data-status="{{this.extended_status}}" id="/{{this.id}}">
            <td data-id="status" data-status="{{this.status}}{{#if this.probably_failed}} probably_failed{{/if}}" data-code="{{this.data.code}}">
                <span class="badge" title="{{this.status}}">
                    <span class="value">{{this.status}}</span>{{#if this.data.code}}: {{this.data.code}}{{/if}}
                </span>
            </td>
            <td data-id="domain_status" data-x="{{this.settings.domain}}" data-value="{{domain_status this.settings.domain}}">
                <span class="badge" title="{{i18n "org_details.tip." (domain_status this.settings.domain) "_domain"}}"></span>
            </td>
            <td data-id="org" class="unconstrained">
                <div data-role="hover_tip_container">
                    <div class="value" title="{{safe_name this.org}}" data-id="org_name">
                        {{#if this.org.id}}
                        <a href="/organizations/{{this.org.id}}">{{safe_name this.org}}</a>
                        {{else}}
                        {{safe_name this.org}}
                        {{/if}}
                    </div>
                    {{> org_tip org=this.org index=@index}}
                </div>
            </td>
            {{#if this.org.admin.nickname}}
            <td data-id="admin">{{this.org.admin.nickname}}</td>
            {{else}}
            <td data-id="admin" class="_id">{{this.org.admin.id}}</td>
            {{/if}}
            <td data-id="age">
                <span title="{{elapsed this.updated_at exact=true}}">{{elapsed this.updated_at}}</span>
            </td>
            <td data-id="last_update" data-date="{{this.updated_at}}">
                {{{html_date this.updated_at}}}
            </td>
            <td data-id="id">
                <span class="value">{{this.id}}</span>
            </td>
            <td data-id="actions" class="unconstrained" id="/{{this.id}}">
                <input type="radio" name="action" id="unchanged_{{@index}}">
                <input type="radio" name="action" id="rollback_{{@index}}">
                <form method="post" action="/forms/pdd-migration/{{this.id}}/" class="hover-card-container">
                    <input type="hidden" name="_method" value="patch">
                    <input type="hidden" name="status" value="rollback">
                    <input type="hidden" name="shard<number>" value="{{this.shard}}">
                    <div class="hover-card">
                        <input type="text" name="comment" placeholder="{{i18n "migration.prop.comment"}}" class="full-width" required>
                    </div>
                    <button type="submit" class="highlighted">{{i18n "migration.action.rollback"}}</button>
                    <label for="unchanged_{{@index}}" data-action="close">&times;</label>
                </form>
                <label class="button" for="rollback_{{@index}}">{{i18n "migration.action.rollback"}}</label>
            </td>
        </tr>
    {{/each}}
    </tbody>
    </table>

    {{> page_navigation}}
    {{else}}
    <div class="blank-paged-list">
        {{i18n "org_list.warning.not_found"}}
    </div>
    {{/if}}
</div>
