import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { DialogContentDirective } from '@isa/ui/dialog';
import {
  RewardSelectionFacade,
  RewardSelectionItem,
} from '@isa/checkout/data-access';
import { RewardSelectionItemsComponent } from './reward-selection-items/reward-selection-items.component';
import { RewardSelectionActionsComponent } from './reward-selection-actions/reward-selection-actions.component';
import { RewardSelectionErrorComponent } from './reward-selection-error/reward-selection-error.component';
import { RewardSelectionStore } from './store/reward-selection-dialog.store';

export type RewardSelectionDialogData = {
  rewardSelectionItems: RewardSelectionItem[];
  customerRewardPoints: number;
  closeText: string;
};

export type RewardSelectionDialogResult =
  | {
      rewardSelectionItems: RewardSelectionItem[];
    }
  | undefined;

@Component({
  selector: 'lib-reward-selection-dialog',
  templateUrl: './reward-selection-dialog.component.html',
  styleUrl: './reward-selection-dialog.component.css',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [
    RewardSelectionItemsComponent,
    RewardSelectionActionsComponent,
    RewardSelectionErrorComponent,
  ],
  providers: [RewardSelectionStore, RewardSelectionFacade],
})
export class RewardSelectionDialogComponent extends DialogContentDirective<
  RewardSelectionDialogData,
  RewardSelectionDialogResult
> {
  store = inject(RewardSelectionStore);

  constructor() {
    super();
    this.store.initState(this.data);
  }
}
