import { directive, Directive, PartType } from 'lit/directive.js';

class CustomClassMapDirective extends Directive {
  constructor(partInfo) {
    super(partInfo);
    if (partInfo.type !== PartType.ATTRIBUTE || partInfo.name !== "class" || partInfo.strings?.length > 2) {
      throw new Error(
        "`customClassMap()` can only be used in the `class` attribute and must be the only part in the attribute."
      );
    }
  }
  render(classInfoList) {
    return " " + Object.keys(classInfoList).filter((key) => classInfoList[key]).join(" ") + " ";
  }
}
const customClassMap = directive(CustomClassMapDirective);

export { CustomClassMapDirective, customClassMap };
