"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Advanced = exports.Regular = exports.default = void 0;

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

var _README = _interopRequireDefault(require("./README.mdx"));

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

var _reactDropzone = _interopRequireWildcard(require("react-dropzone"));

var _iconsReact = require("@wfp/icons-react");

var _classnames = _interopRequireDefault(require("classnames"));

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(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; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var _default = {
  title: 'Components/Forms/FileUploader (react-dropzone)',
  parameters: {
    componentSubtitle: 'Component',
    status: 'released',
    mdx: _README.default,
    introText: "[react-dropzone](https://github.com/react-dropzone/react-dropzone) for handling file uploads. It allows using simple react hooks to create a HTML5-compliant drag'n'drop zone for files."
  }
};
exports.default = _default;

var Regular = function Regular(args) {
  var _useState = (0, _react.useState)([]),
      _useState2 = _slicedToArray(_useState, 2),
      file = _useState2[0],
      setfile = _useState2[1];

  var files = file.map(function (file) {
    return /*#__PURE__*/_react.default.createElement(_List.ListItem, {
      key: file.path
    }, file.path, " - ", Math.round(file.size / 1000), " kB");
  });
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactDropzone.default, {
    onDrop: function onDrop(acceptedFiles) {
      return setfile(acceptedFiles);
    }
  }, function (_ref) {
    var getRootProps = _ref.getRootProps,
        getInputProps = _ref.getInputProps;
    return /*#__PURE__*/_react.default.createElement("section", {
      className: "wfp--dropzone"
    }, /*#__PURE__*/_react.default.createElement("div", getRootProps({
      className: 'wfp--dropzone__input'
    }), /*#__PURE__*/_react.default.createElement("input", getInputProps()), /*#__PURE__*/_react.default.createElement("div", null, "Drag 'n' drop some files here, or click to select files")));
  }), file.length > 0 && /*#__PURE__*/_react.default.createElement("aside", {
    className: "wfp--dropzone__file-list"
  }, /*#__PURE__*/_react.default.createElement("h4", null, "Files"), /*#__PURE__*/_react.default.createElement(_List.List, null, files)));
};

exports.Regular = Regular;
Regular.parameters = {
  html: false,
  docs: {
    source: {
      code: " import Dropzone from 'react-dropzone';\n\n      export const Regular = (args) => {\n        const [file, setfile] = useState([])\n      \n        const files = file.map((file) => (\n          <ListItem key={file.path}>\n            {file.path} - {Math.round(file.size / 1000)} kB\n          </ListItem>\n        ));\n      \n        return(\n        <>\n        <Dropzone onDrop={(acceptedFiles) => setfile(acceptedFiles)}>\n          {({ getRootProps, getInputProps }) => (\n            <section className=\"wfp--dropzone\">\n              <div {...getRootProps({ className: 'wfp--dropzone__input' })}>\n                <input {...getInputProps()} />\n                <div>Drag 'n' drop some files here, or click to select files</div>\n              </div>\n            </section>\n          )}\n        </Dropzone>\n        <aside className=\"wfp--dropzone__file-list\">\n              <h4>Files</h4>\n              <List>{files}</List>\n        </aside>\n        </>\n        \n      )\n      };"
    }
  }
};

var Advanced = function Advanced(args) {
  var _useDropzone = (0, _reactDropzone.useDropzone)(),
      acceptedFiles = _useDropzone.acceptedFiles,
      getRootProps = _useDropzone.getRootProps,
      getInputProps = _useDropzone.getInputProps,
      isDragActive = _useDropzone.isDragActive;

  var files = acceptedFiles.map(function (file) {
    return /*#__PURE__*/_react.default.createElement(_List.ListItem, {
      key: file.path
    }, file.path, " - ", Math.round(file.size / 1000), " kB");
  });
  var wrapperClassNames = (0, _classnames.default)('wfp--dropzone__input', {
    'wfp--dropzone__input--drag-active': isDragActive
  });
  return /*#__PURE__*/_react.default.createElement("section", {
    className: "wfp--dropzone"
  }, /*#__PURE__*/_react.default.createElement("div", getRootProps({
    isDragActive: isDragActive,
    className: wrapperClassNames
  }), /*#__PURE__*/_react.default.createElement("input", getInputProps()), /*#__PURE__*/_react.default.createElement(_iconsReact.UploadGlyph, {
    className: "wfp--dropzone__icon"
  }), /*#__PURE__*/_react.default.createElement("div", null, "Drop files or click here to upload")), files.length > 0 && /*#__PURE__*/_react.default.createElement("aside", {
    className: "wfp--dropzone__file-list"
  }, /*#__PURE__*/_react.default.createElement("h4", null, "Files"), /*#__PURE__*/_react.default.createElement(_List.List, null, files)));
};

exports.Advanced = Advanced;
Advanced.parameters = {
  html: false,
  docs: {
    source: {
      code: "\nimport Dropzone, { useDropzone } from 'react-dropzone';\nimport { Icon, List, ListItem } from '@wfp/ui';\nimport { Upload16 } from '@wfp/icons-react';\nimport classNames from 'classnames';\n\nexport const Advanced = (args) => {\n  const {\n    acceptedFiles,\n    getRootProps,\n    getInputProps,\n    isDragActive,\n  } = useDropzone();\n\n  const files = acceptedFiles.map((file) => (\n    <ListItem key={file.path}>\n      {file.path} - {Math.round(file.size / 1000)} kB\n    </ListItem>\n  ));\n\n  const wrapperClassNames = classNames('wfp--dropzone__input', {\n    'wfp--dropzone__input--drag-active': isDragActive\n  });\n\n  return (\n    <section className=\"wfp--dropzone\">\n      <div {...getRootProps({ isDragActive, className: wrapperClassNames })}>\n        <input {...getInputProps()} />\n        <Upload16 className=\"wfp--dropzone__icon\" />\n        <div>Drop files or click here to upload</div>\n      </div>\n      <aside className=\"wfp--dropzone__file-list\">\n        <h4>Files</h4>\n        <List>{files}</List>\n      </aside>\n    </section>\n  );\n}"
    }
  }
};