import { RefObject } from 'react';

import { Textarea } from '@chakra-ui/react';

import { FormGroup } from '@/components/form/FormGroup';
import { UseFormidableReturn } from '@/components/form/Formidable';

export type FormTextareaProps = {
  form: UseFormidableReturn;
  variableName: string;
  ref?: RefObject<any>;
  label?: string;
  placeholder?: string;
  isRequired?: boolean;
};

export const FormTextarea = ({
  form,
  variableName,
  ref,
  placeholder,
  ...rest
}: FormTextareaProps) => {
  return (
    <FormGroup
      isModify={form.isModify[variableName]}
      onRestore={() => form.restoreValue({ [variableName]: true })}
      {...rest}
    >
      <Textarea
        ref={ref}
        value={form.values[variableName]}
        onChange={(e) => form.setValues({ [variableName]: e.target.value })}
      />
    </FormGroup>
  );
};
