import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { OrderDestinationComponent } from './order-destination.component';
import { OrderTypeFeature } from '@isa/common/data-access';

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

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [OrderDestinationComponent],
      providers: [provideHttpClient(), provideHttpClientTesting()],
    }).compileComponents();

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

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

  it('should display delivery icon for delivery order type', () => {
    fixture.componentRef.setInput('orderType', OrderTypeFeature.Delivery);
    fixture.detectChanges();

    expect(component.destinationIcon()).toBe('isaDeliveryVersand');
  });

  it('should display pickup icon for pickup order type', () => {
    fixture.componentRef.setInput('orderType', OrderTypeFeature.Pickup);
    fixture.detectChanges();

    expect(component.destinationIcon()).toBe('isaDeliveryRuecklage2');
  });

  it('should display in-store icon for in-store order type', () => {
    fixture.componentRef.setInput('orderType', OrderTypeFeature.InStore);
    fixture.detectChanges();

    expect(component.destinationIcon()).toBe('isaDeliveryRuecklage1');
  });

  it('should display branch name when branch is provided', () => {
    fixture.componentRef.setInput('orderType', OrderTypeFeature.Pickup);
    fixture.componentRef.setInput('branch', { name: 'Test Branch' });
    fixture.detectChanges();

    expect(component.name()).toBe('Test Branch');
  });

  it('should display shipping address name for delivery', () => {
    fixture.componentRef.setInput('orderType', OrderTypeFeature.Delivery);
    fixture.componentRef.setInput('shippingAddress', {
      firstName: 'John',
      lastName: 'Doe',
    });
    fixture.detectChanges();

    expect(component.name()).toBe('John Doe');
  });

  it('should return shipping address for delivery orders', () => {
    const testAddress = {
      street: 'Test St',
      city: 'Vienna',
      zipCode: '1010',
    };
    fixture.componentRef.setInput('orderType', OrderTypeFeature.Delivery);
    fixture.componentRef.setInput('shippingAddress', {
      firstName: 'John',
      lastName: 'Doe',
      address: testAddress,
    });
    fixture.detectChanges();

    expect(component.address()).toBe(testAddress);
  });

  it('should return branch address for pickup orders', () => {
    const testAddress = {
      street: 'Branch St',
      city: 'Vienna',
      zipCode: '1020',
    };
    fixture.componentRef.setInput('orderType', OrderTypeFeature.Pickup);
    fixture.componentRef.setInput('branch', {
      name: 'Test Branch',
      address: testAddress,
    });
    fixture.detectChanges();

    expect(component.address()).toBe(testAddress);
  });
});
