<!--

    Copyright © 2016-2026 The Thingsboard Authors

    Licensed 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.

-->
<div
  (dblclick)="userNodeCallbacks.doubleClick($event, node)"
  (mousedown)="userNodeCallbacks.mouseDown($event, node)"
  (mouseenter)="userNodeCallbacks.mouseEnter($event, node)"
  (mouseleave)="userNodeCallbacks.mouseLeave($event, node)">
  <div class="fc-node-overlay"></div>
  <div class="tb-rule-node {{node.nodeClass}}"
       [class.tb-rule-node-highlighted]="node.highlighted"
       [class.tb-rule-node-invalid]="node.error">
    @if (!iconUrl) {
      <mat-icon class="max-w-15% flex-full">{{node.icon}}</mat-icon>
    }
    @if (iconUrl) {
      <img class="max-w-15% flex-full" [src]="iconUrl"/>
    }
    <div class="flex max-w-85% flex-full flex-col items-stretch justify-center">
      <span class="tb-node-type">{{ node.component.name }}</span>
      @if (node.name) {
        <span class="tb-node-title">{{ node.name }}</span>
      }
    </div>
    <div class="{{flowchartConstants.leftConnectorClass}}">
      @for (connector of modelservice.nodes.getConnectorsByType(node, flowchartConstants.leftConnectorType); track connector) {
        <div fc-magnet [connector]="connector" [callbacks]="callbacks"
             >
          <div fc-connector [connector]="connector"
               [nodeRectInfo]="nodeRectInfo"
               [mouseOverConnector]="mouseOverConnector"
               [callbacks]="callbacks"
          [modelservice]="modelservice"></div>
        </div>
      }
    </div>
    <div class="{{flowchartConstants.rightConnectorClass}}">
      @for (connector of modelservice.nodes.getConnectorsByType(node, flowchartConstants.rightConnectorType); track connector) {
        <div fc-magnet [connector]="connector" [callbacks]="callbacks"
             >
          <div fc-connector [connector]="connector"
               [nodeRectInfo]="nodeRectInfo"
               [mouseOverConnector]="mouseOverConnector"
               [callbacks]="callbacks"
          [modelservice]="modelservice"></div>
        </div>
      }
    </div>
  </div>
  @if (modelservice.isEditable() && !node.readonly) {
    <section>
      <div class="fc-nodeedit" (click)="userNodeCallbacks.nodeEdit($event, node)">
        <i class="fa fa-pencil" aria-hidden="true"></i>
      </div>
      <div class="fc-nodedelete" (click)="modelservice.nodes.delete(node)">
        &times;
      </div>
    </section>
  }
  @if (node.component?.configurationDescriptor?.nodeDefinition?.ruleChainNode && modelservice.isEditable()) {
    <section>
      <div class="fc-nodeopen" (click)="openRuleChain($event, node)" (mouseenter)="displayOpenRuleChainTooltip($event, node)">
        <mat-icon class="material-icons" svgIcon="mdi:login"></mat-icon>
      </div>
    </section>
  }
</div>
