import {
  Constants,
  type ComponentBase,
  type ModalSubmitInteractionDataLabelComponent,
  type ModalSubmitInteractionDataStringSelectComponent,
  type ModalSubmitInteractionDataTextInputComponent,
} from '@projectdysnomia/dysnomia';

export function isModalLabel(component: ComponentBase): component is ModalSubmitInteractionDataLabelComponent {
  return component.type === Constants.ComponentTypes.LABEL;
}

export function isModalTextInput(component: ComponentBase): component is ModalSubmitInteractionDataTextInputComponent {
  return component.type === Constants.ComponentTypes.TEXT_INPUT;
}

export function isModalSelect(component: ComponentBase): component is ModalSubmitInteractionDataStringSelectComponent {
  return component.type === Constants.ComponentTypes.STRING_SELECT;
}

export function componentHasIdPrefix(component: ComponentBase, prefix: string): boolean {
  return (isModalTextInput(component) || isModalSelect(component)) && component.custom_id.startsWith(prefix);
}
