import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState } from 'react';
import markdown from './README.mdx';
import { List, ListItem } from '../List';
import Dropzone, { useDropzone } from 'react-dropzone';
import { UploadGlyph } from '@wfp/icons-react';
import classNames from 'classnames';
export default {
  title: 'Components/Forms/FileUploader (react-dropzone)',
  parameters: {
    componentSubtitle: 'Component',
    status: 'released',
    mdx: markdown,
    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."
  }
};
export var Regular = function Regular(args) {
  var _useState = useState([]),
      _useState2 = _slicedToArray(_useState, 2),
      file = _useState2[0],
      setfile = _useState2[1];

  var files = file.map(function (file) {
    return /*#__PURE__*/React.createElement(ListItem, {
      key: file.path
    }, file.path, " - ", Math.round(file.size / 1000), " kB");
  });
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropzone, {
    onDrop: function onDrop(acceptedFiles) {
      return setfile(acceptedFiles);
    }
  }, function (_ref) {
    var getRootProps = _ref.getRootProps,
        getInputProps = _ref.getInputProps;
    return /*#__PURE__*/React.createElement("section", {
      className: "wfp--dropzone"
    }, /*#__PURE__*/React.createElement("div", getRootProps({
      className: 'wfp--dropzone__input'
    }), /*#__PURE__*/React.createElement("input", getInputProps()), /*#__PURE__*/React.createElement("div", null, "Drag 'n' drop some files here, or click to select files")));
  }), file.length > 0 && /*#__PURE__*/React.createElement("aside", {
    className: "wfp--dropzone__file-list"
  }, /*#__PURE__*/React.createElement("h4", null, "Files"), /*#__PURE__*/React.createElement(List, null, files)));
};
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      };"
    }
  }
};
export var Advanced = function Advanced(args) {
  var _useDropzone = useDropzone(),
      acceptedFiles = _useDropzone.acceptedFiles,
      getRootProps = _useDropzone.getRootProps,
      getInputProps = _useDropzone.getInputProps,
      isDragActive = _useDropzone.isDragActive;

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