'use client'

import { mergeProps } from '@zag-js/react'
import { forwardRef } from 'react'
import { type HTMLProps, type PolymorphicProps, ark } from '../factory.ts'
import { useColorPickerChannelPropsContext } from './use-color-picker-channel-props-context.ts'
import { useColorPickerContext } from './use-color-picker-context.ts'
import { useColorPickerFormatPropsContext } from './use-color-picker-format-context.ts'

export interface ColorPickerChannelSliderTrackBaseProps extends PolymorphicProps {}
export interface ColorPickerChannelSliderTrackProps extends HTMLProps<'div'>, ColorPickerChannelSliderTrackBaseProps {}

export const ColorPickerChannelSliderTrack = forwardRef<HTMLDivElement, ColorPickerChannelSliderTrackProps>(
  (props, ref) => {
    const colorPicker = useColorPickerContext()

    const channelProps = useColorPickerChannelPropsContext()
    const formatProps = useColorPickerFormatPropsContext()
    const channelSliderProps = { ...channelProps, ...formatProps }

    const mergedProps = mergeProps(colorPicker.getChannelSliderTrackProps(channelSliderProps), props)

    return <ark.div {...mergedProps} ref={ref} />
  },
)

ColorPickerChannelSliderTrack.displayName = 'ColorPickerChannelSliderTrack'
