// packages/block-editor/src/components/block-styles/utils.js
import TokenList from "@wordpress/token-list";
import { _x } from "@wordpress/i18n";
function getActiveStyle(styles, className) {
  for (const style of new TokenList(className).values()) {
    if (style.indexOf("is-style-") === -1) {
      continue;
    }
    const potentialStyleName = style.substring(9);
    const activeStyle = styles?.find(
      ({ name }) => name === potentialStyleName
    );
    if (activeStyle) {
      return activeStyle;
    }
  }
  return getDefaultStyle(styles);
}
function replaceActiveStyle(className, activeStyle, newStyle) {
  const list = new TokenList(className);
  if (activeStyle) {
    list.remove("is-style-" + activeStyle.name);
  }
  list.add("is-style-" + newStyle.name);
  return list.value;
}
function getRenderedStyles(styles) {
  if (!styles || styles.length === 0) {
    return [];
  }
  return getDefaultStyle(styles) ? styles : [
    {
      name: "default",
      label: _x("Default", "block style"),
      isDefault: true
    },
    ...styles
  ];
}
function getDefaultStyle(styles) {
  return styles?.find((style) => style.isDefault);
}
export {
  getActiveStyle,
  getDefaultStyle,
  getRenderedStyles,
  replaceActiveStyle
};
//# sourceMappingURL=utils.js.map
