import { dynamic } from "@solidjs/web";
import { createMemo, omit } from "solid-js";
import { composeRefs, userRef } from "../../internals/compose-refs.jsx";
import { mergeRootProps } from "../../internals/merge-root-props.jsx";
import { resolveClassStyle } from "../../internals/resolve-class-style.jsx";
import { useButton } from "../../internals/use-button/use-button.jsx";
import { useNumberFieldRootContext } from "../root/number-field-root-context.jsx";
import { useNumberFieldButton } from "../root/use-number-field-button.jsx";
import { numberFieldDataAttrs } from "../utils/state-attributes-mapping.jsx";
/**
 * A stepper button that increases the field value when clicked. Renders a
 * `<button>` (or `as` override).
 */
export function NumberFieldIncrement(props) {
  const context = useNumberFieldRootContext();
  const isMax = () => {
    const current = context.value();
    return current != null && current >= context.maxWithDefault();
  };
  const disabled = () => props.disabled === true || context.disabled() || isMax();
  const {
    props: buttonHandlerProps
  } = useNumberFieldButton({
    isIncrement: true,
    inputRef: context.inputRef,
    inputValue: context.inputValue,
    disabled,
    readOnly: context.readOnly,
    id: context.id,
    setValue: context.setValue,
    getStepAmount: context.getStepAmount,
    incrementValue: context.incrementValue,
    allowInputSyncRef: context.allowInputSyncRef,
    formatOptionsRef: context.formatOptionsRef,
    valueRef: context.valueRef,
    locale: context.locale,
    lastChangedValueRef: context.lastChangedValueRef,
    onValueCommitted: context.onValueCommitted
  });
  const {
    props: buttonProps,
    ref: buttonRef
  } = useButton({
    disabled,
    native: () => props.nativeButton ?? true,
    focusableWhenDisabled: true
  });
  const state = createMemo(() => ({
    ...context.state(),
    disabled: disabled()
  }));
  const userStyling = resolveClassStyle(props, () => state());
  const userProps = omit(props, "class", "style", "attrs", "as", "nativeButton", "disabled");
  const styledUserProps = mergeRootProps(userStyling, userProps);
  let merged = mergeRootProps(buttonProps, buttonHandlerProps);
  merged = mergeRootProps(merged, numberFieldDataAttrs(state));
  merged = mergeRootProps(merged, styledUserProps);
  const Tag = dynamic(() => props.as ?? "button");
  return <Tag {...merged} ref={composeRefs(buttonRef, userRef(props))} />;
}
//# sourceMappingURL=number-field-increment.jsx.map
