import {
  Canvas,
  Meta,
  Story,
  ArgsTable
} from '@storybook/addon-docs'
import RplFormDropdown from './RplFormDropdown.vue'
import { RplButton } from '@dpc-sdp/ripple-ui-core/vue'

export const SingleTemplate = (args) => ({
  components: { RplFormDropdown, RplButton },
  setup() {
    return { args }
  },
  data: () => ({ currentValue: null }),
  methods: {
    onChange: function(val) {
      this.currentValue = val
    }
  },
  template: `
  <RplButton class="rpl-u-margin-b-6">Button above to test keyboard behaviour (not part of dropdown)</RplButton>
  <RplFormDropdown v-bind="args" :value="currentValue" @onChange="onChange" />
  <RplButton class="rpl-u-margin-t-6">Button below to test keyboard behaviour (not part of dropdown)</RplButton>
  `
})

<Meta title='Forms/Dropdown' component={RplFormDropdown} args={{
      id: 'dropdown-default',
      placeholder: 'Select',
      options: [
        {
          id: 'item-1',
          value: 'item-1',
          label: 'Value 1'
        },
        {
          id: 'item-2',
          value: 'item-2',
          label: 'Value 2'
        },
        {
          id: 'item-3',
          value: 'item-3',
          label: 'Value 3'
        }
      ]
    }} />

# Forms

<ArgsTable of={RplFormDropdown} />

<Canvas>
  <Story
    name='Single select - few items'
    args={{
      id: 'dropdown-single',
      multiple: false,
    }}
  >
    {SingleTemplate.bind()}
  </Story>
</Canvas>

<Canvas>
  <Story
    name='Single select - many items'
    args={{
      id: 'dropdown-single',
      multiple: false,
      options: [...Array(10).keys()].map((i) => ({
        id: `item-${i + 1}`,
        value: `item-${i + 1}`,
        label: `Value ${i + 1}`
      }))
    }}
  >
    {SingleTemplate.bind()}
  </Story>
</Canvas>

<Canvas>
  <Story
    name='Multi select - few items'
    args={{
      id: 'dropdown-multi',
      multiple: true,
    }}
  >
    {SingleTemplate.bind()}
  </Story>
</Canvas>

<Canvas>
  <Story
    name='Multi select - many items'
    args={{
      id: 'dropdown-multi',
      multiple: true,
      options: [...Array(10).keys()].map((i) => ({
        id: `item-${i + 1}`,
        value: `item-${i + 1}`,
        label: `Value ${i + 1}`
      }))
    }}
  >
    {SingleTemplate.bind()}
  </Story>
</Canvas>

<Canvas>
  <Story
    name='Reverse variant'
    parameters={{
      background: 'gray'
    }}
    args={{
      id: 'dropdown-reverse',
      variant: 'reverse',
    }}
  >
    {SingleTemplate.bind()}
  </Story>
</Canvas>

<Canvas>
  <Story
    name='Long labels'
    args={{
      id: 'dropdown-long-labels',
      options: [
        {
          id: 'item-1',
          value: 'item-1',
          label: 'Value 1'
        },
        {
          id: 'item-2',
          value: 'item-2',
          label: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
        },
        {
          id: 'item-3',
          value: 'item-3',
          label: 'Value 3'
        }
      ]
    }}
  >
    {SingleTemplate.bind()}
  </Story>
</Canvas>

<Canvas>
  <Story
    name='Inactive'
    args={{
      id: 'dropdown-long-labels',
      disabled: true
    }}
  >
    {SingleTemplate.bind()}
  </Story>
</Canvas>
