import {View} from 'react-native'
import React from 'react'
import LdvColorSlider from './ldvColorSlider'
import Spacer from './Spacer'
import LdvPresetView from './ldvPresetView'
import LdvSlider from './ldvSlider'
import {Utils} from 'tuya-panel-kit'
import I18n from '../i18n/index'
import {cctToColor} from '../utils/cctUtils'
import ThemeType from '../config/themeType'

const {convertX: cx} = Utils.RatioUtils
const { withTheme } = Utils.ThemeUtils

export interface ColorTempAdjustViewProps {
  theme?: ThemeType
  colorTemp: number
  brightness: number
  minBrightness?: number
  isSupportTemperature: boolean
  isSupportBrightness: boolean
  onCCTChange?: (cct: number) => void
  onCCTChangeComplete: (cct: number) => void
  onBrightnessChange?: (brightness: number) => void
  onBrightnessChangeComplete: (brightness: number) => void
}

const ColorTempAdjustView = (props: ColorTempAdjustViewProps) => {
  return (
    <View>
      {props.isSupportTemperature &&
          <>
              <LdvColorSlider
                  type={'temperature'}
                  title={I18n.getLang('light_sources_tile_main_lighting_shade')}
                  thumbColor={cctToColor(props.colorTemp)}
                  value={props.colorTemp}
                  onValueChange={props.onCCTChange}
                  onSlidingComplete={props.onCCTChangeComplete}/>
              <Spacer height={cx(10)}/>
              <LdvPresetView
                  type={'temperature'}
                  style={{height: cx(60)}}
                  onPress={item => {
                    props.onCCTChangeComplete(item.value)
                  }}/>
              <Spacer height={cx(10)}/>
          </>
      }
      {props.isSupportBrightness &&
          <LdvSlider
              title={I18n.getLang('light_sources_tile_rgb_lighting_brightness')}
              min={props.minBrightness}
              value={props.brightness}
              onValueChange={props.onBrightnessChange}
              onSlidingComplete={props.onBrightnessChangeComplete}/>}
    </View>
  )
}

export default withTheme(ColorTempAdjustView)
