<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_order_detail %}
<sw-page
    v-if="orderId"
    class="sw-order-detail"
>
    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_order_detail_header %}
    <template #smart-bar-header>

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_order_detail_header_title %}
        <h2 v-if="orderIdentifier">
            {{ $tc('sw-order.detail.textHeadline') }} {{ orderIdentifier }}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_order_detail_header_label_manual_order %}
            <sw-label
                v-if="createdById"
                appearance="pill"
                size="small"
                class="sw-order-detail__manual-order-label"
            >
                {{ $tc('sw-order.detail.labelManualOrder') }}
            </sw-label>
            {% endblock %}
        </h2>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_order_detail_header_title_new %}
        <h2 v-else>
            {{ $tc('sw-order.detail.textHeadlineNew') }}
        </h2>
        {% endblock %}

    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_order_detail_language_switch %}
    <template #language-switch>
        <sw-language-switch
            @on-change="onChangeLanguage"
        />
    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_order_detail_actions %}
    <template #smart-bar-actions>

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_order_detail_actions_slot_smart_bar_actions %}
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_order_detail_actions_abort %}
        <sw-button
            v-tooltip="{
                message: $tc('sw-privileges.tooltip.warning'),
                disabled: acl.can('order.editor'),
                showOnDisabledElements: true
            }"
            class="sw-order-detail__smart-bar-cancel-button"
            :disabled="isLoading || !acl.can('order.editor')"
            @click="onCancelEditing"
        >
            {{ $tc('global.default.cancel') }}
        </sw-button>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_order_detail_actions_save %}
        <sw-button-process
            v-tooltip="{
                message: $tc('sw-privileges.tooltip.warning'),
                disabled: acl.can('order.editor'),
                showOnDisabledElements: true
            }"
            class="sw-order-detail__smart-bar-save-button"
            variant="primary"
            :disabled="isLoading || !acl.can('order.editor')"
            :is-loading="isLoading"
            :process-success="isSaveSuccessful"
            @update:process-success="saveEditsFinish"
            @click.prevent="onSaveEdits"
        >
            {{ $tc('global.default.save') }}
        </sw-button-process>
        {% endblock %}
        {% endblock %}

    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_order_detail_content %}
    <template #content>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_order_detail_content_leave_page_modal %}
        <sw-order-leave-page-modal
            v-if="isDisplayingLeavePageWarning"
            @page-leave-cancel="onLeaveModalClose"
            @page-leave-confirm="onLeaveModalConfirm"
        />
        {% endblock %}
        <sw-card-view>

            <sw-alert
                v-if="isOrderEditing"
                class="sw-order-detail__alert"
                variant="warning"
            >
                {{ $tc('sw-order.detail.textUnsavedOrderWarning') }}
            </sw-alert>

            <sw-alert
                v-if="missingProductLineItems.length > 0"
                class="sw-order-detail__alert"
                variant="warning"
            >
                {{ $tc('sw-order.detailBase.textMissingProductLineItems') }}

                <ul class="sw_order_detail_base__missing_products_alert-list">
                    <li
                        v-for="lineItem in missingProductLineItems"
                        :key="lineItem.id"
                    >
                        {{ lineItem.label }}
                    </li>
                </ul>

                {{ $tc('sw-order.detailBase.textMissingProductLineItemsDescription') }}
            </sw-alert>

            <sw-alert
                v-if="convertedProductLineItems.length > 0"
                class="sw-order-detail__alert"
                variant="info"
            >
                {{ $tc('sw-order.detailBase.textConvertedProductLineItems') }}

                <ul class="sw_order_detail_base__converted_products_alert-list">
                    <li
                        v-for="lineItem in convertedProductLineItems"
                        :key="lineItem.id"
                    >
                        {{ lineItem.label }}
                    </li>
                </ul>

                {{ $tc('sw-order.detailBase.textConvertedProductLineItemsDescription') }}
            </sw-alert>

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_order_detail_content_tabs %}
            <sw-tabs
                v-if="showTabs"
                class="sw-order-detail__tabs"
                :class="{ 'has-warning': showWarningTabStyle }"
                position-identifier="sw-order-detail"
            >

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_order_detail_content_tabs_general %}
                <sw-tabs-item
                    class="sw-order-detail__tabs-tab-general"
                    :route="{ name: 'sw.order.detail.general', params: { id: $route.params.id } }"
                    :title="$tc('sw-order.detail.tabGeneral')"
                >
                    {{ $tc('sw-order.detail.tabGeneral') }}
                </sw-tabs-item>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_order_detail_content_tabs_details %}
                <sw-tabs-item
                    class="sw-order-detail__tabs-tab-details"
                    :route="{ name: 'sw.order.detail.details', params: { id: $route.params.id } }"
                    :title="$tc('sw-order.detail.tabDetails')"
                >
                    {{ $tc('sw-order.detail.tabDetails') }}
                </sw-tabs-item>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_order_detail_content_tabs_documents %}
                <sw-tabs-item
                    class="sw-order-detail__tabs-tab-documents"
                    :class="{ 'has-warning': isOrderEditing }"
                    :route="{ name: 'sw.order.detail.documents', params: { id: $route.params.id } }"
                    :title="$tc('sw-order.detail.tabDocuments')"
                >
                    {{ $tc('sw-order.detail.tabDocuments') }}

                    <sw-icon
                        v-if="isOrderEditing"
                        v-tooltip="{ message: $tc('sw-order.documentTab.tooltipSaveBeforeCreateDocument') }"
                        class="sw-order-detail__tab-warning-badge"
                        name="solid-exclamation-circle"
                        size="12px"
                    />
                </sw-tabs-item>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_order_detail_content_tabs_extension %}{% endblock %}
            </sw-tabs>
            {% endblock %}

            <sw-extension-component-section
                position-identifier="sw-order-detail__before-content"
            />

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_order_detail_content_view %}
            <template v-if="isLoading">
                <sw-skeleton />
                <sw-skeleton />
            </template>

            {# v-show is used here as underlying components influence the loading state and v-if would destroy this behaviour #}
            <router-view
                v-if="order"
                v-show="!isLoading"
                ref="baseComponent"
                :order-id="orderId"
                :is-editing="isEditing"
                :is-loading="isLoading"
                :is-save-successful="isSaveSuccessful"
                @identifier-change="updateIdentifier"
                @created-by-id-change="updateCreatedById"
                @loading-change="onUpdateLoading"
                @editing-change="onUpdateEditing"
                @save-and-recalculate="onSaveAndRecalculate"
                @recalculate-and-reload="onRecalculateAndReload"
                @reload-entity-data="reloadEntityData"
                @save-and-reload="onSaveAndReload"
                @save-edits="onSaveEdits"
                @error="onError"
            />
            {% endblock %}

        </sw-card-view>
    </template>
    {% endblock %}

</sw-page>
{% endblock %}
