import React from 'react';
import { Modal } from 'antd';

import { FileTypeEnum } from '@easytwin/core';

export interface PreviewAssetModalProp {
  type: FileTypeEnum;
  url?: string;
  onCancel?: () => void;
}

const PreviewAssetModal: React.FC<PreviewAssetModalProp> = function ({ type, url, onCancel }) {
  const renderPreviewWinndow = () => {
    if (!url) return null;
    switch (type) {
      case FileTypeEnum.IMAGE:
        return <img className="inline-block" src={url} alt="poi" />;
      default:
        return null;
    }
  };

  return (
    <Modal
      visible
      title="预览资产"
      footer={null}
      width={600}
      bodyStyle={{
        display: 'flex',
        justifyContent: 'center',
      }}
      onCancel={onCancel}>
      {renderPreviewWinndow()}
    </Modal>
  );
};

export default PreviewAssetModal;
