<?php 
// 片刻发布模块
$user_id = get_current_user_id();
$term_id = get_queried_object()->term_id ?? false;
$power = get_user_power($user_id);
$func = get_mj_func($term_id);
$allow_card = is_allow_card($user_id,$term_id);
$max_word = mo_word_max($term_id);
$max = $max_word['max'];
$min = $max_word['min'];

$disable = $term_id ? '' : 'disabled';

$ga_num = mo_gallery_num($term_id);
$file_num = mo_file_num($term_id);
$moment_label = ppo_moment_label('moment');
$moments_label = ppo_moment_label('moments');
?>

<div class="mo-push-wrap">

    <div class="mo-form-main">

        <?php 
            if(!is_user_logged_in()){ ?>

        <div class="mo-login-required">
            <div class="mo-login-required-icon"><i class="ri-lock-unlock-line"></i></div>
            <div class="mo-login-required-main">
                <div class="mo-login-required-title">登录后解锁<?php echo esc_html($moment_label); ?>互动</div>
                <div class="mo-login-required-desc">需要登录后才可发布<?php echo esc_html($moment_label); ?>，并查看你加入或创建的<?php echo esc_html($moments_label); ?>。</div>
            </div>
            <a href="#modal-login" uk-toggle class="mo-login-required-btn">立即登录</a>
        </div>

        <?php } elseif(!check_mo_joined() && $term_id){
                echo join_mo_box($term_id);
            } else { ?>
        

        <?php echo mo_user_box($term_id); ?>
        <div class="mo-form-within">
            <div class="mo-title-form">
                <input type="text" placeholder="标题（选填）" name="moment-title" id="moment-title">
            </div>
            <div class="mo-content-form">
                <textarea id="moment_content" class="pix-editor-source" name="moemnt_content" placeholder="今日份分享 ! " maxlength="<?php echo $max ?>" style="overscroll-behavior: contain;"></textarea>
                <div id="pix-moment-editor" data-pix-editor data-input="#moment_content" data-placeholder="今日份分享 ! "></div>
            </div>

            <div class="mo-tool-nav">
            <div class="left-tool">
                <?php if(user_moments_power($user_id , $term_id,'audio')) { ?>
                    <a class="mo-music-btn mo-audio-btn mo-btn hint--top hint--rounded <?php echo $disable ?>" data="audio" data-hint="音乐"><i class="ri-disc-line"></i></a>
                <?php } ?>
                <?php if(user_moments_power($user_id , $term_id,'card')) { ?>
                    <a class="mo-card-btn mo-btn hint--top hint--rounded <?php echo $disable ?>" data="card" data-hint="卡片"><i class="ri-article-line"></i></a>
                <?php } ?>  
                <?php if(user_moments_power($user_id , $term_id,'gallery')) { ?>
                    <button type="button" class="pix-moment-attach-trigger mo-gallery-btn hint--top hint--rounded <?php echo $disable ?>" data-kind="image" data-hint="图片"><i class="ri-image-add-line"></i></button>
                <?php } ?>
                <?php if(user_moments_power($user_id , $term_id,'video')) { ?>
                    <button type="button" class="pix-moment-attach-trigger mo-video-btn hint--top hint--rounded <?php echo $disable ?>" data-kind="video" data-hint="视频"><i class="ri-video-add-line"></i></button>
                <?php } ?>
                <?php if(user_moments_power($user_id , $term_id,'file')) { ?>
                    <button type="button" class="pix-moment-attach-trigger mo-file-btn hint--top hint--rounded <?php echo $disable ?>" data-kind="file" data-hint="文件"><i class="ri-file-add-line"></i></button>
                <?php } ?>
                <span class="fenge">|</span>
                <a class="mo-smile-btn mo-btn"><i class="ri-emotion-line"></i></a>

                <div class="mo-smile-drop" uk-dropdown="mode: click;toggle:.mo-smile-btn;pos:bottom-center;animation:uk-animation-slide-bottom-small;animate-out:true">
                    <div class="mo-smile-inner"></div>
                </div>
            </div>

            <div class="right-tool">
                <div class="mo-num">0</div>
            </div>
        </div>
        
        </div>

        <div class="pix-moment2-panel is-collapsed">
            <div class="pix-moment2-head">
                <div class="pix-moment2-icon"><i class="ri-add-circle-line"></i></div>
                <div class="pix-moment2-copy">
                    <span>添加附件</span>
                    <small>图片可多选和排序，视频 / 文件每次添加一个，也支持外链图片和我的媒体库</small>
                </div>
                <button type="button" class="pix-moment2-close" aria-label="收起附件面板"><i class="ri-close-line"></i></button>
            </div>
            <div id="pix-moment-uploader"
                data-pix-uploader
                data-context="moment_asset"
                data-limit="<?php echo esc_attr(max((int)$ga_num, (int)$file_num, 1)); ?>"></div>
        </div>

        <div class="mo-tool-box">
            <div class="mo-music-box mo-audio-box mo-toggle-box">
                <div class="cancel-toggle-box"><i class="ri-close-line"></i></div>
                <div class="mo-netease">
                    <input type="text" name="netease_mo" class="netease_mo" placeholder="输入网易云单曲ID">
                    <a class="preview-music">生成音乐</a>
                </div>
                <div class="audio-preview-box"></div>
                <!-- <span class="mo-tips"><i class="ri-error-warning-line"></i>必须安装pixmusic插件后才可使用</span> -->
            </div>

            <div class="mo-card-box mo-toggle-box">
                <div class="cancel-toggle-box"><i class="ri-close-line"></i></div>
                <span class="mo-tips"><i class="ri-error-warning-line"></i>输入本站网址,自动生成链接卡片<small>支持文章, <?php echo esc_html($moment_label); ?>, 页面等网址</small></span>
                <div class="mo-card-content">
                    <input type="text" placeholder="本站网址" name="mo_card_link" id="mo_card_link" required="required">
                    <a class="push_card">生成</a>
                </div>
                <div class="card-wrap" uk-sortable="handle: .card-box"></div>
            </div>
        </div>

        <div class="bottom-tools">
            <div class="mo-cat">
                <?php echo get_moment_cat_btn(); ?>
                <!-- <a class="mo-cir-btn"><div class="cat-thum"><i class="ri-outlet-line"></i></div> <span>圈子</span></a> -->
                <a class="mo-tag-btn"><i class="ri-hashtag"></i> <span>话题</span></a>

                <!-- <div class="circle-drop mo-cat-drop" uk-dropdown="mode: click;toggle:.mo-cir-btn;pos:bottom-left;animation:uk-animation-slide-bottom-small;animate-out:true">
                    <?php //echo get_moment_cat(); ?>
                </div> -->
                <div class="motag-drop mo-cat-drop" uk-dropdown="mode: click;toggle:.mo-tag-btn;pos:bottom-left;animation:uk-animation-slide-bottom-small;animate-out:true">
                <?php echo get_moment_tag(); ?>
                </div>
            </div>
            <div class="push-box">
                <a class="mo-setting"><i class="ri-settings-line"></i></a>
                <a class="push-mo-btn" type="text" action="publish">发布</a>
            </div>
        </div>

        <?php } ?>

    </div>
</div>
