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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useRef, useState, useCallback } from 'react';
import styled from 'styled-components';
import { Box, ShowMoreButton } from '../..';
import useOverflow from './useOverflow';
var StyledDiv = styled.div.withConfig({
  displayName: "ShowMore__StyledDiv",
  componentId: "sc-r7r7ep-0"
})(["display:-webkit-box;-webkit-line-clamp:", ";-webkit-box-orient:vertical;overflow:hidden;"], function (p) {
  return p.showMoreClicked ? 'auto' : p.linesToClamp;
});
export var ShowMore = function ShowMore(_ref) {
  var children = _ref.children,
    _ref$linesToClamp = _ref.linesToClamp,
    linesToClamp = _ref$linesToClamp === void 0 ? 2 : _ref$linesToClamp,
    _ref$onShowMore = _ref.onShowMore,
    onShowMore = _ref$onShowMore === void 0 ? function () {} : _ref$onShowMore,
    showMoreText = _ref.showMoreText;
  var containerRef = useRef(null);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    showMoreClicked = _useState2[0],
    setShowMoreClicked = _useState2[1];
  var onShowMoreClick = useCallback(function (e) {
    onShowMore(e);
    setShowMoreClicked(true);
  }, [onShowMore]);
  var isOverflowing = useOverflow(containerRef, children);
  var showMoreButton = isOverflowing && !showMoreClicked;
  return React.createElement(React.Fragment, null, React.createElement(StyledDiv, {
    ref: containerRef,
    showMoreButton: showMoreButton,
    showMoreClicked: showMoreClicked,
    linesToClamp: linesToClamp
  }, children), showMoreButton && React.createElement(Box, {
    pt: 1
  }, React.createElement(ShowMoreButton, {
    onClick: onShowMoreClick,
    align: "left",
    showMoreText: showMoreText
  })));
};