import { B as BaseError } from './base-KJhhKWYy.js';
import { n } from './property-DfumgIL6.js';
import { r } from './state-CaelFSbE.js';

function defineChain(chain) {
    return {
        formatters: undefined,
        fees: undefined,
        serializers: undefined,
        ...chain,
    };
}

class InvalidDecimalNumberError extends BaseError {
    constructor({ value }) {
        super(`Number \`${value}\` is not a valid decimal number.`, {
            name: 'InvalidDecimalNumberError',
        });
    }
}

/**
 * Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
 *
 * - Docs: https://viem.sh/docs/utilities/parseUnits
 *
 * @example
 * import { parseUnits } from 'viem'
 *
 * parseUnits('420', 9)
 * // 420000000000n
 */
function parseUnits(value, decimals) {
    if (!/^(-?)([0-9]*)\.?([0-9]*)$/.test(value))
        throw new InvalidDecimalNumberError({ value });
    let [integer, fraction = '0'] = value.split('.');
    const negative = integer.startsWith('-');
    if (negative)
        integer = integer.slice(1);
    // trim trailing zeros.
    fraction = fraction.replace(/(0+)$/, '');
    // round off if the fraction is larger than the number of decimals.
    if (fraction.length > decimals) {
        const [left, unit, right] = [
            fraction.slice(0, decimals - 1),
            fraction.slice(decimals - 1, decimals),
            fraction.slice(decimals),
        ];
        const rounded = Math.round(Number(`${unit}.${right}`));
        if (rounded > 9)
            fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, '0');
        else
            fraction = `${left}${rounded}`;
        if (fraction.length > decimals) {
            fraction = fraction.slice(1);
            integer = `${BigInt(integer) + 1n}`;
        }
        fraction = fraction.slice(0, decimals);
    }
    else {
        fraction = fraction.padEnd(decimals, '0');
    }
    return BigInt(`${negative ? '-' : ''}${integer}${fraction}`);
}

const lukso = /*#__PURE__*/ defineChain({
    id: 42,
    network: 'lukso',
    name: 'LUKSO',
    nativeCurrency: {
        name: 'LUKSO',
        symbol: 'LYX',
        decimals: 18,
    },
    rpcUrls: {
        default: {
            http: ['https://rpc.mainnet.lukso.network'],
            webSocket: ['wss://ws-rpc.mainnet.lukso.network'],
        },
    },
    blockExplorers: {
        default: {
            name: 'LUKSO Mainnet Explorer',
            url: 'https://explorer.execution.mainnet.lukso.network',
            apiUrl: 'https://api.explorer.execution.mainnet.lukso.network/api',
        },
    },
    contracts: {
        multicall3: {
            address: '0xcA11bde05977b3631167028862bE2a173976CA11',
            blockCreated: 468183,
        },
    },
});

const luksoTestnet = /*#__PURE__*/ defineChain({
    id: 4201,
    name: 'LUKSO Testnet',
    nativeCurrency: {
        decimals: 18,
        name: 'LUKSO Testnet',
        symbol: 'LYXt',
    },
    rpcUrls: {
        default: {
            http: ['https://rpc.testnet.lukso.network'],
            webSocket: ['wss://ws-rpc.testnet.lukso.network'],
        },
    },
    blockExplorers: {
        default: {
            name: 'LUKSO Testnet Explorer',
            url: 'https://explorer.execution.testnet.lukso.network',
            apiUrl: 'https://api.explorer.execution.testnet.lukso.network/api',
        },
    },
    contracts: {
        multicall3: {
            address: '0xcA11bde05977b3631167028862bE2a173976CA11',
            blockCreated: 605348,
        },
    },
    testnet: true,
});

({
  nativeCurrency: {
    ...lukso.nativeCurrency,
    supply: parseUnits("42000000", 18).toString()
  },
  contracts: {
    ...lukso.contracts}});
({
  nativeCurrency: {
    ...luksoTestnet.nativeCurrency,
    supply: parseUnits("42000000", 18).toString()},
  contracts: {
    ...luksoTestnet.contracts}});

// Generated ESM version of ua-parser-js
// DO NOT EDIT THIS FILE!
// Source: /src/main/ua-parser.js

/////////////////////////////////////////////////////////////////////////////////
/* UAParser.js v2.0.7
   Copyright © 2012-2025 Faisal Salman <f@faisalman.com>
   AGPLv3 License *//*
   Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.
   Supports browser & node.js environment. 
   Demo   : https://uaparser.dev
   Source : https://github.com/faisalman/ua-parser-js */
/////////////////////////////////////////////////////////////////////////////////

