// packages/block-library/src/template-part/variations.js
import { store as coreDataStore } from "@wordpress/core-data";
import { select } from "@wordpress/data";
import { getTemplatePartIcon } from "./edit/utils/get-template-part-icon";
function enhanceTemplatePartVariations(settings, name) {
  if (name !== "core/template-part") {
    return settings;
  }
  if (settings.variations) {
    const isActive = (blockAttributes, variationAttributes) => {
      const { area, theme, slug } = blockAttributes;
      if (area) {
        return area === variationAttributes.area;
      }
      if (!slug) {
        return false;
      }
      const { getCurrentTheme, getEntityRecord } = select(coreDataStore);
      const entity = getEntityRecord(
        "postType",
        "wp_template_part",
        `${theme || getCurrentTheme()?.stylesheet}//${slug}`
      );
      if (entity?.slug) {
        return entity.slug === variationAttributes.slug;
      }
      return entity?.area === variationAttributes.area;
    };
    const variations = settings.variations.map((variation) => {
      return {
        ...variation,
        ...!variation.isActive && { isActive },
        ...typeof variation.icon === "string" && {
          icon: getTemplatePartIcon(variation.icon)
        }
      };
    });
    return {
      ...settings,
      variations
    };
  }
  return settings;
}
export {
  enhanceTemplatePartVariations
};
//# sourceMappingURL=variations.js.map
