var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import R from 'ramda';
import React from 'react';
import { Seed } from 'react-seeds';
import Choice from '../ui/Choice';
import Field from '../ui/Field';
import { recordField } from '../stylers';

var types = [{ value: 'string', title: 'Text' }, { value: 'boolean', title: 'Yes / No' }, { value: 'number', title: 'Number' }, { value: 'array', title: 'List' }, { value: 'object', title: 'Record' }];

var valueEditorForType = R.cond([[R.equals('string'), R.always(function (string) {
    return React.createElement(Field, _extends({ value: string }, recordField));
})], [R.equals('boolean'), R.always(function (boolean) {
    return React.createElement(Choice, { value: boolean, items: [{ value: true, title: 'Yes' }, { value: false, title: ' No' }] });
})], [R.equals('number'), R.always(function (number) {
    return React.createElement('input', { type: 'number', value: number });
})], [R.equals('array'), function () {
    return function (items) {
        return React.createElement(
            'div',
            null,
            items.map(function (item, index) {
                return React.createElement(Item, { key: index, id: index, value: item });
            })
        );
    };
}], [R.equals('object'), function () {
    return function (object) {
        return React.createElement(RecordEditor, { object: object });
    };
}]]);

var valueEditorForValue = R.converge(R.call, [R.pipe(R.type, R.toLower, valueEditorForType), R.identity]);

function Item(_ref) {
    var id = _ref.id,
        value = _ref.value;

    return React.createElement(
        Seed,
        { column: true },
        React.createElement(
            Seed,
            { row: true, grow: 1 },
            React.createElement('input', { value: id, style: { fontWeight: 'bold' } }),
            React.createElement(Choice, { value: R.type(value).toLowerCase(), items: types })
        ),
        valueEditorForValue(value)
    );
}

export default function RecordEditor(_ref2) {
    var object = _ref2.object,
        seedProps = _objectWithoutProperties(_ref2, ['object']);

    return React.createElement(
        Seed,
        _extends({ column: true }, seedProps),
        Object.keys(object).map(function (key) {
            return React.createElement(Item, { key: key,
                id: key,
                value: object[key]
            });
        })
    );
}