{{> common_header}}

{{#is Layout.org.code "not_found"}}
<div class="layout-body" data-id="org_details">
    {{> org_title org=Layout.org}}
    <div class="blank-content">
        {{i18n "org_details.not_found"}}
    </div>
</div>
{{else}}
<div class="layout-body" data-id="org_details">

    {{> org_title org=Layout.org}}
    {{> org_menu selected_tab="details"}}

    <table class="key-value" data-id="basic_details">
        <tbody>
            <tr data-blocked="{{Layout.org.is_blocked}}">
                <th>{{i18n "org_list.header.id"}}{{#if Layout.org.shard}}:{{i18n "org_details.header.shard"}}{{/if}}</th>
                <td class="value">
                    {{Layout.org.id}}{{#if Layout.org.shard}}:{{Layout.org.shard}}{{/if}}
                    {{#if Layout.org.is_blocked}}
                    <span data-id="block_status">{{i18n "org_details.status.blocked"}}</span>
                    {{/if}}
                </td>
                <td data-id="actions">
                    <label class="link" for="block">
                        {{#if Layout.org.is_blocked}}
                        {{i18n "org_details.action.unblock"}}
                        {{else}}
                        {{i18n "org_details.action.block"}}
                        {{/if}}
                    </label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="cancel_block">
                        <input type="radio" name="action" id="block">
                        {{> forms.org.block org=Layout.org}}
                    </div>
                </td>
            </tr>
            {{#if Layout.org.cloud_org_id}}
                <tr data-id="cloud_org_id">
                    <th>{{i18n "org_list.header.cloud_org_id"}}</th>
                    <td colspan="2">{{Layout.org.cloud_org_id}}</td>
                </tr>
            {{/if}}
            <tr data-id="domain">
                <th>{{i18n "org_list.header.domain"}}</th>
                <td>
                    {{#if Layout.org.domains.master}}
                    <a href="{{link_url Layout.org.domains.master}}" rel="noopener noreferrer">
                        {{Layout.org.domains.master}}
                    </a>
                    {{else}}
                    &mdash;
                    {{/if}}
                </td>
                <td data-id="actions">
                    {{#if Layout.org.domains.master}}
                    <a href="/organizations/{{Layout.org.id}}/domains">&bull;&nbsp;&bull;&nbsp;&bull;</a>
                    {{/if}}
                </td>
            </tr>
            <tr data-id="admin">
                <th>{{i18n "org_details.prop.owner"}}</th>
                <td>
                    <div class="value">
                        <span title="{{user_name Layout.org.owner.object}}">{{dash_empty Layout.org.owner.object.nickname}}</span>
                    </div>
                    <div class="details">
                        <span title="{{i18n "user_details.prop.uid"}}">UID {{fallback Layout.org.owner.object.id Layout.org.admin_uid}}</span>
                        <a href="/search?query={{fallback Layout.org.owner.object.id Layout.org.admin_uid}}&type=owner_id" title="{{i18n "org_list.tip.search_by_owner"}}" class="symbol">🔍</a>
                    </div>
                </td>
                <td data-id="actions">
                    <label class="link" for="change_owner">{{i18n "org_details.action.change_owner"}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="unchanged_owner">
                        <input type="radio" name="action" id="change_owner">
                        {{> forms.org.owner org=Layout.org}}
                    </div>
                </td>
            </tr>
            {{#if (and (is Layout.action.request (concat "post <directory_admin>/organizations/" Layout.org.id "/owner/")) (is Layout.action.type "success") Layout.org.domains.master)}}
            <tr data-element="inline-notification" data-status="warning">
                <td colspan="3">{{{i18n "org_details.message.change_owner_in_pdd" domain=Layout.org.domains.master owner_id=(fallback Layout.query.owner_id Layout.org.admin.id Layout.org.admin_uid)}}}</td>
            </tr>
            {{/if}}
            {{#unless (is Layout.org.sync.code "not_found")}}
            <tr data-id="consistency">
                <th>{{i18n "org_list.header.mailing_lists"}}</th>
                <td>
                    {{#if (is Layout.org.sync null)}}
                    {{i18n "org_list.mailing_lists.consistency.never_checked"}}
                    {{else if Layout.org.sync.code}}
                    &mdash;
                    {{else if Layout.org.sync}}
                    <div data-role="hover_tip_container">
                        <span data-value="{{Layout.org.sync.ml_is_ok}}" title="{{i18n "org_list.tip.mailing_lists_consistency"}}">{{dash_empty (i18n "org_list.mailing_lists.consistency." Layout.org.sync.ml_is_ok)}}</span>
                        <div data-element="hover_tip">
                            <div class="content">
                                <table>
                                    <tr>
                                        <th>{{i18n "org_details.prop.sync.updated_at"}}</th>
                                        <td>{{{dash_empty (html_date Layout.org.sync.updated_at)}}}</td>
                                    </tr>
                                    <tr>
                                        <th>{{i18n "org_details.prop.sync.revision"}}</th>
                                        <td>{{dash_empty Layout.org.sync.revision}}</td>
                                    </tr>
                                    <tr>
                                        <th>{{i18n "org_details.prop.sync.problems"}}</th>
                                        <td>{{#if (empty Layout.org.sync.problems)}}&mdash;{{else}}<a href="/fetch/organizations/{{Layout.org.id}}/maillists/sync/" target="_blank">{{line_count Layout.org.sync.problems}}</a>{{/if}}</td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    {{else}}
                    &mdash;
                    {{/if}}
                </td>
                <td data-id="actions">
                    <label class="link" for="mailing_lists_sync">{{i18n "org_details.action.sync_mailing_lists"}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="canceled_mailing_lists_sync">
                        <input type="radio" name="action" id="mailing_lists_sync">
                        <form action="/forms/organizations/{{Layout.org.id}}/maillists/sync/" method="post" data-element="popup">
                            <div class="actions">
                                <button type="submit" class="highlighted" data-action="ok">{{i18n "org_details.form.action.start_mailing_lists_sync"}}</button>
                                <label for="canceled_mailing_lists_sync" class="button" data-action="cancel">{{i18n "common.action.cancel"}}</label>
                            </div>
                        </form>
                    </div>
                </td>
            </tr>
            {{/unless}}
        </tbody>
        <tbody>
            <tr data-id="creation_date">
                <th>{{i18n "org_list.header.creation_date"}}</th>
                <td data-date="{{Layout.org.created}}" colspan="2">{{{dash_empty (html_date Layout.org.created)}}}</td>
            </tr>
            <tr>
                <th>{{i18n "org_list.header.source"}}</th>
                {{#if (utm_source_components Layout.org.source)}}
                <td colspan="2">
                    <table class="minimal">
                        {{#each (utm_source_components Layout.org.source)}}
                        {{#if this.key}}
                        <tr><td>{{this.key}}</td><td>=</td><td>{{this.value}}</td></tr>
                        {{else}}
                        <tr><td colspan="3">{{this.value}}</td></tr>
                        {{/if}}
                        {{/each}}
                    </table>
                </td>
                {{else}}
                <td colspan="2">{{{dash_empty (linebreaking_utm_source Layout.org.source)}}}</td>
                {{/if}}
            </tr>
            {{#if Layout.org.migration_id}}
            <tr data-id="migration">
                <th>{{i18n "org_details.prop.migration_id"}}</th>
                <td>{{Layout.org.migration_id}}</td>
                <td data-id="actions">
                    {{#if Layout.org.billing.client_id}}
                    <span class="link" title="{{i18n "org_details.tip.rollback_unavailable"}}" disabled>{{i18n "org_details.action.rollback"}}</span>
                    {{else}}
                    <label class="link" for="rollback_migration">{{i18n "org_details.action.rollback"}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="unchanged_migration">
                        <input type="radio" name="action" id="rollback_migration">
                        {{> forms.org.rollback org=Layout.org}}
                    </div>
                    {{/if}}
                </td>
            </tr>
            {{else}}
            {{#unless (is Layout.org.environment Layout.env)}}
            {{#unless (and (is Layout.org.environment "testing") (is Layout.env "development"))}}
            <tr data-id="migration">
                <th>{{i18n "org_details.prop.migration_id"}}</th>
                <td colspan="2">
                    &rarr;&nbsp;
                    {{#is Layout.org.environment "qa"}}
                    <a href="//catalog-qa.ws.yandex-team.ru/organizations/{{Layout.org.id}}">{{Layout.org.environment}}</a>
                    {{else is Layout.org.environment "testing"}}
                    <a href="//catalog-test.ws.yandex-team.ru/organizations/{{Layout.org.id}}">{{Layout.org.environment}}</a>
                    {{else is Layout.org.environment "production"}}
                    <a href="//catalog.ws.yandex-team.ru/organizations/{{Layout.org.id}}">{{Layout.org.environment}}</a>
                    {{else}}
                    {{Layout.org.environment}}
                    {{/is}}
                </td>
            </tr>
            {{/unless}}
            {{/unless}}
            {{/if}}
            <tr>
                <th>{{i18n "org_details.header.environment"}}</th>
                <td colspan="2">{{Layout.org.environment}}</td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <th>{{i18n "org_list.header.subscription_plan.full"}}</th>
                <td>{{dash_empty (fallback (i18n "org_details.subscription_plan." Layout.org.subscription_plan) Layout.org.subscription_plan)}}</td>
                <td data-id="actions">
                    <label class="link" for="open_subscription_plan">{{i18n "org_details.action.change_subscription_plan"}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="cancel_subscription_plan">
                        <input type="radio" name="action" id="open_subscription_plan">
                        {{> forms.org.subscription org=Layout.org name="subscription_plan"}}
                    </div>
                </td>
            </tr>
            <tr>
                <th>{{i18n "org_details.prop.subscription_plan_expires_at"}}</th>
                <td>{{{dash_empty (html_date Layout.org.subscription_plan_expires_at)}}}</td>
                <td data-id="actions">
                    <label class="link" for="open_subscription_plan_expiration">{{i18n "org_details.action.change_subscription_plan_expiration_date"}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="cancel_subscription_plan_expiration">
                        <input type="radio" name="action" id="open_subscription_plan_expiration">
                        {{> forms.org.subscription org=Layout.org name="subscription_plan_expiration"}}
                    </div>
                </td>
            </tr>
            {{!--
            <tr>
                <th>{{i18n "org_list.header.subscription_plan_last_change"}}</th>
                <td data-date="{{Layout.org.subscription_plan_changed_at}}" colspan="2">
                    {{{html_date Layout.org.subscription_plan_changed_at}}}
                </td>
            </tr>
            --}}
            <tr data-id="balance" data-type="{{sign_type Layout.org.billing.balance}}">
                <th>{{i18n "org_list.header.balance"}}</th>
                <td colspan="2">{{dash_empty (signed_formatted_number Layout.org.billing.balance)}}</td>
            </tr>
            <tr data-id="client_id">
                <th>{{i18n "org_list.header.client_id"}}</th>
                <td colspan="2">{{dash_empty Layout.org.billing.client_id}}</td>
            </tr>
            {{#if Layout.org.billing.person_id}}
            <tr data-id="person_id">
                <th>{{i18n "org_details.prop.person_id"}}</th>
                <td colspan="2">{{dash_empty Layout.org.billing.person_id}}</td>
            </tr>
            {{/if}}
            {{#if (or (is Layout.org.organization_type "partner_organization") (is Layout.org.organization_type "cloud_partner"))}}
            <tr data-id="partner">
                <th>{{i18n "org_details.prop.partner"}}</th>
                <td colspan="2">
                    {{#if Layout.org.partner.name}}
                    <div data-role="hover_tip_container">
                        <span>{{Layout.org.partner.name}}</span>
                        <div data-element="hover_tip">
                            <div class="content">
                                <table>
                                    <tr>
                                        <th>{{i18n "org_details.prop.partner_id"}}</th>
                                        <td>{{{dash_empty Layout.org.partner_id}}}</td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    {{else if Layout.org.partner_id}}
                    <span class="dim">#{{Layout.org.partner_id}}</span>
                    {{else}}
                    &mdash;
                    {{/if}}
                </td>
            </tr>
            {{/if}}
        </tbody>
        <tbody>
            <tr>
                <th>{{i18n "org_details.prop.type"}}</th>
                <td>{{dash_empty Layout.org.organization_type}}</td>
                <td data-id="actions">
                    <label class="link" for="change_org_type">{{i18n "org_details.action.change_type"}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="unchanged_org_type">
                        <input type="radio" name="action" id="change_org_type">
                        {{> forms.org.type org=Layout.org}}
                    </div>
                </td>
            </tr>
            <tr>
                <th>{{i18n "org_details.prop.vip"}}</th>
                <td>{{on_off Layout.org.vip.length}}</td>
                <td data-id="actions">
                    <label class="link" for="change_org_vip">{{#if (contains Layout.org.vip "whitelist")}}{{i18n "org_details.action.remove_from_vip_whitelist"}}{{else}}{{i18n "org_details.action.add_to_vip_whitelist"}}{{/if}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="unchanged_org_vip">
                        <input type="radio" name="action" id="change_org_vip">
                        {{> forms.org.whitelist org=Layout.org mode=(ternary (contains Layout.org.vip "whitelist") "remove" "add")}}
                    </div>
                </td>
            </tr>
            {{#unless (empty Layout.org.vip)}}
            <tr class="followup">
                <th>{{i18n "org_details.prop.vip_reasons"}}</th>
                <td colspan="2">
                    <span title="{{i18n "org_details.tip.vip_reasons"}}">
                    {{#each Layout.org.vip}}
                        {{i18n "org_details.vip." this}}{{#unless @last}}, {{/unless}}
                    {{/each}}
                    </span>
                </td>
            </tr>
            {{/unless}}
            <tr>
                <th>{{i18n "org_list.header.preset"}}</th>
                <td>{{dash_empty Layout.org.preset}}</td>
                <td></td>
            </tr>
            <tr>
                <th>{{i18n "org_list.header.shared_contacts"}}</th>
                <td><span data-value="{{Layout.org.shared_contacts}}">{{on_off Layout.org.shared_contacts}}</span></td>
                <td></td>
            </tr>
            <tr>
                <th>{{i18n "org_list.header.navigation_header"}}</th>
                <td>{{dash_empty Layout.org.header}}</td>
                <td></td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <th>{{i18n "org_details.prop.user_aliases_max_count"}}</th>
                <td>{{dash_empty Layout.org.limits.user_aliases_max_count}}</td>
                <td data-id="actions">
                    <label class="link" for="change_user_aliases_max_count">{{i18n "org_details.action.change_user_aliases_max_count"}}</label>
                    <div data-element="popup_form">
                        <input type="radio" name="action" id="unchanged_user_aliases_max_count">
                        <input type="radio" name="action" id="change_user_aliases_max_count">
                        {{> forms.org.limit name="user_aliases_max_count" org=Layout.org}}
                    </div>
                </td>
            </tr>
        </tbody>
        <tbody>
        <tr>
            <th>{{i18n "org_details.prop.users_limit"}}</th>
            <td>{{dash_empty Layout.org.limits.users_limit}}</td>
            <td data-id="actions">
                <label class="link" for="change_users_limit">{{i18n "org_details.action.change_users_limit"}}</label>
                <div data-element="popup_form">
                    <input type="radio" name="action" id="unchanged_users_limit">
                    <input type="radio" name="action" id="change_users_limit">
                    {{> forms.org.limit name="users_limit" org=Layout.org}}
                </div>
            </td>
        </tr>
        </tbody>
        <tbody>
            <tr>
                <th>{{i18n "org_list.header.language"}}</th>
                <td colspan="2">{{dash_empty (fallback (i18n "languages." Layout.org.language) Layout.org.language)}}</td>
            </tr>
            <tr>
                <th>{{i18n "org_list.header.country"}}</th>
                <td colspan="2">{{dash_empty (fallback (i18n "countries." (uppercase Layout.org.country)) Layout.org.country)}}</td>
            </tr>
        </tbody>
    </table>

    <div data-id="stats">
        {{#unless (empty Layout.org.users_count)}}
        <div>
            <span class="value">{{formatted_number Layout.org.users_count}}</span>
            <span class="caption">{{pluralize Layout.org.users_count (i18n "org_details.stats.user") "${objects}"}}</span>
            {{> diagram_bar value=Layout.org.users_count max=1000}}
        </div>
        {{/unless}}
        {{#unless (empty Layout.org.departments_count)}}
        <div>
            <span class="value">{{formatted_number Layout.org.departments_count}}</span>
            <span class="caption">{{{pluralize Layout.org.departments_count (i18n "org_details.stats.department") "${objects}"}}}</span>
            {{> diagram_bar value=Layout.org.departments_count max=1000}}
        </div>
        {{/unless}}
        {{#unless (empty Layout.org.groups_count)}}
        <div>
            <span class="value">{{formatted_number Layout.org.groups_count}}</span>
            <span class="caption">{{{pluralize Layout.org.groups_count (i18n "org_details.stats.group") "${objects}"}}}</span>
            {{> diagram_bar value=Layout.org.groups_count max=1000}}
        </div>
        {{/unless}}
        {{#unless (empty Layout.org.disk_usage)}}
        {{#if Layout.org.disk_limit}}
        <div>
            <span class="compound value">{{{i18n "org_details.stats.disk_usage.value" current=(memory_units Layout.org.disk_usage) total=(memory_units Layout.org.disk_limit)}}}</span>
            <span class="caption">{{i18n "org_details.stats.disk_usage.caption"}}</span>
            {{> diagram_bar value=Layout.org.disk_usage max=Layout.org.disk_limit}}
        </div>
        {{/if}}
        {{/unless}}
    </div>

    <div class="break"></div>

</div>
{{/is}}
