import React, { useContext } from "react";
import { ContextWindowHeight } from "../../contextWindowHeight";
import { ButtonContainer } from "./buttonContainer";
import './toolbar.css';
import { ToolbarButton } from "./toolbarButton";
import { BorderLine } from "./toolbarButtonContainerBorderLine";
import { CaptionToolbarButtons } from "./typeCaptionButtons";

type TProps = {
    onClickOpenButton: () => void
    onClickMobileUsers?: () => void
    onClickMobileOther?: () => void
    isOpen: boolean
    isOpenUsersMobilePart?: boolean
    isOpenOtherMobilePart?: boolean
}

export const Toolbar:React.FC<TProps> = React.memo((props) => {
    const windowHeight = useContext(ContextWindowHeight);

    if(windowHeight < 700) {
        return <div className={`toolbar-container ${props.isOpen ? 'opened' : 'closed'}`}>
            <div className="toolbar-field">
                <div className="toolbar-field-part">
                    <ToolbarButton 
                        type="fullscreen"
                        onClick={() => {
                            if(!document.fullscreenElement) {
                                document.documentElement.requestFullscreen();
                            } else {
                                document.exitFullscreen();
                            }
                        }}
                        caption={CaptionToolbarButtons['fullscreen on']}
                        active={true}
                        isCaption={false}
                    />
                    <ButtonContainer 
                        buttons={[
                            {
                                type: "users",
                                onClick: props.onClickMobileUsers,
                                isCaption: false,
                                isSelected: props?.isOpenUsersMobilePart
                            }
                        ]}
                    />
                </div>
                <div className="toolbar-field-part">
                    <ButtonContainer 
                        buttons={[
                            {
                                type: "control",
                                onClick: () => console.log('click'),
                                active: true,
                                isCaption: false
                            },
                            {
                                type: "micro",
                                onClick: () => console.log('click'),
                                active: false,
                                isCaption: false
                            }                        
                        ]}
                    />                    
                    {/* <BorderLine /> */}
                    <ToolbarButton 
                        type="other"
                        onClick={props.onClickMobileOther}
                        caption={CaptionToolbarButtons["other"]}
                        isCaption={false}
                        isSelected={props.isOpenOtherMobilePart}
                    />
                </div>
            </div>
            <button className='toolbar-open-button' onClick={() => props.onClickOpenButton()}>
                <span className="toolbar-open-button-icon"></span>
            </button>
        </div>
    }
    return <div className={`toolbar-container ${props.isOpen ? 'opened' : 'closed'}`}>
        <div className="toolbar-field">
            <div className="toolbar-field-part">
                <ToolbarButton 
                    type="fullscreen"
                    onClick={() => {
                        if(!document.fullscreenElement) {
                            document.documentElement.requestFullscreen();
                        } else {
                            document.exitFullscreen();
                        }
                    }}
                    caption={CaptionToolbarButtons['fullscreen on']}
                    active={true}
                    isCaption={true}
                />
                <ButtonContainer 
                    buttons={[
                        {
                            type: "user admin",
                            onClick: () => console.log('click'),
                            isCaption: true
                        },
                        {
                            type: "user self",
                            onClick: () => console.log('click'),
                            isCaption: true
                        },
                        {
                            type: "user guest",
                            onClick: () => console.log('click'),
                            isCaption: true
                        },
                        {
                            type: "user guest",
                            onClick: () => console.log('click'),
                            isNotification: true,
                            isCaption: true
                        }
                    ]}
                />
            </div>
            <div className="toolbar-field-part">
                <ButtonContainer 
                    buttons={[
                        {
                            type: "control",
                            onClick: () => console.log('click'),
                            active: true,
                            isCaption: true
                        },
                        {
                            type: "micro",
                            onClick: () => console.log('click'),
                            active: false,
                            isCaption: true
                        }                        
                    ]}
                />
                <ToolbarButton 
                    type="share"
                    onClick={() => console.log('click')}
                    caption={CaptionToolbarButtons["share"]}
                    isCaption={true}
                />
                <BorderLine />                
                <ToolbarButton
                    type="exit"
                    onClick={() => null}
                    caption={CaptionToolbarButtons["exit"]}
                    isCaption={true}
                />
            </div>
        </div>
        <button className='toolbar-open-button' onClick={() => props.onClickOpenButton()}>
            <span className="toolbar-open-button-icon"></span>
        </button>
    </div>
})