import { Component, inject, output } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { TooltipModule } from 'primeng/tooltip';
import { FeedbackStorageService } from '../services/feedback-storage.service';

@Component({
  selector: 'app-feedback-button',
  standalone: true,
  imports: [CommonModule, TranslateModule, TooltipModule],
  template: `
    <button
      id="feedback-fab"
      class="feedback-fab"
      (click)="openFeedback.emit()"
      [pTooltip]="'FEEDBACK.TITLE' | translate"
      tooltipPosition="right"
    >
      <i class="pi pi-comments text-xl"></i>
      @if (storageService.count() > 0) {
        <span class="feedback-badge">{{ storageService.count() }}</span>
      }
    </button>
  `,
  styles: [
    `
      .feedback-fab {
        position: fixed;
        bottom: 24px;
        inset-inline-start: 24px;
        z-index: 9990;
        width: 52px;
        height: 52px;
        border-radius: 50%;
        border: none;
        background: var(--color-accent);
        color: var(--color-brand);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        transition: all 0.2s ease;

        &:hover {
          transform: scale(1.1);
          box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
        }

        &:active {
          transform: scale(0.95);
        }
      }

      .feedback-badge {
        position: absolute;
        top: -4px;
        inset-inline-end: -4px;
        min-width: 20px;
        height: 20px;
        border-radius: 10px;
        background: var(--color-danger);
        color: #fff;
        font-size: 11px;
        font-weight: 700;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
      }
    `,
  ],
})
export class FeedbackButtonComponent {
  storageService = inject(FeedbackStorageService);
  openFeedback = output<void>();
}
