import Reveal from "reveal.js/dist/reveal.js";
import RevealZoom from 'reveal.js/plugin/zoom/zoom.js';
import RevealNotes from 'reveal.js/plugin/notes/notes.js';
import RevealSearch from 'reveal.js/plugin/search/search.js';
import RevealMarkdown from 'reveal.js/plugin/markdown/markdown.js';
import RevealHighlight from 'reveal.js/plugin/highlight/highlight.js';

import RevealMath from 'reveal.js/plugin/math/math.js';
import CodeEditorPlugin from "@/assets/js/codeEditorPlugin.js";


export default function initializeReveal(containerEl, codeEditorPluginYn) {

    // if (Reveal.isReady()) {
    //     Reveal.sync();           // 내부 상태 동기화
    //     Reveal.layout();         // 레이아웃 재계산
    //     return;
    // }

    const basePlugins = [ RevealZoom, RevealNotes, RevealSearch, RevealMarkdown, RevealHighlight, 
        // RevealMenu, 
        RevealChalkboard, RevealCustomControls ];
    if (codeEditorPluginYn) {
        // basePlugins.unshift(CodeEditorPlugin()); // CodeEditorPlugin을 첫 번째로 추가
    }
    
    var path = 'reveal.js-plugins/chalkboard/';
    // Reveal.initialize({	
    const deck = new Reveal(containerEl, {	
        width: 1280,
        height: 720,
        margin: 0.08,			
        minScale: 0.2,
        maxScale: 1.28503,			
        // Add the current slide number to the URL hash so that reloading the
        // page/copying the URL will return you to the same slide
        //	hash: false,			
        // Display presentation control arrows
        controls: true,			
        // Display a presentation progress bar
        progress: true,			
        // Push each slide change to the browser history.  Implies `hash: true`
        history: false,			
        // Enable keyboard shortcuts for navigation
        keyboard: true,			
        // Vertical centering of slides
        center: false,			
        // Enables touch navigation on devices with touch input
        //touch: true,			
        mouseWheel: false,			
        slideNumber: true,	
        
        overview: true,           // 개요 모드 활성화 (기본값 true)
        viewDistance: 10,         // 미리 로드할 슬라이드 수 (기본 3 -> 10으로 증가)
        mobileViewDistance: 5,    // 모바일에서 로드할 수
        hideInactiveCursor: true,
        
        // menu: { // Menu works best with font-awesome installed: sudo apt-get install fonts-font-awesome
        //     themes: false,
        //     transitions: false,
        //     markers: true,
        //     hideMissingTitles: true,				
        // },			
        chalkboard: {
            boardmarkerWidth: 3,
            chalkWidth: 7,
            chalkEffect: 1.0,
            storage: null,
            src: null,
            readOnly: undefined,
            transition: 800,
            theme: "chalkboard",
            // background: [ 'rgba(127,127,127,.1)' , path + 'img/blackboard.png' ],
            grid: { color: 'rgb(50,50,10,0.5)', distance: 80, width: 2},
        },
        customcontrols: {
            controls: [
                { icon: '<i class="fa fa-pen-square"></i>',
                    title: 'Toggle chalkboard (B)',
                    action: 'RevealChalkboard.toggleChalkboard();'
                },
                { icon: '<i class="fa fa-pen"></i>',
                    title: 'Toggle notes canvas (C)',
                    action: 'RevealChalkboard.toggleNotesCanvas();'
                }
            ]
        },
        //	완성
        plugins: basePlugins
    });
    
    // 설정한 인스턴스를 초기화 후 반환합니다.
    deck.initialize();
    return deck;
  }