local this = class("modulePhotoGroup_param", require("ui.pages.photo.group.modulePhotoGroup_base"))

function this.bind()
  return {
    goSlider = false,
    sliderNumTxt = "0",
    selectedId = 0,
    activeReset = false,
    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.mediator = L_PhotoManager:getMediator()
  self.paramDic = self.mediator.paramDic
  self.bind.selectedId = L_Const.photoParam.wideIntensity
  self:initGroupList(L_Const.photoGroup.param)
  self.timer = Timer.repeated(0, self.update, self)
  L_PhotoManager:addListener(L_PhotoManager.event.photoTemplateChange, self.onEvent_photoTemplateChange, self)
end

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

function this:onEvent_photoTemplateChange()
  self:refreshSelection(self.settingId)
end

function this:update()
  if self.settingId == L_Const.photoParam.rotation and self.bindComponents.slider.gameObject.activeInHierarchy then
    self.bindComponents.slider.value = self.mediator:getPhotoParmVal(self.settingId)
  end
end

function this:refreshSelection(id)
  local isOn = id ~= 0
  self.bind.goSlider = isOn
  self.settingId = id
  if isOn then
    self.bind.activeReset = self.settingId ~= L_Const.photoParam.rotation
    self:refreshSliderArea(id)
    self:refreshDefaultSignPos(id)
  end
end

function this:setVal(id, val)
  L_PhotoManager:getMediator():setPhotoParmVal(id, val)
  local defaultMin, defaultMax = this.super.getDefaultMinAndMax(self, id)
  if tonumber(defaultMin) ~= 0 or tonumber(defaultMax) ~= 1 then
    self.bind.sliderNumTxt = string.format("%.0f", val)
  else
    self.bind.sliderNumTxt = string.format("%.0f", val * 100)
  end
end

function this:getDefaultVal(id)
  if self.settingId == L_Const.photoParam.rotation then
    return self.mediator:getPhotoParmVal(self.settingId)
  end
  local val = self.paramDic[id] or this.super.getDefaultVal(self, id)
  return val
end

return this
