import { html } from 'lit';
import { property } from 'lit/decorators.js';
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
import DOMPurify from 'dompurify';
import { safeCustomElement } from '../../shared/safe-custom-element.js';
import { TailwindStyledElement } from '../../shared/tailwind-element/index.js';
import style from './style.css.js';

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result) __defProp(target, key, result);
  return result;
};
const DEFAULT_OPTIONS = {
  ADD_ATTR: ["target"],
  // allow target attribute on anchor tags
  CUSTOM_ELEMENT_HANDLING: {
    tagNameCheck: /^lukso-/,
    attributeNameCheck: /.*/
  }
};
const NO_HTML_TAGS_OPTIONS = { ALLOWED_TAGS: [] };
let LuksoSanitize = class extends TailwindStyledElement(style) {
  constructor() {
    super(...arguments);
    this.htmlContent = "";
    this.isPre = false;
    this.stripHtmlTags = false;
  }
  sanitize() {
    if (this.stripHtmlTags) {
      return DOMPurify.sanitize(this.htmlContent, NO_HTML_TAGS_OPTIONS);
    }
    return DOMPurify.sanitize(this.htmlContent, DEFAULT_OPTIONS);
  }
  // in order to show HTML we  need to use unsafeHTML directive.
  // This is safe since we already sanitized content
  render() {
    return this.isPre ? html`<!-- prettier-ignore -->
          <div
      class='whitespace-pre-wrap'>${unsafeHTML(this.sanitize())}</div>` : html`${unsafeHTML(this.sanitize())}`;
  }
};
__decorateClass([
  property({ type: String, attribute: "html-content" })
], LuksoSanitize.prototype, "htmlContent", 2);
__decorateClass([
  property({ type: Boolean, attribute: "is-pre" })
], LuksoSanitize.prototype, "isPre", 2);
__decorateClass([
  property({ type: Boolean, attribute: "strip-html-tags" })
], LuksoSanitize.prototype, "stripHtmlTags", 2);
LuksoSanitize = __decorateClass([
  safeCustomElement("lukso-sanitize")
], LuksoSanitize);

export { DEFAULT_OPTIONS, LuksoSanitize, NO_HTML_TAGS_OPTIONS };
