"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Vertical = exports.ReorderableFullFeatured = exports.Reorderable = exports.NestedFullFeatured = exports.Nested = exports.ExpandedList = exports.Basic = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _react = _interopRequireWildcard(require("react"));

var _List = _interopRequireDefault(require("./List"));

var _ListActions = _interopRequireDefault(require("./ListActions"));

var _ListAction = _interopRequireDefault(require("./ListAction"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
const Basic = args => /*#__PURE__*/_react.default.createElement(_List.default, args);

exports.Basic = Basic;
Basic.args = {
  columns: [{
    key: 'col1',
    title: 'Countr 2',
    type: 'title'
  }, {
    key: 'col2',
    title: 'Population',
    align: 'right'
  }],
  data: [{
    key: '1',
    col1: 'China',
    col2: '1 433 783 686'
  }, {
    key: '2',
    col1: 'India',
    col2: '1 366 417 754'
  }, {
    key: '3',
    col1: 'United States',
    col2: '329 064 917'
  }, {
    key: '4',
    col1: ' Indonesia',
    col2: '270 625 568'
  }, {
    key: '5',
    col1: 'Pakistan',
    col2: '216 565 318'
  }]
};
const Vertical = Basic.bind(null);
exports.Vertical = Vertical;
Vertical.args = { ...Basic.args,
  vertical: 480
};
const Nested = Basic.bind(null);
exports.Nested = Nested;
Nested.args = { ...Basic.args,
  data: [{
    key: '1',
    col1: 'China',
    col2: '1 433 783 686',
    data: [{
      key: '2',
      col1: 'Guangdong',
      col2: '113 460 126'
    }, {
      key: '3',
      col1: 'Shandong',
      col2: '100 471 831'
    }]
  }, {
    key: '4',
    col1: 'India',
    col2: '1 366 417 754',
    data: [{
      key: '5',
      col1: 'Uttar Pradesh',
      col2: '237 882 725'
    }, {
      key: '6',
      col1: 'Bihar',
      col2: '124 799 926'
    }]
  }]
};
const NestedFullFeatured = Nested.bind(null);
exports.NestedFullFeatured = NestedFullFeatured;
NestedFullFeatured.args = { ...Nested.args,
  onSelectionChange: () => {},
  renderRowBody: () => null
};
const ExpandedList = Nested.bind(null);
exports.ExpandedList = ExpandedList;
ExpandedList.args = { ...Nested.args,
  onSelectionChange: () => {},
  renderRowBody: () => 'row body',
  expandedRows: ['1', '2', '4', '6']
};

const Reorderable = args => {
  const {
    data: initialData,
    ...props
  } = args;
  const [data, setData] = (0, _react.useState)(initialData);

  const handleReorderEnd = ({
    oldIndex,
    newIndex
  }) => {
    const nextData = [...data];
    nextData.splice(newIndex, 0, nextData.splice(oldIndex, 1)[0]);
    setData(nextData);
  };

  return /*#__PURE__*/_react.default.createElement(Basic, (0, _extends2.default)({
    data: data,
    reorderable: true,
    onReorderEnd: handleReorderEnd
  }, props));
};

exports.Reorderable = Reorderable;
Reorderable.args = { ...Basic.args
};
const ReorderableFullFeatured = Reorderable.bind(null);
exports.ReorderableFullFeatured = ReorderableFullFeatured;
ReorderableFullFeatured.args = { ...Reorderable.args,
  columns: [...Reorderable.args.columns, {
    key: 'actions',
    type: 'actions',
    // eslint-disable-next-line react/display-name
    render: () => /*#__PURE__*/_react.default.createElement(_ListActions.default, null, /*#__PURE__*/_react.default.createElement(_ListAction.default, {
      icon: "clip",
      primary: true
    }), /*#__PURE__*/_react.default.createElement(_ListAction.default, {
      icon: "clock",
      primary: true
    }), /*#__PURE__*/_react.default.createElement(_ListAction.default, {
      icon: "clone",
      primary: true
    }))
  }],
  onSelectionChange: () => {},
  renderRowBody: () => null
};