import React from 'react';

import StudioInsertionPopup from './StudioInsertionPopup';

import './StudioContextBlockPopup.css';

function StudioContextBlockPopup({ open, block, onClose }) {
  if (!block) return null;

  return (
    <StudioInsertionPopup
      open={open}
      title={block.label}
      defaultExpanded
      onClose={onClose}
    >
      {({ expanded }) =>
        expanded ? (
          <pre className="studio-context-block-popup__content">
            {block.content}
          </pre>
        ) : (
          <div className="studio-context-block-popup__preview">
            <span className="studio-insertion-popup__field-label">来源</span>
            <span className="studio-insertion-popup__field-value">{block.source}</span>
          </div>
        )
      }
    </StudioInsertionPopup>
  );
}

export default StudioContextBlockPopup;
