/**
 * Copyright © Volker Schukai and all contributing authors, 2026. All rights reserved.
 * Node module: @schukai/monster
 *
 * This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
 * The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html
 *
 * For those who do not wish to adhere to the AGPLv3, a commercial license is available.
 * Acquiring a commercial license allows you to use this software without complying with the AGPLv3 terms.
 * For more information about purchasing a commercial license, please contact Volker Schukai.
 */

import { addAttributeToken } from "../../../dom/attributes.mjs";
import { ATTRIBUTE_ERRORMESSAGE } from "../../../dom/constants.mjs";

export { SheetStyleSheet };

/**
 * @private
 * @type {CSSStyleSheet}
 */
const SheetStyleSheet = new CSSStyleSheet();

try {
	SheetStyleSheet.insertRule(
		`
@layer sheet {
:host{--sheet-border-color:var(--monster-theme-control-border-color);--sheet-border-strong:var(--monster-color-primary-4);--sheet-border-width:var(--monster-theme-control-border-width,1px);--sheet-border-style:var(--monster-theme-control-border-style,solid);--sheet-header-bg:var(--monster-bg-color-primary-2);--sheet-header-fg:var(--monster-color-primary-1);--sheet-cell-bg:var(--monster-bg-color-primary-1);--sheet-cell-fg:var(--monster-color-primary-1);--sheet-grid-gap:0;--sheet-row-header-width:56px;--sheet-header-height:32px;--sheet-cell-padding-inline:8px;--sheet-cell-padding-block:6px;--sheet-resize-handle:6px;color:var(--sheet-cell-fg);display:block;font-family:var(--monster-font-family)}[part=control]{flex-direction:column;height:100%}[part=control],[part=toolbar]{display:flex;gap:var(--monster-space-4)}[part=grid-wrapper]{border:var(--sheet-border-width) var(--sheet-border-style) var(--sheet-border-color);overflow:auto;position:relative;flex:1;min-height:0}[part=grid]{display:grid;gap:var(--sheet-grid-gap);min-width:-moz-max-content;min-width:max-content;background:var(--sheet-cell-bg)}:host([data-virtualized]) [part=grid]{position:absolute;top:0;left:0;will-change:transform}:host([data-virtualized]) [part=column-header],:host([data-virtualized]) [part=corner],:host([data-virtualized]) [part=row-header]{position:relative}:host([data-resizing]) [part=grid]{-webkit-user-select:none;-moz-user-select:none;user-select:none}[part=column-header],[part=corner],[part=row-header]{background:var(--sheet-header-bg);color:var(--sheet-header-fg);display:flex;align-items:center;font-weight:600;position:sticky;z-index:2;white-space:nowrap;word-break:keep-all}[part=corner]{left:0;top:0;z-index:3}[part=column-header]{top:0;justify-content:center}[part=row-header]{left:0;justify-content:flex-end;padding-inline:var(--sheet-cell-padding-inline)}[part=cell]{border-right:var(--sheet-border-width) var(--sheet-border-style) var(--sheet-border-color);border-bottom:var(--sheet-border-width) var(--sheet-border-style) var(--sheet-border-color);background:var(--sheet-cell-bg);display:flex;align-items:stretch}[part=column-header],[part=corner],[part=row-header]{border-bottom:var(--sheet-border-width) var(--sheet-border-style) var(--sheet-border-strong);border-right:var(--sheet-border-width) var(--sheet-border-style) var(--sheet-border-strong)}[part=column-header],[part=corner]{border-bottom:0}[part=corner],[part=row-header]{border-right:0}[part=cell-input]{border:0;background:transparent;color:inherit;font:inherit;padding:var(--sheet-cell-padding-block) var(--sheet-cell-padding-inline);width:100%;outline:none}[part=cell-input]:focus{background:var(--monster-bg-color-primary-2)}[part=column-resize]{right:-1px;top:0;height:100%;width:var(--sheet-resize-handle);cursor:col-resize;background:linear-gradient(to right,transparent 0,transparent calc(100% - 1px),var(--sheet-border-strong) calc(100% - 1px),var(--sheet-border-strong) 100%)}[part=column-resize],[part=row-resize]{position:absolute;pointer-events:auto;touch-action:none;z-index:4}[part=row-resize]{bottom:-1px;left:0;width:100%;height:var(--sheet-resize-handle);cursor:row-resize;background:linear-gradient(to bottom,transparent 0,transparent calc(100% - 1px),var(--sheet-border-strong) calc(100% - 1px),var(--sheet-border-strong) 100%)}
}`,
		0,
	);
} catch (e) {
	addAttributeToken(
		document.getRootNode().querySelector("html"),
		ATTRIBUTE_ERRORMESSAGE,
		e + "",
	);
}
