import { ComponentFixture, TestBed } from '@angular/core/testing';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { RewardSelectionDialogComponent } from './reward-selection-dialog.component';
import { RewardSelectionStore } from './store/reward-selection-dialog.store';
import { RewardSelectionFacade } from '@isa/checkout/data-access';
import { DialogComponent } from '@isa/ui/dialog';
import { DialogRef, DIALOG_DATA } from '@angular/cdk/dialog';
import { provideHttpClient } from '@angular/common/http';
import { signal } from '@angular/core';

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

  const mockDialogData = {
    rewardSelectionItems: [
      {
        item: {
          id: 1,
          data: {
            product: { catalogProductNumber: 'CAT-123', name: 'Test Product' },
            quantity: 1,
            loyalty: { value: 100 },
          },
        },
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: 100,
        cartQuantity: 1,
        rewardCartQuantity: 0,
      } as any,
    ],
    customerRewardPoints: 500,
    closeText: 'Close',
  };

  const dialogComponentMock = {
    close: vi.fn(),
    data: mockDialogData,
  };

  const dialogRefMock = {
    close: vi.fn(),
  };

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [RewardSelectionDialogComponent],
      providers: [
        { provide: DialogComponent, useValue: dialogComponentMock },
        { provide: DialogRef, useValue: dialogRefMock },
        { provide: DIALOG_DATA, useValue: mockDialogData },
        provideHttpClient(),
      ],
    });

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

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

  it('should initialize store with dialog data on construction', () => {
    // The component provides its own store, so we verify it exists and has the init method
    expect(component.store).toBeDefined();
    expect(component.store.initState).toBeDefined();
  });

  it('should inject store', () => {
    // The component provides its own store instance
    expect(component.store).toBeDefined();
    expect(typeof component.store.initState).toBe('function');
  });

  it('should extend DialogContentDirective', () => {
    expect(component.data).toBe(mockDialogData);
  });
});
