import React from 'react';
import { FormField, InputArea } from '@wix/design-system';
import { BaseInputProps } from '../BaseInput';
import { Field } from '../Field';
import { dataHooks } from '../dataHooks';
import { useTextInput } from '../useTextInput';

export interface LongTextProps extends BaseInputProps<string> {}

export const LongText = ({
  dataHook,
  schema,
  initialValue,
  onChange,
}: LongTextProps) => {
  const { value, charCount, handleChange } = useTextInput({
    initialValue,
    maxLength: schema.maxLength,
    onChange,
  });

  return (
    <Field dataHook={dataHook} type={schema.type}>
      <FormField
        dataHook={dataHooks.Label}
        label={schema.label}
        charCount={charCount}
      >
        <InputArea
          dataHook={dataHooks.Input}
          value={value}
          onChange={handleChange}
        />
      </FormField>
    </Field>
  );
};
