avshow.ShareDialogObject = {
    data()
    {
        return { show_share_dialog: false }
    },
    computed: { share_url: function()
        {
            var u = document.URL;
            return u
        } },
    methods: { on_share: function()
        {
            this.show_share_dialog = true
        } },
    created: function(){}
};
$g.ReportDialogObject = {
    data()
    {
        return {
                show_report_dialog: false,
                report_data: {
                    reason: "",
                    email: "",
                    message: ""
                },
                report_button_loading: false,
                show_explain_report_dialog: false
            }
    },
    methods: {
        on_report: function()
        {
            this.show_report_dialog = true
        },
        on_submit_report: function()
        {
            if (!this.report_data.reason || this.report_data.reason.length < 1)
            {
                return this.$message("请选择反馈的原因。")
            }
            var post_data = this.report_data;
            if (avshow.av_data)
            {
                post_data.tid = avshow.av_data.tid
            }
            if (avshow.avdata)
            {
                post_data.tid = avshow.avdata.tid
            }
            if (avshow.switch_server)
            {
                post_data.video_server = avshow.switch_server.get()
            }
            this.$axios.post("/app/video/report", post_data).then(response => 
                {
                    this.$message("感谢你的反馈，我们会尽快处理。");
                    this.show_report_dialog = false
                }).catch(error => 
                {
                    console.log("error:", error);
                    this.show_report_dialog = false
                })
        }
    },
    created: function()
    {
        if ($g.config.color_theme == "dark")
        {
            this.$q.dark.set(true)
        }
        if (this.userdata)
        {
            this.report_data.email = this.userdata.email
        }
    }
};
$g.PLAYLISTOBJEVT = CreatePlayListObject = {
    data()
    {
        return {
                playlistdatas: undefined,
                show_playlist_dialog: false,
                show_create_playlist_dialog: false,
                request_playlistdata_error: false,
                playlistdata: {},
                    create_playlistdata: {
                        tag: "",
                        tags: [],
                        public: true
                    },
                    playlistselects: {},
                        create_button_loading: false
                    }
            },
            computed: { tid: function()
                {
                    if ($g.av_data)
                    {
                        return $g.av_data.tid
                    }
                    return $g.avdata.tid
                } },
            methods: {
                show: function()
                {
                    this.show_playlist_dialog = true;
                    this.update_playlistdata()
                },
                get_playlistdata: function(playlistid)
                {
                    if (this.playlistdatas)
                    {
                        for (var i = 0; i < this.playlistdatas.length; ++i)
                        {
                            if (this.playlistdatas[i]["_id"] == playlistid)
                            {
                                return this.playlistdatas[i]
                            }
                        }
                    }
                },
                on_select_playlist: function(playlistid)
                {
                    var action = !this.playlistselects[playlistid] ? "add" : "remove";
                    this.$axios.get("/app/playlist/action", { params: {
                            action: action,
                            playlistid: playlistid,
                            tid: this.tid
                        } }).then(respone => 
                        {
                            this.playlistselects[playlistid] = !this.playlistselects[playlistid];
                            var playlistdata = this.get_playlistdata(playlistid);
                            if (action === "add")
                            {
                                this.$message("已添加到片单!");
                                console.log("list:", playlistdata["list"]);
                                if (!playlistdata["list"].includes(this.tid))
                                {
                                    playlistdata["list"].push(this.tid)
                                }
                            }
                            else
                            {
                                this.$message("已从片单移除!");
                                playlistdata["list"] = playlistdata["list"].filter(function(val)
                                {
                                    return val === this.tid
                                });
                                this.update_playlistdata(playlistid, playlistdata);
                                console.log("移除:", playlistdata["list"])
                            }
                            this.$nextTick(() => 
                                {
                                    this.$forceUpdate()
                                })
                        }).catch(error => {})
                },
                on_create_playlist: function()
                {
                    if (!$g.user.is_login())
                    {
                        $g.user.show_login_dialog("member.login_guestmessage");
                        return false
                    }
                    if (this.create_playlistdata.name.length < 2)
                    {
                        return this.$message("名字过短，不能少于2个字!")
                    }
                    if (!this.create_playlistdata.description || this.create_playlistdata.description.length < 5)
                    {
                        return this.$message("描述过短，不能少于5个字!")
                    }
                    this.create_button_loading = true;
                    var post_data = { playlistdata: this.create_playlistdata };
                this.$axios.post("/app/playlist/create", post_data).then(response => 
                    {
                        this.is_star_loading = false;
                        console.log("playlist create response:", response);
                        this.create_button_loading = false;
                        var response_data = response.data.data;
                        this.show_create_playlist_dialog = false;
                        if (response_data)
                        {
                            this.create_playlistdata["_id"] = response_data["playlistid"];
                            this.$message("创建片单成功。");
                            if (window.EventBus)
                            {
                                window.EventBus.dispatch("create_playlist", this.create_playlistdata)
                            }
                        }
                    }).catch(error => 
                    {
                        console.log("error:", error);
                        this.create_button_loading = false
                    })
            },
            on_addto_playlist: function(e)
            {
                console.log("on_add_playlist:", e);
                if (!$g.user.is_login())
                {
                    $g.user.show_login_dialog("member.login_guestmessage");
                    return
                }
                this.show_playlist_dialog = true;
                if (!this.playlistdatas)
                {
                    this.$axios.get("/app/playlist/list", { params: {} }).then(respone => 
                            {
                                console.log("playlist respone:", respone);
                                this.playlistdatas = respone.data.data.playlists;
                                this.update_playlistselects()
                            }).catch(error => {})
                    }
                },
                on_add_playlist: function()
                {
                    this.show_create_playlist_dialog = true
                },
                create_playlist_event: function(e)
                {
                    console.log("create_playlist_event:", e);
                    var playlistdata = e.target;
                    if (this.playlistdatas)
                    {
                        this.playlistdatas.unshift(playlistdata);
                        this.update_playlistselects()
                    }
                },
                update_playlistdata: function()
                {
                    this.$axios.get("/app/playlist/list", { params: {} }).then(respone => 
                            {
                                console.log("playlist respone:", respone);
                                this.playlistdatas = respone.data.data.playlists;
                                this.update_playlistselects()
                            }).catch(error => {})
                    },
                    update_playlistselects: function()
                    {
                        if (this.playlistdatas)
                        {
                            for (var i = 0; i < this.playlistdatas.length; ++i)
                            {
                                var playlistdata = this.playlistdatas[i];
                                this.playlistselects[playlistdata["_id"]] = false;
                                if (Array.isArray(playlistdata["list"]) && playlistdata["list"].includes(this.tid))
                                {
                                    this.playlistselects[playlistdata["_id"]] = true
                                }
                            }
                            console.log("[update_playlistselects] playlistselects:", this.playlistselects)
                        }
                    },
                    on_add_tag: function()
                    {
                        if (!this.create_playlistdata.tag.trim())
                            return;
                        if (!this.create_playlistdata.tags.includes(this.create_playlistdata.tag))
                        {
                            this.create_playlistdata.tags.push(this.create_playlistdata.tag);
                            this.create_playlistdata.tag = ""
                        }
                        else
                        {
                            this.$message("标签已存在")
                        }
                    },
                    delete_tag(index)
                    {
                        this.create_playlistdata.tags.splice(index, 1)
                    }
                },
                created: function()
                {
                    if (window.EventBus)
                    {
                        window.EventBus.addEventListener("create_playlist", this.create_playlist_event)
                    }
                }
            };
            var Main = {
                delimiters: ["{[", "]}"],
                data()
                {
                    return {
                            avdata: $g.avdata,
                            more_is_loading: false,
                            dislike_active: false,
                            view_count: 0,
                            unlike_count: 0,
                            like_count: 0,
                            collect_active: false,
                            showModal: false,
                            class_btn_primary: "bbt-btn--primary",
                            class_btn_defalut: "test",
                            dialogVisible: false,
                            handleClose: false,
                            like_button_text: "点赞",
                            class_icon_star: "bbt-icon-star-o",
                            tabinfo: {}
                            }
                    },
                    computed: {
                        like_text: function()
                        {
                            if (this.tabinfo.video_like_action == "like")
                            {
                                return "已赞" + this.tabinfo.like_count
                            }
                            return "点赞" + this.tabinfo.like_count
                        },
                        like_active: function()
                        {
                            return this.tabinfo.video_like_action == "like"
                        }
                    },
                    methods: {
                        update_tabinfo: function()
                        {
                            if (isNaN(this.tabinfo.like_count))
                            {
                                this.tabinfo.like_count = 0
                            }
                            if (isNaN(this.tabinfo.unlike_count))
                            {
                                this.tabinfo.unlike_count = 0
                            }
                        },
                        ad_url: function()
                        {
                            return "/ad?f=video:" + this.avdata.tid
                        },
                        collect_click: function()
                        {
                            if (!$g.user.is_login())
                            {
                                $g.user.show_login_dialog("member.login_guestmessage");
                                return
                            }
                            var action = !this.collect_active;
                            console.log("collect_click:", action);
                            var _t = this;
                            this.$axios.post("/app/video/collect/" + avshow.avdata.tid, {
                                tid: avshow.avdata.tid,
                                action: action
                            }).then(function(response)
                            {
                                var response_data = response.data;
                                console.log("collect response_data:", response_data);
                                if (response_data.code == 200)
                                {}
                            }).catch(function(error){});
                            _t.collect_active = action;
                            this.update_video_collect()
                        },
                        update_video_collect: function()
                        {
                            console.log("collect_active:", this.collect_active);
                            if (this.collect_active)
                            {
                                this.class_icon_star = "bbt-icon-star1"
                            }
                            else
                            {
                                this.class_icon_star = "bbt-icon-star-o"
                            }
                        },
                        update_video_like: function()
                        {
                            if (this.like_active)
                            {
                                this.class_btn_primary = "";
                                this.class_btn_defalut = "active";
                                this.like_button_text = "已赞"
                            }
                            else
                            {
                                this.class_btn_primary = "";
                                this.class_btn_defalut = "";
                                this.like_button_text = "点赞"
                            }
                        },
                        video_like_event: function(action)
                        {
                            if (this.tabinfo.video_like_action == action)
                            {
                                return
                            }
                            this.$axios.post("/app/video/like", {
                                tid: $g.avdata.tid,
                                action: action
                            }).then(response => 
                                {
                                    this.$forceUpdate()
                                }).catch(function(error){});
                            if (isNaN(this.tabinfo.like_count))
                            {
                                this.tabinfo.like_count = 0
                            }
                            if (action == "like")
                            {
                                if (isNaN(this.tabinfo.like_count))
                                {
                                    this.like_count = 0
                                }
                                this.tabinfo.like_count = this.tabinfo.like_count + 1;
                                console.log("this.like_count:", this.like_count);
                                if (this.tabinfo.unlike_count >= 1 && this.tabinfo.video_like_action == "dislike")
                                {
                                    this.tabinfo.unlike_count = this.tabinfo.unlike_count - 1
                                }
                            }
                            else if (action == "dislike")
                            {
                                if (isNaN(this.tabinfo.unlike_count))
                                {
                                    this.tabinfo.unlike_count = 0
                                }
                                this.tabinfo.unlike_count = this.tabinfo.unlike_count + 1;
                                if (this.tabinfo.like_count >= 1 && this.tabinfo.video_like_action == "like")
                                {
                                    this.tabinfo.like_count = this.tabinfo.like_count - 1
                                }
                            }
                            this.tabinfo.video_like_action = action;
                            var key = "like:action:" + $g.avdata.tid;
                            localStorage.setItem(key, action);
                            this.update_tabinfo();
                            this.$forceUpdate()
                        },
                        request_tabinfo: function()
                        {
                            var _t = this;
                            var tabinfo_url = "/app/video/tabinfo/" + this.avdata.tid;
                            console.log("request_tabinfo:", tabinfo_url);
                            this.$axios.get(tabinfo_url, {}).then(response => 
                                    {
                                        var avdata_tabinfo = response.data.data;
                                        _t.view_count = avdata_tabinfo.view_count;
                                        if (!avdata_tabinfo.unlike_count)
                                        {
                                            avdata_tabinfo.unlike_count = 0
                                        }
                                        _t.unlike_count = avdata_tabinfo.unlike_count;
                                        _t.like_count = avdata_tabinfo.like_count;
                                        var video_like_action = avdata_tabinfo.video_like_action;
                                        if (video_like_action == 1 || video_like_action == "like")
                                        {
                                            _t.like_active = true;
                                            _t.dislike_active = false
                                        }
                                        else if (video_like_action == 0 || video_like_action == "dislike")
                                        {
                                            _t.like_active = false;
                                            _t.dislike_active = true
                                        }
                                        _t.update_video_like();
                                        var data_is_collect = avdata_tabinfo.is_collect;
                                        if (data_is_collect == "1" || data_is_collect == "true")
                                        {
                                            _t.collect_active = true
                                        }
                                        else
                                        {
                                            _t.collect_active = false
                                        }
                                        _t.update_video_collect();
                                        console.log("avdata_tabinfo:", avdata_tabinfo);
                                        this.tabinfo = avdata_tabinfo;
                                        if (!$g.user.is_login())
                                        {
                                            var key = "like:action:" + avshow.avdata.tid;
                                            this.tabinfo.video_like_action = video_like_action = localStorage.getItem(key);
                                            console.log("[local]like_action:", video_like_action)
                                        }
                                        this.update_tabinfo();
                                        this.$forceUpdate()
                                    }).catch(function(error)
                                {
                                    console.error("request_tabinfo:", error)
                                })
                            }
                        },
                        created: function()
                        {
                            this.$nextTick(this.request_tabinfo)
                        }
                    };
                var Ctor = Vue.extend({ mixins: [
                            Main,
                            $g.PLAYLISTOBJEVT,
                            $g.ReportDialogObject,
                            $g.ShareDialogObject
                        ] });
                $g.toolbar = $m("video-actions-module", Ctor);