import ConfigProvider from '../config-provider';
import Highlight, { defaultProps } from 'prism-react-renderer';
import Icon from '../icon';
import Message from '../message';
import React, { Component } from 'react';
import copy from 'copy-to-clipboard';
import theme from './theme';
class CodeSnippet extends Component {
    render() {
        const { code, type, width } = this.props;
        return (React.createElement(Highlight, Object.assign({}, defaultProps, { code: code, language: "jsx", theme: theme }), type === 'number'
            ? ({ className, style, tokens, getLineProps, getTokenProps }) => (React.createElement("pre", { className: `${className} codesnippet-numberPre next-code-snippet`, style: Object.assign(Object.assign({}, style), { width }) }, tokens.map((line, i) => (React.createElement("div", Object.assign({ className: "codesnippet-line", key: i }, getLineProps({ line, key: i })),
                React.createElement("span", { className: "codesnippet-lineno" }, i + 1),
                React.createElement("span", { className: "codesnippet-linecontent" }, line.map((token, key) => (React.createElement("span", Object.assign({ key: key }, getTokenProps({ token, key })))))))))))
            : ({ className, style, tokens, getLineProps, getTokenProps }) => (React.createElement("pre", { className: className, style: style },
                tokens.map((line, i) => (React.createElement("div", Object.assign({}, getLineProps({ line, key: i })), line.map((token, key) => (React.createElement("span", Object.assign({}, getTokenProps({ token, key })))))))),
                React.createElement(Icon, { type: "Copy2-outlined", onClick: () => {
                        copy(code);
                        Message.success('代码已复制成功');
                    } })))));
    }
}
export default ConfigProvider.config(CodeSnippet);
