// packages/components/src/border-control/border-control-dropdown/hook.ts
import { useMemo } from "@wordpress/element";
import * as styles from "../styles.js";
import { parseQuantityAndUnitFromRawValue } from "../../unit-control/utils.js";
import { useContextSystem } from "../../context/index.js";
import { useCx } from "../../utils/hooks/use-cx.js";
function useBorderControlDropdown(props) {
  const {
    border,
    className,
    colors = [],
    enableAlpha = false,
    enableStyle = true,
    onChange,
    previousStyleSelection,
    size = "default",
    __experimentalIsRenderedInSidebar = false,
    ...otherProps
  } = useContextSystem(props, "BorderControlDropdown");
  const [widthValue] = parseQuantityAndUnitFromRawValue(border?.width);
  const hasZeroWidth = widthValue === 0;
  const onColorChange = (color) => {
    const style = border?.style === "none" ? previousStyleSelection : border?.style;
    const width = hasZeroWidth && !!color ? "1px" : border?.width;
    onChange({
      color,
      style,
      width
    });
  };
  const onStyleChange = (style) => {
    const width = hasZeroWidth && !!style ? "1px" : border?.width;
    onChange({
      ...border,
      style,
      width
    });
  };
  const onReset = () => {
    onChange({
      ...border,
      color: void 0,
      style: void 0
    });
  };
  const cx = useCx();
  const classes = useMemo(() => {
    return cx(styles.borderControlDropdown, className);
  }, [className, cx]);
  const indicatorClassName = useMemo(() => {
    return cx(styles.borderColorIndicator);
  }, [cx]);
  const indicatorWrapperClassName = useMemo(() => {
    return cx(styles.colorIndicatorWrapper(border, size));
  }, [border, cx, size]);
  const popoverControlsClassName = useMemo(() => {
    return cx(styles.borderControlPopoverControls);
  }, [cx]);
  const popoverContentClassName = useMemo(() => {
    return cx(styles.borderControlPopoverContent);
  }, [cx]);
  const resetButtonWrapperClassName = useMemo(() => {
    return cx(styles.resetButtonWrapper);
  }, [cx]);
  return {
    ...otherProps,
    border,
    className: classes,
    colors,
    enableAlpha,
    enableStyle,
    indicatorClassName,
    indicatorWrapperClassName,
    onColorChange,
    onStyleChange,
    onReset,
    popoverContentClassName,
    popoverControlsClassName,
    resetButtonWrapperClassName,
    size,
    __experimentalIsRenderedInSidebar
  };
}
export {
  useBorderControlDropdown
};
//# sourceMappingURL=hook.js.map
