"use client";
import { useMapWithInit } from "./useMapWithInit.js";
import { useStyleObserver } from "./useStyleObserver.js";
import { objectEntries } from "../../utils/objectEntries.js";
function useStyle(properties, options = {}) {
  const { ref, initialValues, onChange } = options;
  const propertyValues = useMapWithInit(
    () => initialValues ? objectEntries(initialValues).map(([property, value]) => [property, value]) : properties.map((property) => [property, void 0])
  );
  const callbackRef = useStyleObserver(
    properties,
    (records) => {
      let changed = false;
      for (const record of records) {
        if (propertyValues.get(record.property) !== record.value) {
          propertyValues.set(record.property, record.value);
          changed = true;
        }
      }
      if (changed) {
        onChange == null ? void 0 : onChange(propertyValues);
      }
    },
    [],
    { ref, immediate: true }
  );
  return [callbackRef, propertyValues];
}
export {
  useStyle
};
