import React from 'react';
import {useActionState} from './helper';
import FieldDynamicArray from '../src/components/FieldDynamicArray';
import {Wrapper} from './ui';

export default {
  title: 'FieldDynamicArray',
  component: FieldDynamicArray,
};


export const NumberType = () => {
  const [value, setValue] = useActionState("onChange", [1,2,3]);

  return (
    <Wrapper>
      <FieldDynamicArray
        label="Foobar"
        type="number"
        value={value}
        onChange={setValue}
      />
    </Wrapper>
  );
};

export const UrlType = () => {
  const [value, setValue] = useActionState("onChange", ["http://example.com"]);

  return (
    <Wrapper>
      <FieldDynamicArray
        label="Foobar"
        type="url"
        value={value}
        onChange={setValue}
      />
    </Wrapper>
  );
};

export const EnumType = () => {
  const [value, setValue] = useActionState("onChange", ["foo"]);

  return (
    <Wrapper>
      <FieldDynamicArray
        label="Foobar"
	fieldSpec={{values: {"foo": null, "bar": null, "baz": null}}}
        type="enum"
        value={value}
        onChange={setValue}
      />
    </Wrapper>
  );
};
