import RnSlider from '@react-native-community/slider';
import React from 'react';
import type { StyleProp, ViewStyle } from 'react-native';
import { useTheme } from '../../theme';

export interface SingleSliderProps {
  /**
   * Minimum value of the slider.
   * Defaults to 0.
   */
  minimumValue?: number;
  /**
   * Maximum value of the slider.
   * Defaults to 1.
   */
  maximumValue?: number;
  /**
   * Step value of the slider.
   * The value should be between 0 and (maximumValue - minimumValue).
   * Defaults to 0.
   */
  step?: number;
  /**
   * Value of the slider.
   * Defaults to 0.
   */
  value?: number;
  /**
   * Callback continuously called while the user is dragging the slider.
   */
  onValueChange?: (value: number) => void;
  /**
   * Callback that is called when the user picks up the slider.
   * The initial value is passed as an argument to the callback handler.
   */
  onSlidingStart?: (value: number) => void;
  /**
   * Callback that is called when the user releases the slider, regardless if the value has changed.
   * The current value is passed as an argument to the callback handler.
   */
  onSlidingComplete?: (value: number) => void;
  /**
   * Whether the slider is disabled.
   */
  disabled?: boolean;
  /**
   * Additional style.
   */
  style?: StyleProp<ViewStyle>;
  /**
   * Testing id of the component.
   */
  testID?: string;
}

const Slider = ({
  minimumValue = 0,
  maximumValue = 1,
  step = 0,
  value = 0,
  onValueChange,
  onSlidingStart,
  onSlidingComplete,
  disabled = false,
  style,
  testID,
}: SingleSliderProps) => {
  const theme = useTheme();

  const { selectedTrack, thumb, unselectedTrack } = theme.__hd__.slider.colors;

  return (
    <RnSlider
      minimumValue={minimumValue}
      maximumValue={maximumValue}
      step={step}
      value={value}
      onValueChange={onValueChange}
      onSlidingStart={onSlidingStart}
      onSlidingComplete={onSlidingComplete}
      disabled={disabled}
      minimumTrackTintColor={selectedTrack}
      thumbTintColor={thumb}
      maximumTrackTintColor={unselectedTrack}
      style={style}
      testID={testID}
    />
  );
};

export default Slider;
