import './LightboxHeader.scss';
import * as React from 'react';
import { INewLightboxHeader } from "./utils";
import { NewLightboxView } from '../NewLightboxView';
import { StrCast } from '../../../../fields/Types';
import { EditableText } from '../components/EditableText';
import { getType } from '../utils';
import { Button, Size, Type } from 'browndash-components';
import { MdExplore, MdTravelExplore } from 'react-icons/md'
import { BsBookmark, BsBookmarkFill } from 'react-icons/bs'
import { Doc } from '../../../../fields/Doc';


export const NewLightboxHeader = (props: INewLightboxHeader) => {
    const {height = 100, width} = props;
    const [doc, setDoc] = React.useState<Doc | undefined>(NewLightboxView.LightboxDoc)
    const [editing, setEditing] = React.useState<boolean>(false)
    const [title, setTitle] = React.useState<JSX.Element | null>(
        (null)
    )
    React.useEffect(() => {
        let lbDoc = NewLightboxView.LightboxDoc
        setDoc(lbDoc)
        if (lbDoc) {
            setTitle(
                <EditableText 
                editing={editing}
                text={StrCast(lbDoc.title)} 
                onEdit={(newText: string) => {
                    if(lbDoc) lbDoc.title = newText;
                }} 
                setEditing={setEditing}            
            />)
        }
    }, [NewLightboxView.LightboxDoc])

    const [saved, setSaved] = React.useState<boolean>(false)

    if (!doc) return null
    else return <div className={`newLightboxHeader-container`} onPointerDown={(e) => e.stopPropagation()} style={{ minHeight: height, height: height, width: width }}>
        <div className={`title-container`}>
            <div className={`lb-label`}>Title</div>
            {title}
        </div>
        <div className={`type-container`}>
            <div className={`lb-label`}>Type</div>
            <div className={`type`}>{getType(StrCast(doc.type))}</div>
        </div>
        <div style={{gridColumn: 2, gridRow: 1, height: '100%', display: 'flex', justifyContent: 'flex-end', alignItems: 'center'}}>
            <div className={`lb-button2`} onClick={() => setSaved(!saved)}>
                {saved ? <BsBookmarkFill/> : <BsBookmark/>}
            </div>
            <div className={`lb-button2`} onClick={() => setSaved(!saved)}>
                {saved ? <BsBookmarkFill/> : <BsBookmark/>}
            </div>
        </div>
        <div  style={{gridColumn: 2, gridRow: 2, height: '100%', display: 'flex', justifyContent: 'flex-end', alignItems: 'center'}}>
            <div className={`lb-button ${NewLightboxView.ExploreMode}`} onClick={() => {
                console.log(NewLightboxView.ExploreMode)
                NewLightboxView.SetExploreMode(!NewLightboxView.ExploreMode)
            }}>
                <MdTravelExplore/>
                t-SNE 2D Embeddings
            </div>
        </div>
    </div>
}