/* jshint esversion: 6 */ 
/* globals window */


    
    //////////////
    // Constants
    /////////////

    var TYPEOF = {
            OBJECT      : 'object',
            UNDEFINED   : 'undefined'
        },

        // properties
        BROWSER     = 'browser',
        CPU         = 'cpu',
        DEVICE      = 'device',
        ENGINE      = 'engine',
        OS          = 'os',
        NAME        = 'name',
        TYPE        = 'type',
        VENDOR      = 'vendor',
        VERSION     = 'version',
        ARCHITECTURE= 'architecture',
        MAJOR       = 'major',
        MODEL       = 'model',

        // device types
        CONSOLE     = 'console',
        MOBILE      = 'mobile',
        TABLET      = 'tablet',
        SMARTTV     = 'smarttv',
        WEARABLE    = 'wearable',
        EMBEDDED    = 'embedded';
   
    var isWindow            = typeof window !== TYPEOF.UNDEFINED,
        NAVIGATOR           = (isWindow && window.navigator) ? 
                                window.navigator : 
                                undefined;
        (NAVIGATOR && NAVIGATOR.userAgentData) ? 
                                NAVIGATOR.userAgentData : 
                                undefined;

    ///////////
    // Helper
    //////////

    var enumerize = function (arr) {
            var enums = {};
            for (var i=0; i<arr.length; i++) {
                enums[arr[i].toUpperCase()] = arr[i];
            }
            return enums;
        },
        setProps = function (arr) {
            for (var i in arr) {
                if (!arr.hasOwnProperty(i)) continue;

                var propName = arr[i];
                if (typeof propName == TYPEOF.OBJECT && propName.length == 2) {
                    this[propName[0]] = propName[1];
                } else {
                    this[propName] = undefined;
                }
            }
            return this;
        };

    /////////////////
    // Factories
    ////////////////

    ((function () {
            var props = { init : {}, isIgnore : {}, isIgnoreRgx : {}, toString : {}};
            setProps.call(props.init, [
                [BROWSER, [NAME, VERSION, MAJOR, TYPE]],
                [CPU, [ARCHITECTURE]],
                [DEVICE, [TYPE, MODEL, VENDOR]],
                [ENGINE, [NAME, VERSION]],
                [OS, [NAME, VERSION]]
            ]);
            setProps.call(props.isIgnore, [
                [BROWSER, [VERSION, MAJOR]],
                [ENGINE, [VERSION]],
                [OS, [VERSION]]
            ]);
            setProps.call(props.isIgnoreRgx, [
                [BROWSER, / ?browser$/i],
                [OS, / ?os$/i]
            ]);
            setProps.call(props.toString, [
                [BROWSER, [NAME, VERSION]],
                [CPU, [ARCHITECTURE]],
                [DEVICE, [VENDOR, MODEL]],
                [ENGINE, [NAME, VERSION]],
                [OS, [NAME, VERSION]]
            ]);
            return props;
    }))();
    enumerize([NAME, VERSION, MAJOR, TYPE]);
    enumerize([ARCHITECTURE]);
    enumerize([MODEL, VENDOR, TYPE, CONSOLE, MOBILE, SMARTTV, TABLET, WEARABLE, EMBEDDED]);
    enumerize([NAME, VERSION]);

var __defProp = Object.defineProperty;
var __decorateClass = (decorators, target, key, kind) => {
  var result = void 0 ;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (decorator(target, key, result) ) || result;
  if (result) __defProp(target, key, result);
  return result;
};

function withTheme(Base) {
  class Mixin extends Base {
    constructor() {
      super(...arguments);
      this.theme = "light";
      this.isDark = false;
      this.mediaQueryList = null;
      /**
       * Handle system theme changes
       *
       * @param event - Media query list event
       */
      this.handleMediaQueryChange = (event) => {
        this.isDark = event.matches;
      };
    }
    connectedCallback() {
      super.connectedCallback();
      this.updateTheme();
      this.updateHostClass();
      if (this.theme === "auto") {
        this.mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");
        this.mediaQueryList.addEventListener(
          "change",
          this.handleMediaQueryChange
        );
      }
    }
    disconnectedCallback() {
      super.disconnectedCallback();
      if (this.mediaQueryList) {
        this.mediaQueryList.removeEventListener(
          "change",
          this.handleMediaQueryChange
        );
      }
    }
    updated(changedProperties) {
      super.updated(changedProperties);
      if (changedProperties.has("theme")) {
        this.updateTheme();
        if (this.theme === "auto" && !this.mediaQueryList) {
          this.mediaQueryList = window.matchMedia(
            "(prefers-color-scheme: dark)"
          );
          this.mediaQueryList.addEventListener(
            "change",
            this.handleMediaQueryChange
          );
        } else if (this.theme !== "auto" && this.mediaQueryList) {
          this.mediaQueryList.removeEventListener(
            "change",
            this.handleMediaQueryChange
          );
          this.mediaQueryList = null;
        }
      }
      if (changedProperties.has("isDark")) {
        this.updateHostClass();
      }
    }
    /**
     * Update isDark state based on theme property
     */
    updateTheme() {
      if (this.theme === "auto") {
        this.isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
      } else {
        this.isDark = this.theme === "dark";
      }
    }
    /**
     * Create the render root with a themed wrapper div
     */
    createRenderRoot() {
      const root = super.createRenderRoot();
      this.themeRoot = document.createElement("div");
      this.themeRoot.setAttribute("data-theme-root", "");
      root.appendChild(this.themeRoot);
      return this.themeRoot;
    }
    /**
     * Update the host element's class based on isDark state
     */
    updateHostClass() {
      if (this.isDark) {
        this.themeRoot.classList.add("dark");
      } else {
        this.themeRoot.classList.remove("dark");
      }
    }
  }
  __decorateClass([
    n({ type: String, reflect: true })
  ], Mixin.prototype, "theme");
  __decorateClass([
    r()
  ], Mixin.prototype, "isDark");
  return Mixin;
}

export { withTheme as w };
