// pages/camwebview/camwebview.js

import {
  get_camera_rule,
  get_phone_model,
} from '../../utils.js'

function make_query(zoom, ai_chat_mode) {
  var gd = getApp().globalData;
  var ret = "zoom=" + zoom;
  var ui = wx.getStorageSync('userinfo');
  ret += "&phonemodel=" + encodeURIComponent(get_phone_model());
  ret += "&realip=" + (gd.real_ip || "");
  ret += "&emblem_id=" + (ui.emblem_id || "");
  ret += "&nick_name=" + encodeURIComponent(ui.nickName || "");
  ret += "&tenant=" + (gd.tenant_id || "");
  ret += "&tk=" + Date.now();
  if (ai_chat_mode) {
    ret += "&ai_chat_mode=" + ai_chat_mode;
  }
  console.log(ret);
  return ret;
}

Page({

    /**
     * 页面的初始数据
     */
    data: {
      emblem_camera_url: null,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      var ai_chat_mode = options.ai_chat_mode;
      get_camera_rule(null, (rule) => {
        // we should have rules loaded, so this is effectively sync, before instantiating Page
        var zoom = rule.zoom;
        this.setData({
          emblem_camera_url: "https://themblem.com/camera-4.0/?" + make_query(zoom, ai_chat_mode),
        });
      })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },

    on_message(e) {
    }
})
