// packages/block-editor/src/components/link-control/use-internal-value.js
import { useState } from "@wordpress/element";
import fastDeepEqual from "fast-deep-equal";
function useInternalValue(value) {
  const [internalValue, setInternalValue] = useState(value || {});
  const [previousValue, setPreviousValue] = useState(value);
  if (!fastDeepEqual(value, previousValue)) {
    setPreviousValue(value);
    setInternalValue(value);
  }
  const setInternalURLInputValue = (nextValue) => {
    setInternalValue({
      ...internalValue,
      url: nextValue
    });
  };
  const setInternalTextInputValue = (nextValue) => {
    setInternalValue({
      ...internalValue,
      title: nextValue
    });
  };
  const createSetInternalSettingValueHandler = (settingsKeys) => (nextValue) => {
    const settingsUpdates = Object.keys(nextValue).reduce(
      (acc, key) => {
        if (settingsKeys.includes(key)) {
          acc[key] = nextValue[key];
        }
        return acc;
      },
      {}
    );
    setInternalValue({
      ...internalValue,
      ...settingsUpdates
    });
  };
  return [
    internalValue,
    setInternalValue,
    setInternalURLInputValue,
    setInternalTextInputValue,
    createSetInternalSettingValueHandler
  ];
}
export {
  useInternalValue as default
};
//# sourceMappingURL=use-internal-value.js.map
