import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { ProductImageService } from '@cdn/product-image';
import { ApplicationService } from '@core/application';
import { BreadcrumbService } from '@core/breadcrumb';
import { CoreCommandModule, CommandService } from '@core/command';
import { CrmCustomerService } from '@domain/crm';
import { DomainGoodsService, DomainOmsService, DomainReceiptService } from '@domain/oms';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator';
import { DateAdapter } from '@ui/common';
import { UiModalService } from '@ui/modal';
import { SharedGoodsInOutOrderDetailsModule } from 'apps/shared/goods-in-out/src/lib/goods-in-out-order-details';
import { of } from 'rxjs';
import { GoodsInDetailsComponent } from '.';

describe('GoodsInDetailsCompoonent', () => {
  let spectator: Spectator<GoodsInDetailsComponent>;

  let breadcrumbServiceMock = {
    addOrUpdateBreadcrumbIfNotExists: jasmine.createSpy(),
    getBreadcrumbsByKeyAndTags$: jasmine.createSpy(),
  };
  let dateAdapterMock = {
    today: () => {},
    addCalendarDays: () => {},
  };

  let routerMock: jasmine.SpyObj<Router>;
  let activatedRouteMock = {
    orderId: 1,
    orderItemId: 2,
    processingStatus: 16,
    compartmentCode: 3,
  };

  const createComponent = createComponentFactory({
    component: GoodsInDetailsComponent,
    imports: [RouterTestingModule, SharedGoodsInOutOrderDetailsModule, CoreCommandModule],
    providers: [
      mockProvider(DomainGoodsService),
      mockProvider(DomainOmsService),
      mockProvider(ApplicationService),
      mockProvider(CommandService),
      mockProvider(CrmCustomerService),
      mockProvider(DomainReceiptService),
      mockProvider(UiModalService),
      mockProvider(ProductImageService),
    ],
  });

  beforeEach(async () => {
    spectator = createComponent({
      providers: [
        { provide: BreadcrumbService, useValue: breadcrumbServiceMock },
        {
          provide: ActivatedRoute,
          useValue: {
            params: of(activatedRouteMock),
          },
        },
        {
          provide: DateAdapter,
          useValue: dateAdapterMock,
        },
      ],
    });
    routerMock = spectator.inject(Router);
  });

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

  // describe('shared-goods-in-out-order-details', () => {
  //   it('should render', () => {
  //     expect(spectator.query('shared-goods-in-out-order-details')).toBeVisible();
  //   });
  // });

  // describe('shared-goods-in-out-order-details-header', () => {
  //   it('should render', () => {
  //     expect(spectator.query('shared-goods-in-out-order-details-header')).toBeVisible();
  //   });
  // });

  // describe('shared-goods-in-out-order-details-item', () => {
  //   it('should render', () => {
  //     expect(spectator.query('shared-goods-in-out-order-details-item')).toBeVisible();
  //   });
  // });

  // describe('shared-goods-in-out-order-details-tags', () => {
  //   it('should not render when no selectedItem is set', () => {
  //     expect(spectator.query('shared-goods-in-out-order-details-tags')).not.toBeVisible();
  //   });

  //   it('should render when selectedItem$ with command arrived is set', () => {
  //     spectator.component.selectedItem$ = of({ orderItemId: 1, actions: [{ command: 'ARRIVED' }] });
  //     spectator.detectComponentChanges();
  //     expect(spectator.query('shared-goods-in-out-order-details-tags')).toBeVisible();
  //   });
  // });

  // describe('shared-goods-in-out-order-details-covers', () => {
  //   it('should render', () => {
  //     expect(spectator.query('shared-goods-in-out-order-details-covers')).toBeVisible();
  //   });
  // });

  // describe('updateBreadcrumb', () => {
  //   it('should call addOrUpdateBreadcrumbIfNotExists', () => {
  //     const orderNumber = '1';
  //     const orderItemId = 2;
  //     const processingStatus = 16;

  //     spectator.component.updateBreadcrumb({ orderNumber, orderItemId, processingStatus });
  //     expect(breadcrumbServiceMock.addOrUpdateBreadcrumbIfNotExists).toHaveBeenCalledWith({
  //       key: 'goods-in',
  //       name: orderNumber,
  //       path: `/goods/in/details/order/${orderNumber}/item/${orderItemId}/${processingStatus}`,
  //       section: 'branch',
  //       tags: ['goods-in', 'details', orderNumber],
  //     });
  //   });
  // });

  // describe('navigate', () => {
  //   it('should navigate to /goods/in when parameter is "search"', () => {
  //     spyOn(routerMock, 'navigate');
  //     spectator.component.navigate('search');
  //     expect(routerMock.navigate).toHaveBeenCalledWith(['/goods/in']);
  //   });

  //   it('should call navigateToEdit when parameter is "edit"', () => {
  //     spyOn(spectator.component, 'navigateToEdit');
  //     spectator.component.navigate('edit');
  //     expect(spectator.component.navigateToEdit).toHaveBeenCalled();
  //   });
  // });

  // describe('navigateToEdit', () => {
  //   it('should navigate to /goods/in/details/compartment when compartmentCode is set', async () => {
  //     activatedRouteMock.compartmentCode = 3;
  //     spyOn(routerMock, 'navigate');
  //     await spectator.component.navigateToEdit();
  //     expect(routerMock.navigate).toHaveBeenCalledWith([
  //       `/goods/in/details/compartment/${activatedRouteMock.compartmentCode}/item/${activatedRouteMock.orderItemId}/${activatedRouteMock.processingStatus}/edit`,
  //     ]);
  //   });

  //   it('should navigate to /goods/in/details/order when compartmentCode is not set', async () => {
  //     activatedRouteMock.compartmentCode = undefined;
  //     spyOn(routerMock, 'navigate');
  //     await spectator.component.navigateToEdit();
  //     expect(routerMock.navigate).toHaveBeenCalledWith([
  //       `/goods/in/details/order/${activatedRouteMock.orderId}/item/${activatedRouteMock.orderItemId}/${activatedRouteMock.processingStatus}/edit`,
  //     ]);
  //   });
  // });
});
