import { ForgotPassword } from './ForgotPassword';
import { I18nProvider } from '../../../providers/I18nProvider';

export default {
  title: 'Views/ForgotPassword',
  component: ForgotPassword,
  tags: ['autodocs'],
  decorators: [
    (Story) => (
      <I18nProvider language="es-AR">
        <Story />
      </I18nProvider>
    ),
  ],
  argTypes: {
    variant: {
      control: 'select',
      options: ['default', 'hexa-login'],
      description: 'Variante del componente',
    },
    loading: {
      control: 'boolean',
      description: 'Estado de carga',
    },
    error: {
      control: 'text',
      description: 'Error general del servidor',
    },
  },
};

// Estado por defecto
export const Default = {
  args: {
    onBackToLogin: () => {
      console.log('Back to login clicked');
      alert('Volver al login');
    },
    onSubmit: async ({ email, countryCode }) => {
      console.log('Forgot password data:', { email, countryCode });
      await new Promise((resolve) => setTimeout(resolve, 2000));
      return { resetLink: 'https://example.com/reset-password' };
    },
  },
};

// Estado de carga
export const Loading = {
  args: {
    loading: true,
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async () => {
      await new Promise((resolve) => setTimeout(resolve, 5000));
    },
  },
};

// Estado de éxito
export const Success = {
  args: {
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async ({ email }) => {
      console.log('Email:', email);
      await new Promise((resolve) => setTimeout(resolve, 1000));
      return { resetLink: 'https://example.com/reset-password?token=abc123' };
    },
  },
};

// Con error del servidor
export const WithError = {
  args: {
    error: 'No se encontró una cuenta asociada a este correo electrónico.',
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async () => {
      throw new Error('Usuario no encontrado');
    },
  },
};

// Error 404
export const Error404 = {
  args: {
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async () => {
      const error = new Error('Not found');
      error.response = { status: 404, data: { message: 'Usuario no encontrado' } };
      throw error;
    },
  },
};

// Error 400
export const Error400 = {
  args: {
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async () => {
      const error = new Error('Bad request');
      error.response = { status: 400, data: { message: 'Email inválido' } };
      throw error;
    },
  },
};

// Error 500
export const Error500 = {
  args: {
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async () => {
      const error = new Error('Server error');
      error.response = { status: 500 };
      throw error;
    },
  },
};

// Variante hexa-login
export const HexaLogin = {
  args: {
    variant: 'hexa-login',
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async ({ email }) => {
      console.log('Email:', email);
      await new Promise((resolve) => setTimeout(resolve, 2000));
      return { resetLink: 'https://example.com/reset-password' };
    },
  },
};

// Versión en español
export const Spanish = {
  decorators: [
    (Story) => (
      <I18nProvider language="es-AR">
        <Story />
      </I18nProvider>
    ),
  ],
  args: {
    onBackToLogin: () => {
      alert('Volver al login');
    },
    onSubmit: async ({ email }) => {
      console.log('Email:', email);
      await new Promise((resolve) => setTimeout(resolve, 2000));
      return { resetLink: 'https://example.com/reset-password' };
    },
  },
};

// Versión en portugués
export const Portuguese = {
  decorators: [
    (Story) => (
      <I18nProvider language="pt-BR">
        <Story />
      </I18nProvider>
    ),
  ],
  args: {
    onBackToLogin: () => {
      alert('Volver ao login');
    },
    onSubmit: async ({ email }) => {
      console.log('Email:', email);
      await new Promise((resolve) => setTimeout(resolve, 2000));
      return { resetLink: 'https://example.com/reset-password' };
    },
  },
};


