/*
 * Copyright (c) 2024-2026 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* THIS IS AUTOGENERATED FILE, PLEASE DON`T CHANGE IT MANUALLY */
let arkThemeApiTargetVersion = undefined;
function getArkThemeApiTargetVersion() {
    if (arkThemeApiTargetVersion === undefined) {
        arkThemeApiTargetVersion = getUINativeModule().common.getApiTargetVersion();
    }
    return arkThemeApiTargetVersion;
}
class ArkResourcesHelper {
    static $r(name, id) {
        let splitted = name.split('.', 2);
        let strType = splitted[1];
        let type = undefined;
        switch (strType) {
            case 'float':
                type = ArkResourcesHelper.FLOAT;
                break;
            case 'color':
            default:
                type = ArkResourcesHelper.COLOR;
                break;
        }
        return { 'id': id !== null && id !== void 0 ? id : -1, 'type': type, 'params': [name], 'bundleName': '', 'moduleName': '' };
    }
}
ArkResourcesHelper.COLOR = 10001;
ArkResourcesHelper.FLOAT = 10002;
class ArkThemeNativeHelper {
    static sendThemeToNative(theme, elmtId, darkSetStatus) {
        const lightColorArray = ArkThemeNativeHelper.convertColorsToArray(theme.colors);
        const darkColorArray = ArkThemeNativeHelper.convertColorsToArray(theme.darkColors);
        WithTheme.sendThemeToNative(lightColorArray, darkColorArray, elmtId, darkSetStatus);
    }
    static createInternal(themeScopeId, themeId, theme, colorMode, onThemeScopeDestroy, darkSetStatus) {
        if (colorMode && colorMode !== ThemeColorMode.SYSTEM) {
            ArkThemeScopeManager.getInstance().onEnterLocalColorMode(colorMode);
        }
        const lightColorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.colors);
        const darkColorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.darkColors);
        getUINativeModule().theme.createAndBindTheme(themeScopeId, themeId, lightColorArray, darkColorArray, colorMode, onThemeScopeDestroy, darkSetStatus );
        if (colorMode && colorMode !== ThemeColorMode.SYSTEM) {
            ArkThemeScopeManager.getInstance().onExitLocalColorMode();
        }
    }
    static setDefaultTheme(theme) {
        const colorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.colors);
        let darkColorArray = [];
        if(!!theme?.darkColors) {
            darkColorArray = ArkThemeNativeHelper.convertColorsToArray(theme === null || theme === void 0 ? void 0 : theme.darkColors);
        }else {
            darkColorArray = colorArray;
        }
        
        ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.LIGHT);
        getUINativeModule().theme.setDefaultTheme(colorArray, false);
        ArkThemeScopeManager.getInstance().onExitLocalColorMode();

        ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.DARK);
        getUINativeModule().theme.setDefaultTheme(darkColorArray, true);
        ArkThemeScopeManager.getInstance().onExitLocalColorMode();
    }
    static convertThemeToColorArray(theme) {
        return [
            theme.colors.brand,
            theme.colors.warning,
            theme.colors.alert,
            theme.colors.confirm,
            theme.colors.fontPrimary,
            theme.colors.fontSecondary,
            theme.colors.fontTertiary,
            theme.colors.fontFourth,
            theme.colors.fontEmphasize,
            theme.colors.fontOnPrimary,
            theme.colors.fontOnSecondary,
            theme.colors.fontOnTertiary,
            theme.colors.fontOnFourth,
            theme.colors.iconPrimary,
            theme.colors.iconSecondary,
            theme.colors.iconTertiary,
            theme.colors.iconFourth,
            theme.colors.iconEmphasize,
            theme.colors.iconSubEmphasize,
            theme.colors.iconOnPrimary,
            theme.colors.iconOnSecondary,
            theme.colors.iconOnTertiary,
            theme.colors.iconOnFourth,
            theme.colors.backgroundPrimary,
            theme.colors.backgroundSecondary,
            theme.colors.backgroundTertiary,
            theme.colors.backgroundFourth,
            theme.colors.backgroundEmphasize,
            theme.colors.compForegroundPrimary,
            theme.colors.compBackgroundPrimary,
            theme.colors.compBackgroundPrimaryTran,
            theme.colors.compBackgroundPrimaryContrary,
            theme.colors.compBackgroundGray,
            theme.colors.compBackgroundSecondary,
            theme.colors.compBackgroundTertiary,
            theme.colors.compBackgroundEmphasize,
            theme.colors.compBackgroundNeutral,
            theme.colors.compEmphasizeSecondary,
            theme.colors.compEmphasizeTertiary,
            theme.colors.compDivider,
            theme.colors.compCommonContrary,
            theme.colors.compBackgroundFocus,
            theme.colors.compFocusedPrimary,
            theme.colors.compFocusedSecondary,
            theme.colors.compFocusedTertiary,
            theme.colors.interactiveHover,
            theme.colors.interactivePressed,
            theme.colors.interactiveFocus,
            theme.colors.interactiveActive,
            theme.colors.interactiveSelect,
            theme.colors.interactiveClick,
            theme.colors.primary,
            theme.colors.onPrimary,
            theme.colors.container,
        ];
    }
    static convertColorsToArray(colors) {
        const basisColors = ArkThemeScopeManager.getSystemColors();
        if (!colors) {
            return new Array(Object.keys(basisColors).length).fill(undefined);
        }
        const colorArray = [];
        for (let attr in basisColors) {
            colorArray.push(colors[attr]);
        }
        return colorArray;
    }
}
globalThis.LazyForEach.getItemGeneratorForThemeSupport = function (paramItemGenerator) {
    const themeScope = ArkThemeScopeManager.getInstance().lastLocalThemeScope();
    if (themeScope === undefined) {
        return paramItemGenerator;
    }
    const itemGeneratorWrapper = (...params) => {
        const result = ArkThemeScopeManager.getInstance().onDeepRenderScopeEnter(themeScope);
        paramItemGenerator(...params);
        if (result === true) {
            ArkThemeScopeManager.getInstance().onDeepRenderScopeExit();
        }
    };
    return itemGeneratorWrapper;
};
if (globalThis.WithTheme !== undefined) {
    globalThis.ListItem.getDeepRenderFuncForThemeSupport = function (deepRenderFunction) {
        let themeScope = ArkThemeScopeManager.getInstance().lastLocalThemeScope();
        if (themeScope === undefined) {
            const listItemElemtId = ViewStackProcessor.GetElmtIdToAccountFor();
            themeScope = ArkThemeScopeManager.getInstance().scopeForElmtId(listItemElemtId);
        }
        if (themeScope === undefined) {
            return deepRenderFunction;
        }
        const deepRenderFunctionWrapper = (elmtId, isInitialRender) => {
            const result = ArkThemeScopeManager.getInstance().onDeepRenderScopeEnter(themeScope);
            deepRenderFunction(elmtId, isInitialRender);
            if (result === true) {
                ArkThemeScopeManager.getInstance().onDeepRenderScopeExit();
            }
        };
        return deepRenderFunctionWrapper;
    };
}
class ArkThemeCache {
    constructor() {
        this.cache = [];
    }
    static getInstance() {
        if (!ArkThemeCache.instance) {
            ArkThemeCache.instance = new ArkThemeCache();
        }
        return ArkThemeCache.instance;
    }
    add(theme) {
        if (this.contains(theme)) {
            return;
        }
        this.cache.push(theme);
    }
    remove(theme) {
        const index = this.cache.indexOf(theme);
        if (index === -1) {
            return;
        }
        this.cache.splice(index, 1);
        getUINativeModule().theme.removeFromCache(theme.id);
    }
    get(baselineThemeId, customTheme, colorMode) {
        return this.cache.find((item) => {
            return item.getParentThemeId() === baselineThemeId &&
                item.getColorMode() === colorMode &&
                this.isEqualsCustomThemes(item.getCustomTheme(), customTheme);
        });
    }
    contains(theme) {
        return this.containsByAttributes(theme.getParentThemeId(), theme.getCustomTheme(), theme.getColorMode());
    }
    containsByAttributes(baselineThemeId, customTheme, colorMode) {
        return this.get(baselineThemeId, customTheme, colorMode) !== undefined;
    }
    isEqualsCustomThemes(theme1, theme2) {
        if (theme1 === theme2) {
            return true;
        }
        if (!theme1 || !theme2) {
            return false;
        }
        if (theme1.colors === theme2.colors && theme1.darkColors === theme2.darkColors) {
            return true;
        }
        if (!theme1.colors || !theme2.colors || !theme1.darkColors || !theme2.darkColors) {
            return false;
        }
        let keys1 = Object.keys(theme1.colors);
        let keys2 = Object.keys(theme2.colors);
        let darkKeys1 = Object.keys(theme1.darkColors);
        let darkKeys2 = Object.keys(theme2.darkColors);
        if (keys1.length !== keys2.length || darkKeys1.length !== darkKeys2.length) {
            return false;
        }
        for (let key of keys1) {
            if (!keys2.includes(key)) {
                return false;
            }
            let value1 = theme1.colors[key];
            let value2 = theme2.colors[key];
            if (value1 !== value2) {
                return false;
            }
        }
        for (let key of darkKeys1) {
            if (!darkKeys2.includes(key)) {
                return false;
            }
            let value1 = theme1.darkColors[key];
            let value2 = theme2.darkColors[key];
            if (value1 !== value2) {
                return false;
            }
        }
        return true;
    }
}
let themeCounter = 0;
class ArkThemeBase {
    constructor(parentId, customTheme, colorMode, colors, darkColors, shapes, typography) {
        this.scopesCounter = 0;
        this.bindedThemeScopesIds = [];
        this.isJustCreated = true;
        this.parentThemeId = -1;
        this.id = themeCounter++;
        this.parentThemeId = parentId;
        this.customTheme = ArkThemeBase.copyCustomTheme(customTheme);
        this.colorMode = colorMode;
        this.colors = colors;
        this.darkColors = darkColors;
        this.shapes = shapes;
        this.typography = typography;
    }
    bindToScope(themeScopeId) {
        if (this.bindedThemeScopesIds.includes(themeScopeId)) {
            return;
        }
        this.scopesCounter++;
        this.bindedThemeScopesIds.push(themeScopeId);
        if (this.isJustCreated) {
            ArkThemeCache.getInstance().add(this);
            this.isJustCreated = false;
        }
    }
    unbindFromScope(themeScopeId) {
        const index = this.bindedThemeScopesIds.indexOf(themeScopeId);
        if (index === -1) {
            return;
        }
        this.scopesCounter--;
        this.bindedThemeScopesIds.splice(index, 1);
        if (this.canBeDestroyed()) {
            ArkThemeCache.getInstance().remove(this);
        }
    }
    canBeDestroyed() {
        return !this.isJustCreated && this.scopesCounter === 0;
    }
    getParentThemeId() {
        return this.parentThemeId;
    }
    getCustomTheme() {
        return this.customTheme;
    }
    getColorMode() {
        return this.colorMode;
    }
    static copyCustomTheme(customTheme) {
        if (!customTheme) {
            return undefined;
        }
        const copyTheme = {};
        if (customTheme.colors) {
            copyTheme.colors = {};
            Object.assign(copyTheme.colors, customTheme.colors);
        }
        if (customTheme.darkColors) {
            copyTheme.darkColors = {};
            // For properties missing in darkColors, use the values from colors
            Object.assign(copyTheme.darkColors, customTheme?.colors, customTheme.darkColors);
        }
        
        if (customTheme.shapes) {
            copyTheme.shapes = {};
            Object.assign(copyTheme.shapes, customTheme.shapes);
        }
        if (customTheme.typography) {
            copyTheme.typography = {};
            Object.assign(copyTheme.typography, customTheme.typography);
        }
        return copyTheme;
    }
}
class ArkSystemColors {
    constructor() {
        this.brand = ArkResourcesHelper.$r('sys.color.brand', 125830976);
        this.warning = ArkResourcesHelper.$r('sys.color.warning', 125830979);
        this.alert = ArkResourcesHelper.$r('sys.color.alert', 125830980);
        this.confirm = ArkResourcesHelper.$r('sys.color.confirm', 125830981);
        this.fontPrimary = ArkResourcesHelper.$r('sys.color.font_primary', 125830982);
        this.fontSecondary = ArkResourcesHelper.$r('sys.color.font_secondary', 125830983);
        this.fontTertiary = ArkResourcesHelper.$r('sys.color.font_tertiary', 125830984);
        this.fontFourth = ArkResourcesHelper.$r('sys.color.font_fourth', 125830985);
        this.fontEmphasize = ArkResourcesHelper.$r('sys.color.font_emphasize', 125830986);
        this.fontOnPrimary = ArkResourcesHelper.$r('sys.color.font_on_primary', 125830987);
        this.fontOnSecondary = ArkResourcesHelper.$r('sys.color.font_on_secondary', 125830988);
        this.fontOnTertiary = ArkResourcesHelper.$r('sys.color.font_on_tertiary', 125830989);
        this.fontOnFourth = ArkResourcesHelper.$r('sys.color.font_on_fourth', 125830990);
        this.iconPrimary = ArkResourcesHelper.$r('sys.color.icon_primary', 125830991);
        this.iconSecondary = ArkResourcesHelper.$r('sys.color.icon_secondary', 125830992);
        this.iconTertiary = ArkResourcesHelper.$r('sys.color.icon_tertiary', 125830993);
        this.iconFourth = ArkResourcesHelper.$r('sys.color.icon_fourth', 125830994);
        this.iconEmphasize = ArkResourcesHelper.$r('sys.color.icon_emphasize', 125830995);
        this.iconSubEmphasize = ArkResourcesHelper.$r('sys.color.icon_sub_emphasize', 125830996);
        this.iconOnPrimary = ArkResourcesHelper.$r('sys.color.icon_on_primary', 125831057);
        this.iconOnSecondary = ArkResourcesHelper.$r('sys.color.icon_on_secondary', 125831058);
        this.iconOnTertiary = ArkResourcesHelper.$r('sys.color.icon_on_tertiary', 125831059);
        this.iconOnFourth = ArkResourcesHelper.$r('sys.color.icon_on_fourth', 125831060);
        this.backgroundPrimary = ArkResourcesHelper.$r('sys.color.background_primary', 125831061);
        this.backgroundSecondary = ArkResourcesHelper.$r('sys.color.background_secondary', 125831062);
        this.backgroundTertiary = ArkResourcesHelper.$r('sys.color.background_tertiary', 125831063);
        this.backgroundFourth = ArkResourcesHelper.$r('sys.color.background_fourth', 125831064);
        this.backgroundEmphasize = ArkResourcesHelper.$r('sys.color.background_emphasize', 125831065);
        this.compForegroundPrimary = ArkResourcesHelper.$r('sys.color.comp_foreground_primary', 125831003);
        this.compBackgroundPrimary = ArkResourcesHelper.$r('sys.color.comp_background_primary', 125831004);
        this.compBackgroundPrimaryTran = ArkResourcesHelper.$r('sys.color.comp_background_primary_tran');
        this.compBackgroundPrimaryContrary = ArkResourcesHelper.$r('sys.color.comp_background_primary_contrary', 125831005);
        this.compBackgroundGray = ArkResourcesHelper.$r('sys.color.comp_background_gray', 125831006);
        this.compBackgroundSecondary = ArkResourcesHelper.$r('sys.color.comp_background_secondary', 125831007);
        this.compBackgroundTertiary = ArkResourcesHelper.$r('sys.color.comp_background_tertiary', 125831008);
        this.compBackgroundEmphasize = ArkResourcesHelper.$r('sys.color.comp_background_emphasize', 125831009);
        this.compBackgroundNeutral = ArkResourcesHelper.$r('sys.color.neutral', 125831066);
        this.compEmphasizeSecondary = ArkResourcesHelper.$r('sys.color.comp_emphasize_secondary', 125831011);
        this.compEmphasizeTertiary = ArkResourcesHelper.$r('sys.color.comp_emphasize_tertiary', 125831012);
        this.compDivider = ArkResourcesHelper.$r('sys.color.comp_divider', 125831013);
        this.compCommonContrary = ArkResourcesHelper.$r('sys.color.comp_common_contrary', 125831014);
        this.compBackgroundFocus = ArkResourcesHelper.$r('sys.color.comp_background_focus', 125831015);
        this.compFocusedPrimary = ArkResourcesHelper.$r('sys.color.comp_focused_primary', 125831016);
        this.compFocusedSecondary = ArkResourcesHelper.$r('sys.color.comp_focused_secondary', 125831017);
        this.compFocusedTertiary = ArkResourcesHelper.$r('sys.color.comp_focused_tertiary', 125831018);
        this.interactiveHover = ArkResourcesHelper.$r('sys.color.interactive_hover', 125831019);
        this.interactivePressed = ArkResourcesHelper.$r('sys.color.interactive_pressed', 125831020);
        this.interactiveFocus = ArkResourcesHelper.$r('sys.color.interactive_focus', 125831021);
        this.interactiveActive = ArkResourcesHelper.$r('sys.color.interactive_active', 125831022);
        this.interactiveSelect = ArkResourcesHelper.$r('sys.color.interactive_select', 125831023);
        this.interactiveClick = ArkResourcesHelper.$r('sys.color.interactive_click', 125831024);
        this.primary = ArkResourcesHelper.$r('sys.color.primary', 125836896);
        this.onPrimary = ArkResourcesHelper.$r('sys.color.on_primary', 125836897);
        this.container = ArkResourcesHelper.$r('sys.color.container', 125836898);
    }
}
class ArkSystemCornerRadius {
    constructor() {
        this.none = ArkResourcesHelper.$r('sys.float.corner_radius_none');
        this.level1 = ArkResourcesHelper.$r('sys.float.corner_radius_level1');
        this.level2 = ArkResourcesHelper.$r('sys.float.corner_radius_level2');
        this.level3 = ArkResourcesHelper.$r('sys.float.corner_radius_level3');
        this.level4 = ArkResourcesHelper.$r('sys.float.corner_radius_level4');
        this.level5 = ArkResourcesHelper.$r('sys.float.corner_radius_level5');
        this.level6 = ArkResourcesHelper.$r('sys.float.corner_radius_level6');
        this.level7 = ArkResourcesHelper.$r('sys.float.corner_radius_level7');
        this.level8 = ArkResourcesHelper.$r('sys.float.corner_radius_level8');
        this.level9 = ArkResourcesHelper.$r('sys.float.corner_radius_level9');
        this.level10 = ArkResourcesHelper.$r('sys.float.corner_radius_level10');
        this.level11 = ArkResourcesHelper.$r('sys.float.corner_radius_level11');
        this.level12 = ArkResourcesHelper.$r('sys.float.corner_radius_level12');
        this.level16 = ArkResourcesHelper.$r('sys.float.corner_radius_level16');
    }
}
class ArkSystemPaddings {
    constructor() {
        this.level0 = ArkResourcesHelper.$r('sys.float.padding_level0');
        this.level1 = ArkResourcesHelper.$r('sys.float.padding_level1');
        this.level2 = ArkResourcesHelper.$r('sys.float.padding_level2');
        this.level3 = ArkResourcesHelper.$r('sys.float.padding_level3');
        this.level4 = ArkResourcesHelper.$r('sys.float.padding_level4');
        this.level5 = ArkResourcesHelper.$r('sys.float.padding_level5');
        this.level6 = ArkResourcesHelper.$r('sys.float.padding_level6');
        this.level7 = ArkResourcesHelper.$r('sys.float.padding_level7');
        this.level8 = ArkResourcesHelper.$r('sys.float.padding_level8');
        this.level9 = ArkResourcesHelper.$r('sys.float.padding_level9');
        this.level10 = ArkResourcesHelper.$r('sys.float.padding_level10');
        this.level11 = ArkResourcesHelper.$r('sys.float.padding_level11');
        this.level12 = ArkResourcesHelper.$r('sys.float.padding_level12');
        this.level16 = ArkResourcesHelper.$r('sys.float.padding_level16');
        this.level24 = ArkResourcesHelper.$r('sys.float.padding_level24');
        this.level32 = ArkResourcesHelper.$r('sys.float.padding_level32');
        this.level36 = ArkResourcesHelper.$r('sys.float.padding_level36');
    }
}
class ArkSystemOutlines {
    constructor() {
        this.none = ArkResourcesHelper.$r('sys.float.outline_none');
        this.xs = ArkResourcesHelper.$r('sys.float.outline_extra_small');
        this.s = ArkResourcesHelper.$r('sys.float.outline_small');
        this.m = ArkResourcesHelper.$r('sys.float.outline_medium');
        this.l = ArkResourcesHelper.$r('sys.float.outline_larger');
        this.xl = ArkResourcesHelper.$r('sys.float.outline_extra_larger');
    }
}
class ArkSystemBorders {
    constructor() {
        this.none = ArkResourcesHelper.$r('sys.float.border_none');
        this.xs = ArkResourcesHelper.$r('sys.float.border_extra_small');
        this.s = ArkResourcesHelper.$r('sys.float.border_small');
        this.m = ArkResourcesHelper.$r('sys.float.border_medium');
        this.l = ArkResourcesHelper.$r('sys.float.border_larger');
        this.xl = ArkResourcesHelper.$r('sys.float.border_extra_larger');
    }
}
class ArkSystemShapes {
    constructor() {
        this.cornerRadius = new ArkSystemCornerRadius();
        this.paddings = new ArkSystemPaddings();
        this.borders = new ArkSystemBorders();
        this.outlines = new ArkSystemOutlines();
    }
}
class ArkTypographyWeights {
}
ArkTypographyWeights.thin = 100;
ArkTypographyWeights.ultralight = 200;
ArkTypographyWeights.light = 300;
ArkTypographyWeights.regular = 400;
ArkTypographyWeights.medium = 500;
ArkTypographyWeights.semibold = 600;
ArkTypographyWeights.bold = 700;
ArkTypographyWeights.heavy = 800;
ArkTypographyWeights.black = 900;
class ArkSystemTypography {
    constructor() {
        this.displayLarge = {
            weight: ArkTypographyWeights.light,
            size: ArkResourcesHelper.$r('sys.float.Display_L')
        };
        this.displayMiddle = {
            weight: ArkTypographyWeights.light,
            size: ArkResourcesHelper.$r('sys.float.Display_M')
        };
        this.displaySmall = {
            weight: ArkTypographyWeights.light,
            size: ArkResourcesHelper.$r('sys.float.Display_S')
        };
        this.titleLarge = {
            weight: ArkTypographyWeights.bold,
            size: ArkResourcesHelper.$r('sys.float.Title_L')
        };
        this.titleMiddle = {
            weight: ArkTypographyWeights.bold,
            size: ArkResourcesHelper.$r('sys.float.Title_M')
        };
        this.titleSmall = {
            weight: ArkTypographyWeights.bold,
            size: ArkResourcesHelper.$r('sys.float.Title_S')
        };
        this.subtitleLarge = {
            weight: ArkTypographyWeights.medium,
            size: ArkResourcesHelper.$r('sys.float.Subtitle_L')
        };
        this.subtitleMiddle = {
            weight: ArkTypographyWeights.medium,
            size: ArkResourcesHelper.$r('sys.float.Subtitle_M')
        };
        this.subtitleSmall = {
            weight: ArkTypographyWeights.medium,
            size: ArkResourcesHelper.$r('sys.float.Subtitle_S')
        };
        this.bodyLarge = {
            weight: ArkTypographyWeights.medium,
            size: ArkResourcesHelper.$r('sys.float.Body_L')
        };
        this.bodyMiddle = {
            weight: ArkTypographyWeights.regular,
            size: ArkResourcesHelper.$r('sys.float.Body_M')
        };
        this.bodySmall = {
            weight: ArkTypographyWeights.regular,
            size: ArkResourcesHelper.$r('sys.float.Body_S')
        };
        this.captionLarge = {
            weight: ArkTypographyWeights.medium,
            size: ArkResourcesHelper.$r('sys.float.Caption_L')
        };
        this.captionMiddle = {
            weight: ArkTypographyWeights.medium,
            size: ArkResourcesHelper.$r('sys.float.Caption_M')
        };
        this.captionSmall = {
            weight: ArkTypographyWeights.medium,
            size: ArkResourcesHelper.$r('sys.float.Caption_S')
        };
    }
}
class ArkSystemTheme extends ArkThemeBase {
    constructor() {
        super(-1, undefined, ThemeColorMode.SYSTEM, new ArkSystemColors(), new ArkSystemColors(), new ArkSystemShapes(), new ArkSystemTypography());
    }
}
if (globalThis.WithTheme !== undefined) {
    globalThis.WithTheme.create = function (themeOptions) {
        var _a;
        const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
        const colorMode = (_a = themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.colorMode) !== null && _a !== void 0 ? _a : ThemeColorMode.SYSTEM;
        const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.theme);
        const theme = ArkThemeScopeManager.getInstance().makeTheme(cloneTheme, colorMode);
        theme.bindToScope(elmtId);
        const onThemeScopeDestroy = () => {
            ArkThemeScopeManager.getInstance().onScopeDestroy(elmtId);
        };
        ArkThemeNativeHelper.sendThemeToNative(theme, elmtId, !!cloneTheme?.darkColors);
        ArkThemeNativeHelper.createInternal(elmtId, theme.id, cloneTheme, colorMode, onThemeScopeDestroy, !!cloneTheme?.darkColors);
        ArkThemeScopeManager.getInstance().onScopeEnter(elmtId, themeOptions !== null && themeOptions !== void 0 ? themeOptions : {}, theme);
    };
    globalThis.WithTheme.pop = function () {
        var _a;
        if (PUV2ViewBase.isNeedBuildPrebuildCmd() && PUV2ViewBase.prebuildFuncQueues.has(PUV2ViewBase.prebuildingElmtId_)) {
            const prebuildFunc = () => {
                ArkThemeScopeManager.getInstance().setIsFirstRender(true);
                globalThis.WithTheme.pop();
            };
            (_a = PUV2ViewBase.prebuildFuncQueues.get(PUV2ViewBase.prebuildingElmtId_)) === null || _a === void 0 ? void 0 : _a.push(prebuildFunc);
            ViewStackProcessor.PushPrebuildCompCmd();
            return;
        }
        ArkThemeScopeManager.getInstance().onScopeExit();
        getUINativeModule().theme.pop();
    };
}
class ArkColorsImpl {
    constructor(colors, baselineColors) {
        Object.assign(this, baselineColors, colors);
    }
    static expandByBrandColor(colors, isDark = false) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
        if (colors.brand) {
            const brandColors = ArkColorsImpl.makeBrandColors(colors.brand);
            colors.fontEmphasize = (_a = colors.fontEmphasize) !== null && _a !== void 0 ? _a : brandColors.primary;
            colors.iconEmphasize = (_b = colors.iconEmphasize) !== null && _b !== void 0 ? _b : brandColors.primary;
            colors.iconSubEmphasize = (_c = colors.iconSubEmphasize) !== null && _c !== void 0 ? _c : brandColors.tertiary;
            colors.backgroundEmphasize = (_d = colors.backgroundEmphasize) !== null && _d !== void 0 ? _d : brandColors.primary;
            colors.compBackgroundEmphasize = (_e = colors.compBackgroundEmphasize) !== null && _e !== void 0 ? _e : brandColors.primary;
            colors.compEmphasizeSecondary = (_f = colors.compEmphasizeSecondary) !== null && _f !== void 0 ? _f : brandColors.fourth;
            colors.compEmphasizeTertiary = (_g = colors.compEmphasizeTertiary) !== null && _g !== void 0 ? _g : brandColors.fifth;
            colors.interactiveFocus = (_h = colors.interactiveFocus) !== null && _h !== void 0 ? _h : brandColors.primary;
            colors.interactiveActive = (_j = colors.interactiveActive) !== null && _j !== void 0 ? _j : brandColors.primary;
        }
        if (colors.primary) {
            colors.fontPrimary = (_k = colors.fontPrimary) !== null && _k !== void 0 ? _k : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.9);
            colors.fontSecondary = (_l = colors.fontSecondary) !== null && _l !== void 0 ? _l : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.6);
            colors.fontTertiary = (_m = colors.fontTertiary) !== null && _m !== void 0 ? _m : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.4);
            colors.fontFourth = (_o = colors.fontFourth) !== null && _o !== void 0 ? _o : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.2);
            colors.iconPrimary = (_p = colors.iconPrimary) !== null && _p !== void 0 ? _p : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.9);
            colors.iconSecondary = (_q = colors.iconSecondary) !== null && _q !== void 0 ? _q : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.6);
            colors.iconTertiary = (_r = colors.iconTertiary) !== null && _r !== void 0 ? _r : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.4);
            colors.iconFourth = (_s = colors.iconFourth) !== null && _s !== void 0 ? _s : ArkColorsImpl.makeColorWithOpacity(colors.primary, 0.2);
        }
        if (colors.onPrimary) {
            colors.fontOnPrimary = (_t = colors.fontOnPrimary) !== null && _t !== void 0 ? _t : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 1.0);
            colors.fontOnSecondary = (_u = colors.fontOnSecondary) !== null && _u !== void 0 ? _u : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 0.6);
            colors.fontOnTertiary = (_v = colors.fontOnTertiary) !== null && _v !== void 0 ? _v : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 0.4);
            colors.fontOnFourth = (_w = colors.fontOnFourth) !== null && _w !== void 0 ? _w : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 0.2);
            colors.iconOnPrimary = (_x = colors.iconOnPrimary) !== null && _x !== void 0 ? _x : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 1.0);
            colors.iconOnSecondary = (_y = colors.iconOnSecondary) !== null && _y !== void 0 ? _y : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 0.6);
            colors.iconOnTertiary = (_z = colors.iconOnTertiary) !== null && _z !== void 0 ? _z : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 0.4);
            colors.iconOnFourth = (_0 = colors.iconOnFourth) !== null && _0 !== void 0 ? _0 : ArkColorsImpl.makeColorWithOpacity(colors.onPrimary, 0.2);
        }
        if (colors.container) {
            colors.compBackgroundSecondary = (_1 = colors.compBackgroundSecondary) !== null && _1 !== void 0 ? _1 : ArkColorsImpl.makeColorWithOpacity(colors.container, 0.1);
            colors.compBackgroundTertiary = (_2 = colors.compBackgroundTertiary) !== null && _2 !== void 0 ? _2 : ArkColorsImpl.makeColorWithOpacity(colors.container, isDark ? 0.1 : 0.05);
            colors.compDivider = (_3 = colors.compDivider) !== null && _3 !== void 0 ? _3 : ArkColorsImpl.makeColorWithOpacity(colors.container, 0.2);
            colors.interactiveHover = (_4 = colors.interactiveHover) !== null && _4 !== void 0 ? _4 : ArkColorsImpl.makeColorWithOpacity(colors.container, isDark ? 0.1 : 0.05);
            colors.interactivePressed = (_5 = colors.interactivePressed) !== null && _5 !== void 0 ? _5 : ArkColorsImpl.makeColorWithOpacity(colors.container, isDark ? 0.15 : 0.1);
            colors.interactiveClick = (_6 = colors.interactiveClick) !== null && _6 !== void 0 ? _6 : ArkColorsImpl.makeColorWithOpacity(colors.container, isDark ? 0.15 : 0.1);
        }
    }
    static makeBrandColors(brandColor) {
        const result = {
            primary: undefined,
            secondary: undefined,
            tertiary: undefined,
            fourth: undefined,
            fifth: undefined,
            sixth: undefined
        };
        if (brandColor) {
            if (brandColor instanceof Object) {
                result.primary = brandColor;
                result.secondary = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.6);
                result.tertiary = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.4);
                result.fourth = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.2);
                result.fifth = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.1);
                result.sixth = ArkColorsImpl.makeResourceWithOpacity(brandColor, 0.05);
            }
            else {
                const argbColor = getUINativeModule().resource.getColorValue(brandColor);
                result.primary = argbColor;
                result.secondary = ArkColorsImpl.blendOpacity(argbColor, 0.6);
                result.tertiary = ArkColorsImpl.blendOpacity(argbColor, 0.4);
                result.fourth = ArkColorsImpl.blendOpacity(argbColor, 0.2);
                result.fifth = ArkColorsImpl.blendOpacity(argbColor, 0.1);
                result.sixth = ArkColorsImpl.blendOpacity(argbColor, 0.05);
            }
        }
        return result;
    }
    static makeResourceWithOpacity(resourceColor, opacityRatio) {
        return {
            'id': resourceColor.id,
            'type': resourceColor.type,
            'params': [...resourceColor.params],
            'bundleName': resourceColor.bundleName,
            'moduleName': resourceColor.moduleName,
            'opacityRatio': opacityRatio
        };
    }
    static makeColorWithOpacity(color, opacityRatio) {
        if (!color) {
            return undefined;
        }
        if (opacityRatio >= 1.0) {
            return color;
        }
        if (color instanceof Object) {
            return ArkColorsImpl.makeResourceWithOpacity(color, opacityRatio);
        }
        const argbColor = getUINativeModule().resource.getColorValue(color);
        return ArkColorsImpl.blendOpacity(argbColor, opacityRatio);
    }
    static blendOpacity(argbColor, opacityRatio) {
        if (opacityRatio < 0 || opacityRatio > 1.0) {
            return argbColor;
        }
        const alpha = (argbColor >> 24) & 0xFF;
        const outAlpha = (alpha * opacityRatio) & 0xFF;
        return ((argbColor & 0x00FFFFFF) | (outAlpha & 0xFF) << 24) >>> 0;
    }
}
class ArkCornerRadiusImpl {
    constructor(corners, baselineCorners) {
        Object.assign(this, baselineCorners, corners);
    }
}
class ArkPaddingsImpl {
    constructor(paddings, baselinePaddings) {
        Object.assign(this, baselinePaddings, paddings);
    }
}
class ArkOutlinesImpl {
    constructor(outlines = {}, baselineOutlines) {
        Object.assign(this, baselineOutlines, outlines);
    }
}
class ArkBordersImpl {
    constructor(borders = {}, baselineBorders) {
        Object.assign(this, baselineBorders, borders);
    }
}
class ArkShapesImpl {
    constructor(shapes, baselineShapes) {
        this.cornerRadius = new ArkCornerRadiusImpl(shapes === null || shapes === void 0 ? void 0 : shapes.cornerRadius, baselineShapes.cornerRadius);
        this.paddings = new ArkPaddingsImpl(shapes === null || shapes === void 0 ? void 0 : shapes.paddings, baselineShapes.paddings);
        this.borders = new ArkBordersImpl(shapes === null || shapes === void 0 ? void 0 : shapes.borders, baselineShapes.borders);
        this.outlines = new ArkOutlinesImpl(shapes === null || shapes === void 0 ? void 0 : shapes.outlines, baselineShapes.outlines);
    }
}
class ArkTypographyImpl {
    constructor(typography, baselineTypography) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35;
        this.displayLarge = {
            weight: (_b = (_a = typography === null || typography === void 0 ? void 0 : typography.displayLarge) === null || _a === void 0 ? void 0 : _a.weight) !== null && _b !== void 0 ? _b : ArkTypographyWeights.light,
            size: (_d = (_c = typography === null || typography === void 0 ? void 0 : typography.displayLarge) === null || _c === void 0 ? void 0 : _c.size) !== null && _d !== void 0 ? _d : baselineTypography.displayLarge.size
        };
        this.displayMiddle = {
            weight: (_f = (_e = typography === null || typography === void 0 ? void 0 : typography.displayMiddle) === null || _e === void 0 ? void 0 : _e.weight) !== null && _f !== void 0 ? _f : ArkTypographyWeights.light,
            size: (_h = (_g = typography === null || typography === void 0 ? void 0 : typography.displayMiddle) === null || _g === void 0 ? void 0 : _g.size) !== null && _h !== void 0 ? _h : baselineTypography.displayMiddle.size
        };
        this.displaySmall = {
            weight: (_k = (_j = typography === null || typography === void 0 ? void 0 : typography.displaySmall) === null || _j === void 0 ? void 0 : _j.weight) !== null && _k !== void 0 ? _k : ArkTypographyWeights.light,
            size: (_m = (_l = typography === null || typography === void 0 ? void 0 : typography.displaySmall) === null || _l === void 0 ? void 0 : _l.size) !== null && _m !== void 0 ? _m : baselineTypography.displaySmall.size
        };
        this.titleLarge = {
            weight: (_p = (_o = typography === null || typography === void 0 ? void 0 : typography.titleLarge) === null || _o === void 0 ? void 0 : _o.weight) !== null && _p !== void 0 ? _p : ArkTypographyWeights.bold,
            size: (_r = (_q = typography === null || typography === void 0 ? void 0 : typography.titleLarge) === null || _q === void 0 ? void 0 : _q.size) !== null && _r !== void 0 ? _r : baselineTypography.titleLarge.size
        };
        this.titleMiddle = {
            weight: (_t = (_s = typography === null || typography === void 0 ? void 0 : typography.titleMiddle) === null || _s === void 0 ? void 0 : _s.weight) !== null && _t !== void 0 ? _t : ArkTypographyWeights.bold,
            size: (_v = (_u = typography === null || typography === void 0 ? void 0 : typography.titleMiddle) === null || _u === void 0 ? void 0 : _u.size) !== null && _v !== void 0 ? _v : baselineTypography.titleMiddle.size
        };
        this.titleSmall = {
            weight: (_x = (_w = typography === null || typography === void 0 ? void 0 : typography.titleSmall) === null || _w === void 0 ? void 0 : _w.weight) !== null && _x !== void 0 ? _x : ArkTypographyWeights.bold,
            size: (_z = (_y = typography === null || typography === void 0 ? void 0 : typography.titleSmall) === null || _y === void 0 ? void 0 : _y.size) !== null && _z !== void 0 ? _z : baselineTypography.titleSmall.size
        };
        this.subtitleLarge = {
            weight: (_1 = (_0 = typography === null || typography === void 0 ? void 0 : typography.subtitleLarge) === null || _0 === void 0 ? void 0 : _0.weight) !== null && _1 !== void 0 ? _1 : ArkTypographyWeights.medium,
            size: (_3 = (_2 = typography === null || typography === void 0 ? void 0 : typography.subtitleLarge) === null || _2 === void 0 ? void 0 : _2.size) !== null && _3 !== void 0 ? _3 : baselineTypography.subtitleLarge.size
        };
        this.subtitleMiddle = {
            weight: (_5 = (_4 = typography === null || typography === void 0 ? void 0 : typography.subtitleMiddle) === null || _4 === void 0 ? void 0 : _4.weight) !== null && _5 !== void 0 ? _5 : ArkTypographyWeights.medium,
            size: (_7 = (_6 = typography === null || typography === void 0 ? void 0 : typography.subtitleMiddle) === null || _6 === void 0 ? void 0 : _6.size) !== null && _7 !== void 0 ? _7 : baselineTypography.subtitleMiddle.size
        };
        this.subtitleSmall = {
            weight: (_9 = (_8 = typography === null || typography === void 0 ? void 0 : typography.subtitleSmall) === null || _8 === void 0 ? void 0 : _8.weight) !== null && _9 !== void 0 ? _9 : ArkTypographyWeights.medium,
            size: (_11 = (_10 = typography === null || typography === void 0 ? void 0 : typography.subtitleSmall) === null || _10 === void 0 ? void 0 : _10.size) !== null && _11 !== void 0 ? _11 : baselineTypography.subtitleSmall.size
        };
        this.bodyLarge = {
            weight: (_13 = (_12 = typography === null || typography === void 0 ? void 0 : typography.bodyLarge) === null || _12 === void 0 ? void 0 : _12.weight) !== null && _13 !== void 0 ? _13 : ArkTypographyWeights.medium,
            size: (_15 = (_14 = typography === null || typography === void 0 ? void 0 : typography.bodyLarge) === null || _14 === void 0 ? void 0 : _14.size) !== null && _15 !== void 0 ? _15 : baselineTypography.bodyLarge.size
        };
        this.bodyMiddle = {
            weight: (_17 = (_16 = typography === null || typography === void 0 ? void 0 : typography.bodyMiddle) === null || _16 === void 0 ? void 0 : _16.weight) !== null && _17 !== void 0 ? _17 : ArkTypographyWeights.regular,
            size: (_19 = (_18 = typography === null || typography === void 0 ? void 0 : typography.bodyMiddle) === null || _18 === void 0 ? void 0 : _18.size) !== null && _19 !== void 0 ? _19 : baselineTypography.bodyMiddle.size
        };
        this.bodySmall = {
            weight: (_21 = (_20 = typography === null || typography === void 0 ? void 0 : typography.bodySmall) === null || _20 === void 0 ? void 0 : _20.weight) !== null && _21 !== void 0 ? _21 : ArkTypographyWeights.regular,
            size: (_23 = (_22 = typography === null || typography === void 0 ? void 0 : typography.bodySmall) === null || _22 === void 0 ? void 0 : _22.size) !== null && _23 !== void 0 ? _23 : baselineTypography.bodySmall.size
        };
        this.captionLarge = {
            weight: (_25 = (_24 = typography === null || typography === void 0 ? void 0 : typography.captionLarge) === null || _24 === void 0 ? void 0 : _24.weight) !== null && _25 !== void 0 ? _25 : ArkTypographyWeights.medium,
            size: (_27 = (_26 = typography === null || typography === void 0 ? void 0 : typography.captionLarge) === null || _26 === void 0 ? void 0 : _26.size) !== null && _27 !== void 0 ? _27 : baselineTypography.captionLarge.size
        };
        this.captionMiddle = {
            weight: (_29 = (_28 = typography === null || typography === void 0 ? void 0 : typography.captionMiddle) === null || _28 === void 0 ? void 0 : _28.weight) !== null && _29 !== void 0 ? _29 : ArkTypographyWeights.medium,
            size: (_31 = (_30 = typography === null || typography === void 0 ? void 0 : typography.captionMiddle) === null || _30 === void 0 ? void 0 : _30.size) !== null && _31 !== void 0 ? _31 : baselineTypography.captionMiddle.size
        };
        this.captionSmall = {
            weight: (_33 = (_32 = typography === null || typography === void 0 ? void 0 : typography.captionSmall) === null || _32 === void 0 ? void 0 : _32.weight) !== null && _33 !== void 0 ? _33 : ArkTypographyWeights.medium,
            size: (_35 = (_34 = typography === null || typography === void 0 ? void 0 : typography.captionSmall) === null || _34 === void 0 ? void 0 : _34.size) !== null && _35 !== void 0 ? _35 : baselineTypography.captionSmall.size
        };
    }
}
class ArkThemeImpl extends ArkThemeBase {
    constructor(customTheme, colorMode, baselineTheme) {
        if (!customTheme) {
            super(baselineTheme.id, undefined, colorMode, new ArkColorsImpl(undefined, baselineTheme.colors), new ArkColorsImpl(undefined, baselineTheme.darkColors), new ArkShapesImpl(undefined, baselineTheme.shapes), new ArkTypographyImpl(undefined, baselineTheme.typography));
            return;
        }
        super(baselineTheme.id, customTheme, colorMode, new ArkColorsImpl(customTheme.colors, baselineTheme.colors), new ArkColorsImpl(customTheme.darkColors, baselineTheme.darkColors), new ArkShapesImpl(customTheme.shapes, baselineTheme.shapes), new ArkTypographyImpl(customTheme.typography, baselineTheme.typography));
    }
}
class ArkThemeScopeItem {
    constructor() {
        this.isInWhiteList = undefined;
        this.listener = undefined;
    }
}
class ArkThemeScopeArray extends Array {
    binarySearch(elmtId) {
        let start = 0;
        let end = this.length - 1;
        while (start <= end) {
            let mid = (start + end) >> 1;
            if (this[mid].elmtId === elmtId) {
                return mid;
            }
            if (elmtId < this[mid].elmtId) {
                end = mid - 1;
            }
            else {
                start = mid + 1;
            }
        }
        return -1;
    }
}
class ArkThemeScope {
    constructor(ownerComponentId, withThemeId, withThemeOptions, theme) {
        this.ownerComponentId = ownerComponentId;
        this.withThemeId = withThemeId;
        this.withThemeOptions = withThemeOptions;
        this.theme = theme;
        this.prevColorMode = this.colorMode();
    }
    getOwnerComponentId() {
        return this.ownerComponentId;
    }
    getWithThemeId() {
        return this.withThemeId;
    }
    addComponentToScope(elmtId, owner, componentName) {
        if (this.isComponentInScope(elmtId)) {
            return;
        }
        if (!this.components) {
            this.components = new Map();
        }
        this.components.set(elmtId, { elmtId: elmtId, ownerId: owner.id__(), owner: owner, name: componentName });
    }
    addCustomListenerInScope(listener) {
        const len = this.components ? this.components.size : -1;
        if (len <= 0) {
            return;
        }
        const listenerId = listener.id__();
        let themeScopeItem = this.components.get(listenerId);
        if (themeScopeItem) {
            themeScopeItem.listener = listener;
        }
    }
    removeComponentFromScope(elmtId) {
        if (this.components) {
            this.components.delete(elmtId);
        }
    }
    isComponentInScope(elmtId) {
        return this.components && (this.components.has(elmtId));
    }
    componentsInScope() {
        return this.components;
    }
    colorMode() {
        var _a;
        return (_a = this.withThemeOptions.colorMode) !== null && _a !== void 0 ? _a : ThemeColorMode.SYSTEM;
    }
    customTheme() {
        var _a;
        return (_a = this.withThemeOptions.theme) !== null && _a !== void 0 ? _a : {};
    }
    getTheme() {
        return this.theme;
    }
    options() {
        return this.withThemeOptions;
    }
    updateWithThemeOptions(options, theme) {
        var _a;
        this.prevColorMode = this.colorMode();
        this.withThemeOptions = options;
        if (this.theme !== theme) {
            (_a = this.theme) === null || _a === void 0 ? void 0 : _a.unbindFromScope(this.getWithThemeId());
            this.theme = theme;
        }
    }
    isColorModeChanged() {
        return this.prevColorMode !== this.colorMode();
    }
}
class ArkThemeScopeManager {
    constructor() {
        this.localThemeScopes = [];
        this.themeScopes = undefined;
        this.ifElseLastScope = undefined;
        this.ifElseScopes = [];
        this.lastThemeScopeId = 0;
        this.listeners = [];
        this.defaultTheme = undefined;
        this.themeIdStack = [];
    }
    onComponentCreateEnter(componentName, elmtId, isFirstRender, ownerComponent) {
        this.handledIsFirstRender = isFirstRender;
        this.handledOwnerComponentId = ownerComponent.id__();
        this.handledComponentElmtId = elmtId;
        if (!this.themeScopes || componentName === 'WithTheme') {
            return;
        }
        if (this.themeScopes.length === 0) {
            this.handleThemeScopeChange(undefined);
            return;
        }
        let scope = undefined;
        if (isFirstRender) {
            const currentLocalScope = this.localThemeScopes[this.localThemeScopes.length - 1];
            const currentIfElseScope = this.ifElseScopes[this.ifElseScopes.length - 1];
            if (currentLocalScope) {
                scope = currentLocalScope;
                scope.addComponentToScope(elmtId, ownerComponent, componentName);
            }
            else if (currentIfElseScope) {
                scope = currentIfElseScope;
                scope.addComponentToScope(elmtId, ownerComponent, componentName);
            }
            else {
                const parentScope = this.resolveParentScope(ownerComponent.themeScope_, this.themeScopes);
                if (parentScope) {
                    scope = parentScope;
                    scope.addComponentToScope(elmtId, ownerComponent, componentName);
                }
            }
        }
        if (scope === undefined) {
            scope = this.scopeForElmtId(elmtId);
        }
        if (scope === undefined && (this.themeIdStack.length > 0)) {
            scope = this.themeScopes.find(item => item.getWithThemeId() === this.themeIdStack[this.themeIdStack.length - 1]);
        }
        this.handledColorMode = scope === null || scope === void 0 ? void 0 : scope.colorMode();
        if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) {
            this.onEnterLocalColorMode(this.handledColorMode);
        }
        if (componentName === 'If') {
            this.ifElseLastScope = scope;
        }
        this.handledThemeScope = scope;
        this.handleThemeScopeChange(this.handledThemeScope);
        if (scope) {
            this.themeIdStack.push(scope.getWithThemeId());
        }
    }
    onComponentCreateExit(elmtId) {
        if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) {
            this.onExitLocalColorMode();
        }
        this.handledThemeScope = undefined;
        this.handledComponentElmtId = undefined;
        if (this.themeIdStack.length > 0) {
            this.themeIdStack.pop();
        }
    }
    onScopeEnter(withThemeId, withThemeOptions, theme) {
        this.lastThemeScopeId = withThemeId;
        if (this.handledIsFirstRender === true) {
            let themeScope = new ArkThemeScope(this.handledOwnerComponentId, withThemeId, withThemeOptions, theme);
            this.localThemeScopes.push(themeScope);
            if (!this.themeScopes) {
                this.themeScopes = new Array();
            }
            this.themeScopes.push(themeScope);
        }
        else {
            const scope = this.themeScopes.find(item => item.getWithThemeId() === withThemeId);
            scope === null || scope === void 0 ? void 0 : scope.updateWithThemeOptions(withThemeOptions, theme);
            this.forceRerenderScope(scope);
        }
    }
    onScopeExit() {
        if (this.handledIsFirstRender === true) {
            this.localThemeScopes.pop();
        }
    }
    onScopeDestroy(themeScopeId) {
        var _a;
        this.themeScopes = (_a = this.themeScopes) === null || _a === void 0 ? void 0 : _a.filter((scope) => {
            if (scope.getWithThemeId() === themeScopeId) {
                this.onScopeDestroyInternal(scope);
                return false;
            }
            return true;
        });
    }
    onScopeDestroyInternal(scope) {
        const theme = scope.getTheme();
        if (theme) {
            theme.unbindFromScope(scope.getWithThemeId());
        }
        const index = this.localThemeScopes.indexOf(scope);
        if (index !== -1) {
            this.localThemeScopes.splice(index, 1);
        }
        WithTheme.removeThemeInNative(scope.getWithThemeId());
    }
    onViewPUCreate(ownerComponent) {
        var _a;
        if (ownerComponent.parent_ === undefined) {
            this.subscribeListener(ownerComponent);
        }
        ownerComponent.themeScope_ = this.scopeForElmtId(ownerComponent.id__());
        (_a = ownerComponent.themeScope_) === null || _a === void 0 ? void 0 : _a.addCustomListenerInScope(ownerComponent);
    }
    onViewPUDelete(ownerComponent) {
        var _a;
        this.unsubscribeListener(ownerComponent);
        const ownerComponentId = ownerComponent.id__();
        this.themeScopes = (_a = this.themeScopes) === null || _a === void 0 ? void 0 : _a.filter((scope) => {
            if (scope.getOwnerComponentId() === ownerComponentId) {
                this.onScopeDestroyInternal(scope);
                return false;
            }
            return true;
        });
    }
    onIfElseBranchUpdateEnter() {
        this.ifElseScopes.push(this.ifElseLastScope);
    }
    onIfElseBranchUpdateExit(removedElmtIds) {
        const scope = this.ifElseScopes.pop();
        if (removedElmtIds && scope) {
            removedElmtIds.forEach(elmtId => scope.removeComponentFromScope(elmtId));
        }
    }
    onDeepRenderScopeEnter(themeScope) {
        if (themeScope) {
            this.localThemeScopes.push(themeScope);
            return true;
        }
        return false;
    }
    onDeepRenderScopeExit() {
        this.localThemeScopes.pop();
    }
    subscribeListener(listener) {
        if (this.listeners.includes(listener)) {
            return;
        }
        this.listeners.push(listener);
    }
    unsubscribeListener(listener) {
        const index = this.listeners.indexOf(listener, 0);
        if (index > -1) {
            this.listeners.splice(index, 1);
        }
        const scope = listener.themeScope_;
        if (scope) {
            scope.removeComponentFromScope(listener.id__());
            listener.themeScope_ = undefined;
        }
    }
    getFinalTheme(ownerComponent) {
        var _a, _b, _c;
        return (_c = (_b = (_a = ownerComponent.themeScope_) === null || _a === void 0 ? void 0 : _a.getTheme()) !== null && _b !== void 0 ? _b : this.defaultTheme) !== null && _c !== void 0 ? _c : ArkThemeScopeManager.SystemTheme;
    }
    scopeForElmtId(elmtId) {
        var _a;
        if (this.handledThemeScope && this.handledComponentElmtId === elmtId) {
            return this.handledThemeScope;
        }
        if (this.handledIsFirstRender) {
            if (this.localThemeScopes.length > 0) {
                return this.localThemeScopes[this.localThemeScopes.length - 1];
            }
        }
        return (_a = this.themeScopes) === null || _a === void 0 ? void 0 : _a.find(item => item.isComponentInScope(elmtId));
    }
    lastLocalThemeScope() {
        if (this.localThemeScopes.length > 0) {
            return this.localThemeScopes[this.localThemeScopes.length - 1];
        }
        return undefined;
    }
    onEnterLocalColorMode(colorMode) {
        getUINativeModule().resource.updateColorMode(colorMode);
    }
    onExitLocalColorMode() {
        getUINativeModule().resource.restore();
    }
    forceRerenderScope(scope) {
        var _a, _b, _c;
        if (scope === undefined) {
            return;
        }
        const theme = (_b = (_a = scope === null || scope === void 0 ? void 0 : scope.getTheme()) !== null && _a !== void 0 ? _a : this.defaultTheme) !== null && _b !== void 0 ? _b : ArkThemeScopeManager.SystemTheme;
        (_c = scope.componentsInScope()) === null || _c === void 0 ? void 0 : _c.forEach((item) => this.notifyScopeThemeChanged(item, theme, scope.isColorModeChanged()));
    }
    notifyScopeThemeChanged(item, themeWillApply, isColorModeChanged) {
        if (item.owner) {
            const listener = item.owner;
            if (isColorModeChanged) {
                listener.forceRerenderNode(item.elmtId);
            }
            else {
                let isInWhiteList = item.isInWhiteList;
                if (isInWhiteList === undefined) {
                    isInWhiteList = ArkThemeWhiteList.isInWhiteList(item.name);
                    item.isInWhiteList = isInWhiteList;
                }
                if (isInWhiteList === true) {
                    listener.forceRerenderNode(item.elmtId);
                }
            }
        }
        if (item.listener) {
            const listener = item.listener;
            listener.onWillApplyTheme(themeWillApply);
        }
    }
    makeTheme(customTheme, colorMode) {
        var _a;
        const baselineTheme = (_a = this.defaultTheme) !== null && _a !== void 0 ? _a : ArkThemeScopeManager.SystemTheme;
        const theme = ArkThemeCache.getInstance().get(baselineTheme.id, customTheme, colorMode);
        return theme ? theme : new ArkThemeImpl(customTheme, colorMode, baselineTheme);
    }
    static cloneCustomThemeWithExpand(customTheme) {
        const theme = ArkThemeBase.copyCustomTheme(customTheme);
        if (theme === null || theme === void 0 ? void 0 : theme.colors) {
            ArkColorsImpl.expandByBrandColor(theme.colors);
        }
        if (theme === null || theme === void 0 ? void 0 : theme.darkColors) {
            ArkColorsImpl.expandByBrandColor(theme.darkColors, true);
        }
        return theme;
    }
    setDefaultTheme(customTheme) {
        var _a;
        (_a = this.defaultTheme) === null || _a === void 0 ? void 0 : _a.unbindFromScope(0);
        this.defaultTheme = ArkThemeScopeManager.SystemTheme;
        const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(customTheme);
        this.defaultTheme = this.makeTheme(cloneTheme, ThemeColorMode.SYSTEM);
        this.defaultTheme.bindToScope(0);
        ArkThemeNativeHelper.sendThemeToNative(this.defaultTheme, 0, !!cloneTheme?.darkColors);
        ArkThemeNativeHelper.setDefaultTheme(cloneTheme);
        this.notifyGlobalThemeChanged();
    }
    static getSystemColors() {
        return ArkThemeScopeManager.SystemTheme.colors;
    }
    currentBuildingWithThemeNodeId() {
        let _a;
        return (_a = globalThis.WithTheme) === null || _a === void 0 ? void 0 : _a.getCurrentBuildingWithThemeNodeId();
    }
    resolveParentScope(parentScope, themeScopes) {
        if (getArkThemeApiTargetVersion() < 26) {
            return parentScope;
        }
        const currentWithThemeId = this.currentBuildingWithThemeNodeId();
        if (currentWithThemeId === undefined) {
            return parentScope;
        }
        const scope = themeScopes.find(item => item.getWithThemeId() === currentWithThemeId);
        return scope ?? parentScope;
    }
    notifyGlobalThemeChanged() {
        this.listeners.forEach(listener => {
            if (listener.parent_ === undefined) {
                listener.onGlobalThemeChanged();
            }
        });
    }
    handleThemeScopeChange(scope) {
        var _a;
        const currentThemeScopeId = (_a = scope === null || scope === void 0 ? void 0 : scope.getWithThemeId()) !== null && _a !== void 0 ? _a : 0;
        if (currentThemeScopeId !== this.lastThemeScopeId) {
            this.lastThemeScopeId = currentThemeScopeId;
            WithTheme.setThemeScopeId(currentThemeScopeId);
        }
    }
    setIsFirstRender(isFirstRender) {
        this.handledIsFirstRender = isFirstRender;
    }
    static getInstance() {
        if (!ArkThemeScopeManager.instance) {
            ArkThemeScopeManager.instance = new ArkThemeScopeManager();
            ViewBuildNodeBase.setArkThemeScopeManager(ArkThemeScopeManager.instance);
        }
        return ArkThemeScopeManager.instance;
    }
}
ArkThemeScopeManager.SystemTheme = new ArkSystemTheme();
ArkThemeScopeManager.instance = undefined;
globalThis.themeScopeMgr = ArkThemeScopeManager.getInstance();
class ArkThemeWhiteList {
    static isInWhiteList(componentName) {
        let start = 0;
        let end = ArkThemeWhiteList.whiteList.length - 1;
        while (start <= end) {
            let mid = (start + end) >> 1;
            if (ArkThemeWhiteList.whiteList[mid].localeCompare(componentName) === 0) {
                return true;
            }
            if (ArkThemeWhiteList.whiteList[mid].localeCompare(componentName) === 1) {
                end = mid - 1;
            }
            else {
                start = mid + 1;
            }
        }
        return false;
    }
}
// Keep whiteList sorted A~Z (binary search depends on it).
ArkThemeWhiteList.whiteList = [
    'Badge',
    'Button',
    'DatePicker',
    'JSAlphabetIndexer',
    'JSCounter',
    'JSDataPanel',
    'JSMenu',
    'JSMenuItem',
    'JSPatternLock',
    'JSQRCode',
    'JSRadio',
    'JSTextClock',
    'JSTimePicker',
    'LoadingProgress',
    'Progress',
    'Scroll',
    'JSSearch',
    'Swiper',
    'Text',
    'TextPicker',
];

export default { ArkThemeScopeManager };