import React from 'react';
import PropTypes from 'prop-types';
import { Button } from 'antd';
import * as types from './types';
import { downloadImage } from '../utils';
import { LS_SHOW_DOWNLOAD_BUTTON } from '../constants';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export function Fragment({
  children
}) {
  return children;
}
const isShow = () => localStorage.getItem(LS_SHOW_DOWNLOAD_BUTTON) === 'true' ? {} : {
  display: 'none'
};
export function Link({
  children,
  href,
  text
}) {
  if (children) {
    return /*#__PURE__*/_jsx("a", {
      className: "dbm-dd-link",
      href: children,
      target: "_blank",
      rel: "noreferrer",
      children: children
    });
  }
  return /*#__PURE__*/_jsx("a", {
    className: "dbm-dd-link",
    href: href,
    target: "_blank",
    rel: "noreferrer",
    children: text
  });
}
Link.propTypes = types.linkShape;
Link.defaultProps = {
  children: '',
  href: '',
  text: ''
};
export function Links({
  links
}) {
  return /*#__PURE__*/_jsx("div", {
    children: links.map(({
      href,
      text
    }, index) =>
    /*#__PURE__*/
    /* eslint-disable-next-line react/no-array-index-key */
    _jsx(Link, {
      href: href,
      text: text
    }, index))
  });
}
Links.propTypes = {
  links: PropTypes.arrayOf(types.link)
};
Links.defaultProps = {
  links: []
};

/**
 * @param {string|string[]|undefined} props.description
 * @returns
 */
export function ImageLink({
  children,
  url,
  imgSrc,
  description
}) {
  let url2 = url;
  let imgSrc2 = imgSrc;
  if (children) {
    url2 = children;
    imgSrc2 = children;
  }
  return /*#__PURE__*/_jsxs("div", {
    className: "dbm-dd-image-link",
    children: [/*#__PURE__*/_jsxs("a", {
      href: url2,
      rel: "noreferrer",
      target: "_blank",
      children: [/*#__PURE__*/_jsx("span", {
        children: url2
      }), /*#__PURE__*/_jsx("img", {
        alt: "ImageLink",
        src: imgSrc2
      })]
    }), /*#__PURE__*/_jsx("br", {}), description, /*#__PURE__*/_jsx("div", {
      style: isShow(),
      children: /*#__PURE__*/_jsx(Button, {
        className: "dbm-dd-image-link-download-btn",
        onClick: () => {
          downloadImage(url2);
        },
        children: "Download"
      })
    })]
  });
}
ImageLink.propTypes = {
  children: PropTypes.string,
  url: PropTypes.string,
  imgSrc: PropTypes.string,
  description: PropTypes.string
};
ImageLink.defaultProps = {
  children: '',
  url: '',
  imgSrc: '',
  description: ''
};

// eslint-disable-next-line react/prop-types
export function ImageLinks({
  imgs,
  limit = 3
}) {
  if (!imgs) return null;
  let results = imgs;
  if (limit !== null) {
    // eslint-disable-next-line react/prop-types
    results = imgs.slice(0, limit);
  }
  // eslint-disable-next-line react/no-array-index-key, react/jsx-props-no-spreading
  return results.map((img, index) => /*#__PURE__*/_jsx(ImageLink, {
    ...img
  }, index));
}
//# sourceMappingURL=Links.js.map