export const delegateTriggerChangeEvent = <T extends HTMLElement>(target: T, value?: unknown) => {
  if (target.tagName === 'INPUT') {
    const inputTarget = target as unknown as HTMLInputElement;
    const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set;
    if (nativeInputValueSetter) {
      if (inputTarget.type !== 'file') {
        nativeInputValueSetter.call(inputTarget, value);
      }
      const simulatedEvent = new Event('change', {bubbles: true});
      inputTarget.dispatchEvent(simulatedEvent);
    }
  }
}
