<div style="box-sizing: border-box;padding: 10px" id="core-next-editor-power">
    <div>
        <el-tabs v-model="active_name" @tab-click="changeTab">
            <el-tab-pane label="短代码" name="short_code">
                <div class="short-btns-warp">
                    <el-button size="small" @click="addShortCode('title-plane')">标题面板</el-button>
                    <el-button size="small" @click="addShortCode('icon-url')">图标超链接</el-button>
                    <el-button size="small" @click="addShortCode('zd-plane')">折叠面板</el-button>
                    <el-button size="small" @click="addShortCode('loginshow')">登录可见</el-button>
                    <el-button size="small" @click="addShortCode('pwdshow')">密码可见</el-button>
                    <el-button size="small" @click="addShortCode('reply')">回复可见</el-button>
                    <el-button size="small" @click="addShortCode('wxshow')">关注微信可见</el-button>
                    <el-button size="small" @click="addShortCode('clickshow')">点击可见</el-button>
                    <el-button size="small" @click="addShortCode('selectbox')">勾选框</el-button>
                    <el-button size="small" @click="addShortCode('postcard')">文章卡片</el-button>
                    <el-button size="small" @click="addShortCode('dh')">导航卡片</el-button>
                </div>
                <el-divider></el-divider>
                <div class="plane">
                    <div class="set-item">
                        <div>标星面板</div>
                        <div>
                            <el-select v-model="star_plane" size="mini" placeholder="请选择">
                                <el-option label="黄色" value="1"></el-option>
                                <el-option label="蓝色" value="2"></el-option>
                                <el-option label="红色" value="3"></el-option>
                                <el-option label="灰色" value="4"></el-option>
                            </el-select>
                        </div>
                        <div>
                            <el-button size="small" @click="addShortCode('star_plane')">插入</el-button>
                        </div>
                    </div>
                    <div class="set-item">
                        <div>提示面板</div>
                        <div>
                            <el-select v-model="alert_plane" size="mini" placeholder="请选择">
                                <el-option label="默认" value="info"></el-option>
                                <el-option label="成功" value="success"></el-option>
                                <el-option label="警告" value="warning"></el-option>
                                <el-option label="错误" value="error"></el-option>
                            </el-select>
                        </div>
                        <div>
                            <el-button size="small" @click="addShortCode('alert_plane')">插入</el-button>
                        </div>
                    </div>
                    <div class="set-item">
                        <div>下载面板</div>
                        <div>
                            <el-select v-model="download_plane" size="mini" placeholder="请选择">
                                <el-option :label="item.name" :value="item.value"
                                           v-for="item in download_list"></el-option>
                            </el-select>
                        </div>
                        <div>
                            <el-button size="small" @click="addShortCode('download_plane')">插入</el-button>
                        </div>
                    </div>
                </div>
            </el-tab-pane>
            <el-tab-pane label="代码高亮" name="code">
                <el-input
                        ref="code_input"
                        type="textarea"
                        :rows="15"
                        placeholder="输入代码"
                        v-model="code_input">
                </el-input>
                <div style="margin-top: 10px;text-align: right">
                    <!--<el-button size="small" @click="pasteCode">粘贴</el-button>-->
                    <el-button size="small" @click="clearCode">清空</el-button>
                    <el-button size="small" type="primary" @click="insertCode('inline')">插入代码(行内代码)</el-button>
                    <el-button size="small" type="primary" @click="insertCode">插入代码</el-button>
                    <p>行内代码，<b>只能一行</b>，多行请勿使用</p>
                </div>
            </el-tab-pane>
        </el-tabs>
    </div>
</div>
<style>

    #core-next-editor-power .short-btns-warp .el-button {
        margin-bottom: 10px;
        margin-left: 0;
        margin-right: 10px;
    }

    #core-next-editor-power input[type=checkbox]:focus, input[type=color]:focus, input[type=date]:focus, input[type=datetime-local]:focus, input[type=datetime]:focus, input[type=email]:focus, input[type=month]:focus, input[type=number]:focus, input[type=password]:focus, input[type=radio]:focus, input[type=search]:focus, input[type=tel]:focus, input[type=text]:focus, input[type=time]:focus, input[type=url]:focus, input[type=week]:focus, select:focus, textarea:focus {
        border-color: unset;
        box-shadow: unset;
        outline: unset;
    }

    #core-next-editor-power .set-item {
        display: flex;
        gap: 10px;
        align-items: center;
        margin-bottom: 10px;
    }

    #core-next-editor-power input.readonly, input[readonly], textarea.readonly, textarea[readonly] {
        background-color: unset;
    }

