// This file is part of Coog. The COPYRIGHT file at the top level of
// this repository contains the full copyright notices and license terms.

import React from 'react';
import { useArgs } from '@storybook/client-api';

import DuplicateButton from './DuplicateButton';
import { DuplicateButtonProps } from './DuplicateButton.types';

export default {
  title: 'DuplicateButton',
  parameters: {
    actions: {
      handles: ['mouseover', 'click button'],
    },
    component: DuplicateButton,
  },
};

const TemplateDuplicate = (args: DuplicateButtonProps): JSX.Element => {
  const [_, updateArgs] = useArgs();

  const eventEmitter = (value: string) => {
    updateArgs({ isLoadingValidate: true });
    console.log(value);

    setTimeout(() => {
      updateArgs({ isLoadingValidate: false });
    }, 3000);
  };

  return <DuplicateButton {...args} eventEmitter={eventEmitter} />;
};

export const Duplicate = TemplateDuplicate.bind({});

Duplicate.args = {
  isLoadingValidate: false,
  label: 'Dupliquer',
  validateLabel: 'Valider',
  cancelLabel: 'Annuler',
  selection: [
    { name: 'Mutuelle', value: 'mutuelle_sante' },
    { name: 'Emprunteur', value: 'emprunteur' },
  ],
};
