import { Component, Input } from '@angular/core'; import { FormDefinitionComponent, ValueLogicResult } from '@features/configure-forms/form.typing'; import { SelectOption, TypeaheadSelectOption } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { YCModalComponent } from '@yourcause/common/modals'; import { LogicBuilderService } from '../logic-builder.service'; import { GlobalValueLogicGroup, LogicColumnDisplay, LogicValueFormatType } from '../logic-builder.typing'; export interface ValueLogicBuilderModalResponse extends GlobalValueLogicGroup> { delete: boolean; } @Component({ selector: 'gc-value-logic-builder-modal', templateUrl: './value-logic-builder-modal.component.html', styleUrls: ['./value-logic-builder-modal.component.scss'] }) export class ValueLogicBuilderModalComponent extends YCModalComponent< ValueLogicBuilderModalResponse > { @Input() formId: number; @Input() builderName: string; @Input() component: FormDefinitionComponent; @Input() options: (TypeaheadSelectOption|SelectOption)[] = []; @Input() logicValueFormatType: LogicValueFormatType; @Input() currentColumnName: string; @Input() availableColumns: LogicColumnDisplay[]; @Input() sourceColumn: LogicColumnDisplay; @Input() logic: GlobalValueLogicGroup>; @Input() alwaysTrueAvailable: boolean; currentLogic: GlobalValueLogicGroup>; valid = true; constructor ( private logicBuilderService: LogicBuilderService, private analyticsService: AnalyticsService ) { super(); } handleLogicChange (logic: GlobalValueLogicGroup>) { this.currentLogic = logic; } handleValidChange (valid: boolean) { this.valid = valid; } handleSubmit () { if (this.valid) { this.closeModal.emit({ ...(this.currentLogic || this.logic), delete: false }); } this.analyticsService.emitEvent({ eventName: 'Submit logic', eventType: EventType.Click, extras: null }); } handleClear () { this.logic = this.logicBuilderService.getDefaultConditionalValueLogic(); this.currentLogic = this.logic; // Conditions are required for value logic this.handleValidChange(false); this.analyticsService.emitEvent({ eventName: 'Clear logic', eventType: EventType.Click, extras: null }); } deleteRule () { this.closeModal.emit({ ...this.currentLogic, delete: true }); this.analyticsService.emitEvent({ eventName: 'Delete logic', eventType: EventType.Click, extras: null }); } handleCancel () { this.closeModal.emit(); } }