</style>
<script>
    new Vue({
        el: '#core-next-editor-power',
        data: {
            active_name: 'short_code',
            code_input: '',
            star_plane: '1',
            alert_plane: 'info',
            download_plane: 'default',
            download_list: [
                {name: '默认', value: 'default'},
                {name: '百度云盘', value: 'bd'},
                {name: '阿里云盘', value: 'al'},
                {name: '天翼云盘', value: 'ty'},
                {name: '诚通', value: 'ct'},
                {name: '蓝奏', value: 'lz'},
                {name: '123盘', value: '123'},
                {name: '迅雷', value: 'xl'},
                {name: '微云', value: 'wy'},
                {name: '360', value: '360'},
                {name: '夸克', value: 'quark'},
                {name: 'UC', value: 'uc'},
                {name: 'GitHub', value: 'github'},
                {name: 'OneDrive', value: 'OneDrive'},
                {name: '文叔叔', value: 'wss'},
                {name: '微云', value: 'wy'}
            ]
        },
        created() {
            let name = localStorage.getItem('core_next_editor_power_select_tab');
            if (name !== null) {
                this.active_name = name;
            }
        },
        methods: {
            addShortCode(content) {
                switch (content) {
                    case 'title-plane':
                        window.insertShortCode('[title-plane title="标题"]内容[/title-plane]');
                        break;
                    case 'icon-url':
                        window.insertShortCode('[icon-url href="网址" target="_blank"]网址[/icon-url]');
                        break;
                    case 'zd-plane':
                        window.insertShortCode('[zd-plane title="折叠标题"]折叠内容[/zd-plane]');
                        break;
                    case 'loginshow':
                        window.insertShortCode('[loginshow]登录可见的内容[/loginshow]');
                        break;
                    case 'wxshow':
                        window.insertShortCode('[wxshow]可见内容[/wxshow]');
                        break;
                    case 'clickshow':
                        window.insertShortCode('[clickshow]点击可见内容[/clickshow]');
                        break;
                    case 'pwdshow':
                        window.insertShortCode('[pwdshow pwd="密码"]密码可见内容[/pwdshow]');
                        break;
                    case 'reply':
                        window.insertShortCode('[reply]回复可见内容[/reply]');
                        break;
                    case 'selectbox':
                        window.insertShortCode('[selectbox type="1"]');
                        break;
                    case 'star_plane':
                        window.insertShortCode('[start-plane type="' + this.star_plane + '"]内容[/start-plane]');
                        break;
                    case 'alert_plane':
                        window.insertShortCode('[c-alert type="' + this.alert_plane + '"]提示面板内容[/c-alert]');
                        break;
                    case 'postcard':
                        window.insertShortCode('[postcard type="list"]文章id，多个ID使用,隔开[/postcard]');
                        break;
                    case 'dh':
                        window.insertShortCode('[dh url="地址" icon="网站图标" des="描述"]导航名称[/dh]');
                        break;
                    case 'download_plane':
                        window.insertShortCode('[c-downbtn type="' + this.download_plane + '" url="链接地址" pwd=""]提示面板内容[/c-downbtn]');
                        break;
                }

            },
            changeTab(tab) {
                window.localStorage.setItem('core_next_editor_power_select_tab', tab.name);
            },
            pasteCode() {
                //const clipboardObj = navigator.clipboard;
                /* navigator.clipboard.readText()
                     .then(text => {
                         console.log('剪贴板内容：', text);
                     })
                     .catch(err => {
                         console.error('获取剪贴板内容失败：', err);
                     });*/

                this.$refs.code_input.focus();
                document.execCommand('paste');
            },
            clearCode() {
                this.code_input = '';
            },
            encodeCode(code) {
                return code.replace(/</g, '&lt;')
                    .replace(/>/g, '&gt;')
            },
            insertCode(type) {
                if (this.code_input == '') {
                    return;
                }
                if (type == 'inline') {
                    window.insertShortCode('<code>' + this.encodeCode(this.code_input) + '</code>&nbsp;');
                } else {
                    window.insertShortCode('<pre class="corepress-code-pre"><code>' + this.encodeCode(this.code_input) + '</code></pre>&nbsp;');
                }
            }
        }
    });
</script>