<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<ng-template #menu>
    <div
        class="context-menu pt-2 pb-2 mat-elevation-z8 primary-color"
        [class.show-focused]="showFocused$ | async"
        (keydown)="keydown($event)"
        cdkMenu>
        @for (item of getMenuItems(menuId); track item) {
            @if (item.isSeparator) {
                <hr />
            } @else {
                @if (hasSubMenu(item)) {
                    @if (menuComponent.menu; as subMenu) {
                        <button class="context-menu-item p-2" cdkMenuItem [cdkMenuTriggerFor]="subMenu">
                            <div class="flex gap-x-1">
                                <div class="context-menu-item-img" [class]="item.clazz"></div>
                                <div class="context-menu-item-text surface-contrast" [title]="item.text">
                                    {{ item.text }}
                                </div>
                            </div>
                            <div class="context-menu-group-item-img fa fa-caret-right"></div>
                        </button>
                    }
                    <fd-context-menu
                        #menuComponent
                        [menuProvider]="menuProvider"
                        [menuId]="item.subMenuId"></fd-context-menu>
                } @else {
                    <button
                        class="context-menu-item p-2 flex justify-between"
                        (click)="menuItemClicked(item, $event)"
                        cdkMenuItem>
                        <div class="flex gap-x-1">
                            <div class="context-menu-item-img" [class]="item.clazz"></div>
                            <div class="context-menu-item-text surface-contrast" [title]="item.text">
                                {{ item.text }}
                            </div>
                        </div>
                        @if (item.shortcut) {
                            <div class="context-menu-item-shortcut surface-contrast justify-end opacity-40">
                                @if (item.shortcut.shift) {
                                    ⇧
                                }
                                @if (item.shortcut.control) {
                                    {{ isMac ? '⌘' : '⌃' }}
                                }
                                @if (item.shortcut.alt) {
                                    ⌥
                                }
                                {{ item.shortcut.code }}
                            </div>
                        }
                    </button>
                }
            }
        }
    </div>
</ng-template>
