local this = class("modulePhotoGroup_color", require("ui.pages.photo.group.modulePhotoGroup_base"))
local IDTOFIELD = L_PhotoManager.IDTOFIELD

function this.bind()
  return {
    goSlider = false,
    sliderNumTxt = "0",
    selectedId = 0,
    list = {
      moduleName = "pages/photo/cell/cellPhotoMenu"
    }
  }
end

function this.methods()
  return {
    onValueChanged_selection = function(self, id)
      self:refreshSelection(id)
    end,
    onClick_reset = function(self)
      self:resetVal(self.settingId)
    end,
    onValueChanged_slider = function(self, val)
      self:setVal(self.settingId, val)
    end
  }
end

function this:open()
  self.paramDic = {}
  local args = self:getUseArgs(L_Const.photoTemplateSettingParam.color)
  self.bind.selectedId = args and args.val or L_Const.photoParam.postExposure
  L_PhotoManager:addListener(L_PhotoManager.event.photoTemplateChange, self.onEvent_photoTemplateChange, self)
  self:initGroupList(L_Const.photoGroup.color)
end

function this:close()
  L_PhotoManager:removeListener(L_PhotoManager.event.photoTemplateChange, self.onEvent_photoTemplateChange, self)
end

function this:onEvent_photoTemplateChange()
  self:refreshSelection(self.bind.selectedId)
end

function this:refreshSelection(id)
  local tpl = self.paramTpl:getTplById(id)
  local isSlider = self.paramTpl:getParamType(tpl) == L_Const.photoParamType.range
  self.bind.goSlider = isSlider
  self.settingId = id
  L_PhotoManager:getMediator().colorSettingId = id
  if isSlider then
    self:refreshSliderArea(id)
    self:refreshDefaultSignPos(id)
  end
end

function this:setVal(id, val)
  local filter = L_PhotoManager:getMediator().photoFilter
  self.bind.sliderNumTxt = string.format("%.0f", val * 50)
  filter[IDTOFIELD[id]] = val
end

function this:getDefaultVal(id)
  local filter = L_PhotoManager:getMediator().photoFilter
  local val = filter[IDTOFIELD[id]]
  return val
end

return this
