/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-68a4774
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { useRef } from 'react';
import { useDateSegment } from 'react-aria';
import { tasty } from '../../../tasty/index.js';
const LiteralSegmentElement = tasty({
    qa: 'LiteralSegment',
    as: 'span',
    'aria-hidden': 'true',
    styles: {},
});
const EditableSegmentElement = tasty({
    qa: 'EditableSegment',
    styles: {
        padding: '0 1bw',
        fontVariantNumeric: 'tabular-nums lining-nums',
        textAlign: 'right',
        font: 'monospace',
        border: 0,
        outline: 0,
        color: {
            '': 'inherit',
            ':focus': '#white',
        },
        fill: {
            '': '#clear',
            ':focus': '#purple',
        },
        radius: '.25x',
        Placeholder: {
            opacity: '#disabled-opacity',
        },
    },
});
export function DatePickerSegment({ segment, state, ...otherProps }) {
    switch (segment.type) {
        // A separator, e.g. punctuation
        case 'literal':
            return _jsx(LiteralSegment, { segment: segment });
        // Editable segment
        default:
            return (_jsx(EditableSegment, { segment: segment, state: state, ...otherProps }));
    }
}
function LiteralSegment({ segment }) {
    return (_jsx(LiteralSegmentElement, { "data-type": segment.type === 'literal' ? undefined : segment.type, children: segment.text }));
}
function EditableSegment({ segment, state }) {
    let ref = useRef(null);
    let { segmentProps } = useDateSegment(segment, state, ref);
    return (_jsx(EditableSegmentElement, { ...segmentProps, ref: ref, mods: {
            placeholder: segment.isPlaceholder,
            'read-only': !segment.isEditable,
        }, style: {
            ...segmentProps.style,
            minWidth: segment.maxValue != null
                ? `calc(${String(segment.maxValue).length + 'ch'})`
                : undefined,
        }, "data-testid": segment.type, children: segment.isPlaceholder ? (_jsx("span", { "data-element": "Placeholder", "aria-hidden": "true", children: segment.placeholder })) : (segment.text) }));
}

        