'use strict';

const directive_js = require('lit/directive.js');
const litHtml = require('lit-html');

class CustomClassMapDirective extends directive_js.Directive {
  constructor(partInfo) {
    super(partInfo);
    if (partInfo.type !== directive_js.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_js.directive(CustomClassMapDirective);

class CustomStyleMapDirective extends directive_js.Directive {
  constructor(partInfo) {
    super(partInfo);
    if (partInfo.type !== directive_js.PartType.ATTRIBUTE || partInfo.name !== "style" || partInfo.strings?.length > 2) {
      throw new Error(
        "`customStyleMap()` can only be used in the `style` attribute and must be the only part in the attribute."
      );
    }
  }
  render(styleInfoList) {
    const styles = Object.keys(styleInfoList).filter((key) => styleInfoList[key]);
    if (styles.length === 0) {
      return litHtml.nothing;
    }
    return ` ${styles.join("; ")} `;
  }
}
const customStyleMap = directive_js.directive(CustomStyleMapDirective);

exports.customClassMap = customClassMap;
exports.customStyleMap = customStyleMap;
