import { A, T as TailwindStyledElement, x } from '../../index-2f5488b6.js';
import { n, e as e$1 } from '../../query-assigned-elements-5d94572f.js';
import { c as customClassMap } from '../../index-5e194caf.js';
import { e, i, t } from '../../directive-2bb7789e.js';

class CustomStyleMapDirective extends i {
  constructor(partInfo) {
    super(partInfo);
    if (partInfo.type !== t.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 A;
    }
    return ` ${styles.join("; ")} `;
  }
}
const customStyleMap = e(CustomStyleMapDirective);

const sliceAddress = (address, startSliceBy = 6, endSliceBy) => {
  if (!address) {
    return "";
  }
  let sliceAddress2 = "";
  endSliceBy = endSliceBy || startSliceBy;
  if (address.length < startSliceBy + endSliceBy) {
    return address;
  }
  sliceAddress2 = address.length > startSliceBy + 2 ? `${address.slice(0, startSliceBy + 2)}...${address.slice(-endSliceBy)}` : address;
  return sliceAddress2;
};

const style = ":host {\n    display: inline-flex\n}";

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;
};
let LuksoUsername = class extends TailwindStyledElement(style) {
  constructor() {
    super(...arguments);
    this.name = "";
    this.address = "";
    this.maxWidth = 200;
    this.size = "large";
    this.sliceBy = 8;
    this.addressColor = "";
    this.nameColor = "";
    this.customClass = "";
    this.hidePrefix = false;
    this.prefix = "@";
    /** Width of the first 4 bytes of the address */
    this.bytesWidth = 52;
  }
  addressBytesTemplate() {
    return x`<div
      class="inline-block ${customClassMap({
      ["text-neutral-60"]: this.addressColor === ""
    })}"
      style=${customStyleMap({
      [`color: var(--${this.addressColor})`]: this.addressColor !== ""
    })}
    >
      #${this.address.slice(2, 6)}
    </div>`;
  }
  nameTemplate() {
    return x`<div
      class="inline-block whitespace-nowrap overflow-hidden text-ellipsis ${customClassMap(
      {
        ["text-transparent bg-clip-text bg-gradient-to-r from-gradient-1-start to-gradient-1-end"]: this.nameColor === ""
      }
    )}"
      style=${customStyleMap({
      [`max-width: ${this.maxWidth - this.bytesWidth}px`]: true,
      [`color: var(--${this.nameColor})`]: this.nameColor !== ""
    })}
    >
      ${this.hidePrefix ? A : this.prefix}${this.name}
    </div>`;
  }
  addressTemplate() {
    return x`<div
      class="inline-block ${customClassMap({
      ["text-" + this.addressColor]: this.addressColor !== "",
      ["text-neutral-20"]: this.addressColor === ""
    })}"
    >
      ${sliceAddress(this.address, this.sliceBy, this.sliceBy)}
    </div>`;
  }
  render() {
    const template = (() => {
      if (this.name && this.address) {
        return x`${this.nameTemplate()}${this.addressBytesTemplate()}`;
      }
      if (this.name) {
        return this.nameTemplate();
      }
      if (this.address) {
        return this.addressTemplate();
      }
    })();
    return x`<div
      class="inline-flex ${customClassMap({
      [this.customClass]: true,
      "paragraph-ptmono-10-bold": this.size === "x-small",
      "paragraph-ptmono-12-bold": this.size === "small",
      "paragraph-ptmono-14-bold": this.size === "medium",
      "paragraph-ptmono-16-bold": this.size === "large"
    })}"
    >
      ${template}
    </div>`;
  }
};
__decorateClass([
  n({ type: String })
], LuksoUsername.prototype, "name", 2);
__decorateClass([
  n({ type: String })
], LuksoUsername.prototype, "address", 2);
__decorateClass([
  n({ type: Number, attribute: "max-width" })
], LuksoUsername.prototype, "maxWidth", 2);
__decorateClass([
  n({ type: "string" })
], LuksoUsername.prototype, "size", 2);
__decorateClass([
  n({ type: Number, attribute: "slice-by" })
], LuksoUsername.prototype, "sliceBy", 2);
__decorateClass([
  n({ type: String, attribute: "address-color" })
], LuksoUsername.prototype, "addressColor", 2);
__decorateClass([
  n({ type: String, attribute: "name-color" })
], LuksoUsername.prototype, "nameColor", 2);
__decorateClass([
  n({ type: String, attribute: "custom-class" })
], LuksoUsername.prototype, "customClass", 2);
__decorateClass([
  n({ type: Boolean, attribute: "hide-prefix" })
], LuksoUsername.prototype, "hidePrefix", 2);
__decorateClass([
  n({ type: String })
], LuksoUsername.prototype, "prefix", 2);
LuksoUsername = __decorateClass([
  e$1("lukso-username")
], LuksoUsername);

export { LuksoUsername };
