import React, { useRef } from 'react';
import './BottomSheet.css';

export default function BottomSheet({ visible = false, title = '', onClose, children, footer }) {
  const startY = useRef(0);
  return (
    <>
      <div className={'kole-sheet-mask' + (visible ? ' is-open' : '')} onClick={onClose} />
      <div
        className={'kole-sheet' + (visible ? ' is-open' : '')}
        onPointerDown={e => { startY.current = e.clientY; }}
        onPointerUp={e => { if (startY.current - e.clientY < -80) onClose && onClose(); }}
      >
        <div className="kole-sheet-handle" />
        {title ? <div className="kole-sheet-header">{title}</div> : null}
        <div className="kole-sheet-body">{children}</div>
        {footer ? <div className="kole-sheet-footer">{footer}</div> : null}
      </div>
    </>
  );
}
