import React, { useState, useEffect, useCallback } from 'react';
import { View, StyleSheet } from 'react-native';
import Slider from '@coorpacademy/react-native-slider';
import Text from '../../../../atom/text/index.native';
import { useTemplateContext } from '../../../../template/app-review/template-context';
import { BOX_STYLE } from '../../../../variables/shadow';
const createStyleSheet = (brandTheme, theme) => StyleSheet.create({
  container: {
    flex: 1,
    paddingHorizontal: 20,
    flexDirection: 'column',
    justifyContent: 'center'
  },
  header: {
    fontSize: 25,
    fontWeight: theme.fontWeight.bold,
    textAlign: 'center'
  },
  textValue: {
    fontSize: 15,
    color: theme.colors.black,
    fontWeight: theme.fontWeight.bold,
    textAlign: 'center'
  },
  valuesContainer: {
    flexDirection: 'row',
    justifyContent: 'space-around'
  },
  leftValue: {
    flex: 1,
    alignItems: 'flex-start'
  },
  rightValue: {
    flex: 1,
    alignItems: 'flex-end'
  },
  track: {
    height: 10,
    borderRadius: theme.radius.button
  },
  thumb: {
    ...BOX_STYLE,
    width: 30,
    height: 30,
    borderRadius: 30 / 2,
    borderWidth: 5,
    backgroundColor: brandTheme?.colors?.primary,
    borderColor: 'white'
  }
});
const QuestionSlider = props => {
  const {
    step,
    style,
    min,
    max,
    unit = '',
    value: storeValue = 0,
    onSlidingComplete,
    testID
  } = props;
  const templateContext = useTemplateContext();
  const {
    brandTheme,
    theme
  } = templateContext;
  const [styleSheet, setStylesheet] = useState(null);
  const [value, setValue] = useState(storeValue);
  const handleSlidingComplete = useCallback(() => {
    onSlidingComplete(value);
  }, [onSlidingComplete, value]);
  useEffect(() => {
    const _stylesheet = createStyleSheet(brandTheme, theme);
    setStylesheet(_stylesheet);
  }, [brandTheme, theme]);
  if (!styleSheet) {
    return null;
  }
  const textStyle = {
    ...styleSheet.header,
    color: brandTheme?.colors?.primary
  };
  return /*#__PURE__*/React.createElement(View, {
    style: [styleSheet.container, style],
    testID: testID
  }, /*#__PURE__*/React.createElement(Text, {
    style: textStyle,
    testID: "slider-value"
  }, value), /*#__PURE__*/React.createElement(Slider, {
    step: step || 1,
    value: value,
    onValueChange: setValue,
    maximumValue: max,
    minimumValue: min,
    onSlidingComplete: handleSlidingComplete,
    minimumTrackTintColor: brandTheme?.colors?.primary,
    trackStyle: styleSheet.track,
    thumbStyle: [styleSheet.thumb],
    testID: "slider"
  }), /*#__PURE__*/React.createElement(View, {
    style: styleSheet.valuesContainer,
    testID: "slider-values-container"
  }, /*#__PURE__*/React.createElement(View, {
    style: styleSheet.leftValue
  }, /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.textValue,
    testID: "slider-min-value"
  }, `${min} ${unit}`)), /*#__PURE__*/React.createElement(View, {
    style: styleSheet.rightValue
  }, /*#__PURE__*/React.createElement(Text, {
    style: styleSheet.textValue,
    testID: "slider-max-value"
  }, `${max} ${unit}`))));
};
export default QuestionSlider;
//# sourceMappingURL=index.native.js.map