<!--

    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 class="tb-card-content flex flex-col gap-2">
  @if (hasUsageInfoAccess) {
    <div class="tb-card-header">
      <a class="tb-title-link" routerLink="/usage">{{ 'widgets.usage-info.title' | translate }}</a>
      <tb-toggle-header #usageToggle [value]="toggleValue" name="usageToggle">
        <tb-toggle-option value="entities">{{ 'widgets.usage-info.entities' | translate }}</tb-toggle-option>
        <tb-toggle-option value="apiCalls">{{ 'widgets.usage-info.api-calls' | translate }}</tb-toggle-option>
      </tb-toggle-header>
    </div>
    @switch (usageToggle.value) {
      @case ('entities') {
        <div class="tb-usage-list flex-1">
          <div class="tb-usage-items">
            <div class="tb-usage-item" [class.critical]="entityItemCritical.devices" translate>device.devices</div>
            <div class="tb-usage-item" [class.critical]="entityItemCritical.assets" translate>asset.assets</div>
            <div class="tb-usage-item" [class.critical]="entityItemCritical.users" translate>user.users</div>
            <div class="tb-usage-item" [class.critical]="entityItemCritical.dashboards" translate>dashboard.dashboards</div>
            <div class="tb-usage-item" [class.critical]="entityItemCritical.customers" translate>customer.customers</div>
          </div>
          <div class="tb-usage-items-values">
            <div class="tb-usage-items-counts">
              <div class="tb-usage-item-counts" [class.critical]="entityItemCritical.devices">{{ usageInfo?.devices | shortNumber }} / {{ maxValue(usageInfo?.maxDevices) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="entityItemCritical.assets">{{ usageInfo?.assets | shortNumber }} / {{ maxValue(usageInfo?.maxAssets) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="entityItemCritical.users">{{ usageInfo?.users | shortNumber }} / {{ maxValue(usageInfo?.maxUsers) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="entityItemCritical.dashboards">{{ usageInfo?.dashboards | shortNumber }} / {{ maxValue(usageInfo?.maxDashboards) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="entityItemCritical.customers">{{ usageInfo?.customers | shortNumber }} / {{ maxValue(usageInfo?.maxCustomers) }}</div>
            </div>
            <div class="tb-usage-items-progress">
              <mat-progress-bar [class.critical]="entityItemCritical.devices" color="primary" mode="determinate" [value]="progressValue(usageInfo?.devices, usageInfo?.maxDevices)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="entityItemCritical.assets" color="primary" mode="determinate" [value]="progressValue(usageInfo?.assets, usageInfo?.maxAssets)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="entityItemCritical.users" color="primary" mode="determinate" [value]="progressValue(usageInfo?.users, usageInfo?.maxUsers)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="entityItemCritical.dashboards" color="primary" mode="determinate" [value]="progressValue(usageInfo?.dashboards, usageInfo?.maxDashboards)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="entityItemCritical.customers" color="primary" mode="determinate" [value]="progressValue(usageInfo?.customers, usageInfo?.maxCustomers)"></mat-progress-bar>
            </div>
          </div>
        </div>
      }
      @case ('apiCalls') {
        <div class="tb-usage-list flex-1">
          <div class="tb-usage-items">
            <div class="tb-usage-item" [class.critical]="apiCallItemCritical.transportMessages" translate>api-usage.transport-messages</div>
            <div class="tb-usage-item" [class.critical]="apiCallItemCritical.jsExecutions" translate>api-usage.javascript</div>
            <div class="tb-usage-item" [class.critical]="apiCallItemCritical.alarms" translate>api-usage.alarms-created</div>
            <div class="tb-usage-item" [class.critical]="apiCallItemCritical.emails" translate>api-usage.email</div>
            <div class="tb-usage-item" [class.critical]="apiCallItemCritical.sms" translate>api-usage.sms</div>
          </div>
          <div class="tb-usage-items-values">
            <div class="tb-usage-items-counts">
              <div class="tb-usage-item-counts" [class.critical]="apiCallItemCritical.transportMessages">{{ usageInfo?.transportMessages | shortNumber }} / {{ maxValue(usageInfo?.maxTransportMessages) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="apiCallItemCritical.jsExecutions">{{ usageInfo?.jsExecutions | shortNumber }} / {{ maxValue(usageInfo?.maxJsExecutions) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="apiCallItemCritical.alarms">{{ usageInfo?.alarms | shortNumber }} / {{ maxValue(usageInfo?.maxAlarms) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="apiCallItemCritical.emails">{{ usageInfo?.emails | shortNumber }} / {{ maxValue(usageInfo?.maxEmails) }}</div>
              <div class="tb-usage-item-counts" [class.critical]="apiCallItemCritical.sms">{{ usageInfo?.sms | shortNumber }} / {{ maxValue(usageInfo?.maxSms) }}</div>
            </div>
            <div class="tb-usage-items-progress">
              <mat-progress-bar [class.critical]="apiCallItemCritical.transportMessages" color="primary" mode="determinate" [value]="progressValue(usageInfo?.transportMessages, usageInfo?.maxTransportMessages)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="apiCallItemCritical.jsExecutions" color="primary" mode="determinate" [value]="progressValue(usageInfo?.jsExecutions, usageInfo?.maxJsExecutions)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="apiCallItemCritical.alarms" color="primary" mode="determinate" [value]="progressValue(usageInfo?.alarms, usageInfo?.maxAlarms)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="apiCallItemCritical.emails" color="primary" mode="determinate" [value]="progressValue(usageInfo?.emails, usageInfo?.maxEmails)"></mat-progress-bar>
              <mat-progress-bar [class.critical]="apiCallItemCritical.sms" color="primary" mode="determinate" [value]="progressValue(usageInfo?.sms, usageInfo?.maxSms)"></mat-progress-bar>
            </div>
          </div>
        </div>
      }
    }
  } @else {
    <div class="tb-card-header">
      <div class="tb-title">{{ 'widgets.usage-info.title' | translate }}</div>
    </div>
    <div class="tb-no-data-available">
      <div class="tb-no-data-bg"></div>
      <div class="tb-no-data-text" translate>widgets.home.no-data-available</div>
    </div>
  }
</div>
