import { describe, it, expect, beforeEach } from 'vitest';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CustomerCardComponent } from './customer-card.component';
import { BonusCardInfo } from '@isa/crm/data-access';

describe('CustomerCardComponent', () => {
  let component: CustomerCardComponent;
  let fixture: ComponentFixture<CustomerCardComponent>;

  const mockCard: BonusCardInfo = {
    code: 'CARD-1',
    firstName: 'John',
    lastName: 'Doe',
    isActive: true,
    isPrimary: true,
    totalPoints: 1500,
  };

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [CustomerCardComponent],
    });

    fixture = TestBed.createComponent(CustomerCardComponent);
    component = fixture.componentInstance;
  });

  it('should create', () => {
    expect(component).toBeDefined();
  });

  describe('Inputs', () => {
    it('should accept card input', () => {
      fixture.componentRef.setInput('card', mockCard);
      fixture.detectChanges();

      expect(component.card()).toEqual(mockCard);
    });

    it('should display active card', () => {
      const activeCard: BonusCardInfo = {
        ...mockCard,
        isActive: true,
      };
      fixture.componentRef.setInput('card', activeCard);
      fixture.detectChanges();

      expect(component.card().isActive).toBe(true);
    });

    it('should display blocked card', () => {
      const blockedCard: BonusCardInfo = {
        ...mockCard,
        isActive: false,
      };
      fixture.componentRef.setInput('card', blockedCard);
      fixture.detectChanges();

      expect(component.card().isActive).toBe(false);
    });

    it('should display primary card', () => {
      const primaryCard: BonusCardInfo = {
        ...mockCard,
        isPrimary: true,
      };
      fixture.componentRef.setInput('card', primaryCard);
      fixture.detectChanges();

      expect(component.card().isPrimary).toBe(true);
    });

    it('should display customer name', () => {
      fixture.componentRef.setInput('card', mockCard);
      fixture.detectChanges();

      const card = component.card();
      expect(card.firstName).toBe('John');
      expect(card.lastName).toBe('Doe');
    });

    it('should display card number', () => {
      fixture.componentRef.setInput('card', mockCard);
      fixture.detectChanges();

      expect(component.card().code).toBe('CARD-1');
    });
  });
});
