import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import h from 'react-hyperscript'
import jsf from 'json-schema-faker'

import profileSchema from '../../agents/schemas/profile'
import SingleViewProduct from '../components/SingleViewProduct'

// https://github.com/root-systems/cobuy/wiki/Models
const mockAgents = {
  1: {
    id: 1,
    profile: jsf(profileSchema)
  },
  2: {
    id: 2,
    profile: jsf(profileSchema)
  },
  3: {
    id: 3,
    profile: jsf(profileSchema)
  },
  4: {
    id: 4,
    profile: jsf(profileSchema)
  }
}
const mockProductInfo = {
  id: 188,
  resourceTypeId: 123,
  resourceType: {
    id: 123,
    name: 'crayons',
    description: 'these are crayons. look at all the pretty colours! they are made of beeswax. you could probably eat them and not die.',
    image: 'http://www.mercurius-australia.com/site/images/1250623.jpg'
  },
  priceSpecs: [
    {
      id: 456,
      productId: 188,
      minimum: '10',
      price: '9.99',
      currency: 'NZD'
    },
    {
      id: 457,
      productId: 188,
      minimum: '100',
      price: '7.99',
      currency: 'NZD'
    }
  ],
  facets: [
    {
      id: 345,
      resourceTypeId: 123,
      name: 'colour',
      description: 'the colour of each crayon',
      values: [
        {
          id: 678,
          resourceTypeFacetId: 345,
          name: 'blue'
        },
        {
          id: 679,
          resourceTypeFacetId: 345,
          name: 'orange'
        },
        {
          id: 680,
          resourceTypeFacetId: 345,
          name: 'purple'
        }
      ]
    },
    {
      id: 346,
      resourceTypeId: 123,
      name: 'size',
      description: 'the size of each crayon',
      values: [
        {
          id: 681,
          resourceTypeFacetId: 346,
          name: 'small'
        },
        {
          id: 682,
          resourceTypeFacetId: 346,
          name: 'medium'
        },
        {
          id: 683,
          resourceTypeFacetId: 346,
          name: 'large'
        }
      ]
    }
  ]
}

const props = {
  product: mockProductInfo,
  agents: mockAgents,
  currentAgent: mockAgents[0],
  orderIntentsByAgentPrice: {
    1: {
      456: {
        desiredQuantity: '10'
      },
      457: {
        desiredQuantity: '15'
      }
    }
  },
  onSubmit: action('submit')
}

storiesOf('ordering.SingleViewProduct', module)
  .add('default', () => (
    h(SingleViewProduct, {
      product: mockProductInfo,
      onSubmit: action('submit')
    })
  ))

@@ -157,16 +157,47 @@
 a-faker'
+%0Aimport %7B values %7D from 'ramda'
 %0A%0Aimport
@@ -2149,16 +2149,23 @@
 agents: 
+values(
 mockAgen
@@ -2166,16 +2166,17 @@
 ckAgents
+)
 ,%0A  curr
@@ -2196,17 +2196,17 @@
 kAgents%5B
-0
+1
 %5D,%0A  ord
@@ -2220,26 +2220,26 @@
 tsBy
-Agent
 Price
+Agent
 : %7B%0A    
 1: %7B
@@ -2234,17 +2234,19 @@
 : %7B%0A    
-1
+456
 : %7B%0A    
@@ -2243,27 +2243,25 @@
 56: %7B%0A      
-456
+1
 : %7B%0A        
@@ -2289,24 +2289,29 @@
 %0A      %7D,%0A  
+  %7D,%0A
     457: %7B%0A 
@@ -2305,24 +2305,35 @@
 %0A    457: %7B%0A
+      1: %7B%0A
         desi
@@ -2504,80 +2504,13 @@
 ct, 
-%7B%0A      product: mockProductInfo,%0A      onSubmit: action('submit')%0A    %7D
+props
 )%0A  

fix storybook for single product view