import { computed, Signal, signal, WritableSignal } from '@angular/core';

export interface UsePasswordToggleResult {
  readonly visible: WritableSignal<boolean>;
  readonly type: Signal<'text' | 'password'>;
  toggle(): void;
}

export const usePasswordToggle = (initialVisible = false): UsePasswordToggleResult => {
  const visible = signal(initialVisible);
  const type = computed<'text' | 'password'>(() => (visible() ? 'text' : 'password'));

  return {
    visible,
    type,
    toggle: () => visible.update((current) => !current),
  };
};
