import common from '../../utils/util';
import main from '../../utils/main';
import constant1 from '../../utils/constant';

const app = getApp();

Page({
  data: {
    ImagePath: app.globalData.uploadImageUrl,
  },
  onLoad: function (options) {
    var that = this;

    var icon="cardlist_folder_white_66x60";
    if (options.FolderIcon)
      icon=options.FolderIcon;

    var arr=constant1.arrFolderIcon;
    var arrIcon=[];
    for(var i=0;i<arr.length;i++){
      var obj={};
      obj.ImageUrl=arr[i];
      obj.Width=arr[i].substring(arr[i].lastIndexOf("_")+1,arr[i].lastIndexOf("x"));
      obj.Height=arr[i].substring(arr[i].lastIndexOf("x")+1);
      if (icon==obj.ImageUrl)
        obj.SelectIcon="panelIconSelect";
      else
        obj.SelectIcon="";
      
      arrIcon.push(obj);
    }

    var color="#6B727C";
    if (options.FolderColor)
      color=options.FolderColor;

    var arr2=constant1.arrFolderColor;
    var arrColor=[];
    for(var i=0;i<arr2.length;i++){
      var obj={};
      obj=arr2[i];
      if (obj.Color==color)
        obj.SelectColor=true;
      else
        obj.SelectColor=false;
      arrColor.push(obj);
    }

    that.setData({
      IconArr:arrIcon,
      ColorArr:arrColor,
    });

    setTimeout(function(){
      that.setData({
        Containnerheight: main.getWindowHeight(),
      });
    },2000);
  },
  selectColor:function(e){
    var that=this;
    var index=e.currentTarget.dataset.index;
    var arr=that.data.ColorArr;
    var color="";
    for(var i=0;i<arr.length;i++){
      arr[i].SelectColor=false;
      if (index==i){
        arr[i].SelectColor=true;
        color=arr[i].Color;
      }
    }
    that.setData({
      ColorArr:arr,
      BackColor:color,
    });
    wx.setBackgroundColor({
      backgroundColorBottom: color,
    });
  },
  selectIcon:function(e){
    var that=this;
    var index=e.currentTarget.dataset.index;
    var arr=that.data.IconArr;
    for(var i=0;i<arr.length;i++){
      arr[i].SelectIcon="";
      if (index==i)
        arr[i].SelectIcon="panelIconSelect";
    }
    that.setData({
      IconArr:arr,
    });
  },
  save:function(){
    var that=this;
    for(var i=0;i<that.data.ColorArr.length;i++){
      if (that.data.ColorArr[i].SelectColor){
        app.globalData.TempStr=that.data.ColorArr[i].Color;
        break;
      }
    }
    for(var i=0;i<that.data.IconArr.length;i++){
      if (that.data.IconArr[i].SelectIcon=="panelIconSelect"){
        app.globalData.TempStr2=that.data.IconArr[i].ImageUrl;
        break;
      }
    }
    that.close();
  },
  close: function () {
    wx.navigateBack({
      delta: 1,
    });
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})
