/**
 * 游戏预约按钮相关接口、类
 */
import { callNativeSync } from './util';

class AdjustWebview {
    constructor(id) {
        this._id = id;
    }
    scrollTo(scrollTop, duration){
        const res = callNativeSync('appAdjustableWebView.scrollTo', { id: this._id, scrollTop, duration});
        if(res.code != 0) {
            throw new Error(res)
        }
    }
    startPullDownRefresh() {
        const res = callNativeSync('appAdjustableWebView.startPullDownRefresh', { id: this._id});
        if(res.code != 0) {
            throw new Error(res)
        }
    }
    stopPullDownRefresh() {
        const res = callNativeSync('appAdjustableWebView.stopPullDownRefresh', { id: this._id});
        if(res.code != 0) {
            throw new Error(res)
        }
    }
    postMessageToWebView(data) {
        const res = callNativeSync('appAdjustableWebView.postMessageToWebView', { id: this._id, data});
        if(res.code != 0) {
            throw new Error(res)
        }
    }
    isEnablePullDownRefresh() {
        const res = callNativeSync('appAdjustableWebView.isEnablePullDownRefresh', { id: this._id});
        if(res.code != 0) {
            throw new Error(res)
        } else if(res.data){
            return res.data.value
        }
    }
    isEnableBounce() {
        const res = callNativeSync('appAdjustableWebView.isEnableBounce', { id: this._id});
        if(res.code != 0) {
            throw new Error(res)
        } else if(res.data){
            return res.data.value
        }
    }
    isEnableScroll() {
        const res = callNativeSync('appAdjustableWebView.isEnableScroll', { id: this._id});
        if(res.code != 0) {
            throw new Error(res)
        } else if(res.data){
            return res.data.value
        }
    }
    updateSrc(src) {
        const res = callNativeSync('appAdjustableWebView.updateSrc', { id: this._id, src});
        if(res.code != 0) {
            throw new Error(res)
        }
    }
}

export default function createAdjustWebview(id){
    return new AdjustWebview(id);
}
