'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _stringify = require('babel-runtime/core-js/json/stringify');

var _stringify2 = _interopRequireDefault(_stringify);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _group = require('@vx/group');

var _hierarchy = require('@vx/hierarchy');

var _shape = require('@vx/shape');

var _d3Hierarchy = require('d3-hierarchy');

var _gradient = require('@vx/gradient');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _jsxFileName = '/Users/hshoff/code/vx/packages/vx-demo/components/tiles/dendrogram.js';


var raw = {
  "name": "$",
  "children": [{
    "name": "A",
    "children": [{ "name": "A1" }, { "name": "A2" }, { "name": "C",
      "children": [{
        "name": "C1"
      }] }] }, {
    "name": "B",
    "children": [{ "name": "B1" }, { "name": "B2" }, { "name": "B3" }] }, {
    "name": "X",
    "children": [{
      "name": "Z"
    }]
  }]
};

function Node(_ref) {
  var node = _ref.node,
      events = _ref.events;

  var width = 40;
  var height = 20;
  return _react2.default.createElement(_group.Group, { top: node.y, left: node.x, __source: {
      fileName: _jsxFileName,
      lineNumber: 38
    }
  }, node.depth === 0 && _react2.default.createElement('rect', {
    width: width,
    height: height,
    y: -height / 2,
    x: -width / 2,
    fill: 'url(\'#top\')',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 40
    }
  }), node.depth !== 0 && _react2.default.createElement('circle', {
    r: 12,
    fill: '#306c90',
    stroke: node.children ? "white" : "#ddf163",
    onClick: function onClick() {
      if (!events) return;
      alert('clicked: ' + (0, _stringify2.default)(node.data.name));
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 49
    }
  }), _react2.default.createElement('text', {
    dy: ".33em",
    fontSize: 9,
    fontFamily: 'Arial',
    textAnchor: "middle",
    style: { pointerEvents: "none" },
    fill: node.depth === 0 ? "#286875" : node.children ? "white" : "#ddf163",
    __source: {
      fileName: _jsxFileName,
      lineNumber: 59
    }
  }, node.data.name));
}

function Link(_ref2) {
  var link = _ref2.link;

  return _react2.default.createElement(_shape.LinkVertical, {
    data: link,
    stroke: '#f7f7f3',
    strokeWidth: '1',
    strokeOpacity: 0.2,
    fill: 'none',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 75
    }
  });
}

exports.default = function (_ref3) {
  var width = _ref3.width,
      height = _ref3.height,
      _ref3$events = _ref3.events,
      events = _ref3$events === undefined ? false : _ref3$events,
      _ref3$margin = _ref3.margin,
      margin = _ref3$margin === undefined ? {
    top: 40,
    left: 0,
    right: 0,
    bottom: 110
  } : _ref3$margin;

  if (width < 10) return null;
  var data = (0, _d3Hierarchy.hierarchy)(raw);
  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 99
    }
  }, _react2.default.createElement(_gradient.LinearGradient, { id: 'top', from: '#79d259', to: '#37ac8c', __source: {
      fileName: _jsxFileName,
      lineNumber: 100
    }
  }), _react2.default.createElement('rect', {
    width: width,
    height: height,
    rx: 14,
    fill: '#306c90',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 101
    }
  }), _react2.default.createElement(_hierarchy.Cluster, {
    top: margin.top,
    left: margin.left,
    root: data,
    size: [width - margin.left - margin.right, height - margin.top - margin.bottom],
    nodeComponent: function nodeComponent(_ref4) {
      var node = _ref4.node;
      return _react2.default.createElement(Node, { node: node, events: events, __source: {
          fileName: _jsxFileName,
          lineNumber: 115
        }
      });
    },
    linkComponent: Link,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 107
    }
  }));
};