@use "styleboost/utilities/functions";
@use "styleboost/utilities/properties";
@use "variables" as *;

@layer defaults {

	:root {
		--size-c-table-cell-padding: var(--spacing-3) var(--spacing-4);
		--size-c-table-row-height: 3rem;

		// Don't give tables borders by default
		// (Table borders are weird anyway, it's better to wrap them)
		--size-c-table-border: 0;

		// Make tables transparent by default
		--color-c-table-bg: transparent;
	}

	.table {
		--color-p-table-bg: #{properties.backgroundColor('table')};
		--color-p-table-bg-text: #{properties.textColor('table')};

		--color-p-table-bg-striped: #{properties.stripedBackgroundColor('table')};
		--color-p-table-bg-striped-text: #{properties.stripedBackgroundColor('table', 'text')};

		--color-p-table-bg-hover: #{properties.hoverBackgroundColor('table')};
		--color-p-table-bg-hover-text: #{properties.hoverBackgroundColor('table', 'text')};

		--color-p-table-bg-selected: #{properties.selectedBackgroundColor('table')};
		--color-p-table-bg-selected-text: #{properties.selectedBackgroundColor('table', 'text')};

		--size-p-table-border-inner: #{properties.innerBorderWidth('table')};
		--color-p-table-border: #{properties.borderColor('table')};
		--size-p-table-border: #{properties.borderWidth('table')};
		--size-p-table-border-radius: #{properties.borderRadius('table')};
		--style-p-table-border: #{properties.borderStyle('table')};
		--size-p-table-cell-padding: #{properties.miscSize('cell-padding', 'table')};
		--color-p-card-border-inner: #{properties.innerBorderColor('table')};

		// State variables
		--color-s-table-bg: var(--color-p-table-bg);
		--color-s-table-bg-text: var(--color-p-table-bg-text);

		width: 100%;
		color: var(--color-s-table-bg-text);
		background-color: var(--color-s-table-bg);
		border-color: var(--color-p-table-border);
		border-radius: var(--size-p-table-border-radius);
		border-width: var(--size-p-table-border);
		border-style: var(--style-p-table-border);

		thead {
			vertical-align: bottom;
		}

		tbody {
			vertical-align: inherit;
		}

		th,
		td {
			text-align: inherit;
			padding: var(--size-p-table-cell-padding);
			min-height: var(--size-c-table-row-height);
			vertical-align: middle;

			color: var(--color-s-table-text);
			background-color: var(--color-s-table-bg);
			border-bottom: var(--size-p-table-border-inner) var(--style-p-table-border) var(--color-p-card-border-inner);
		}

		&:not(.table-bordered) {
			--size-c-table-border: 0;
		}

		&:not(:has(tfoot)) {
			tbody tr:last-child {
				th, td {
					border-bottom: 0;
				}
			}
		}

		&-bordered {
			--size-c-table-border: 1px;
		}

		&-striped {
			tbody > tr:nth-of-type(odd) > * {
				--color-s-table-bg: var(--color-p-table-bg-striped);
				--color-s-table-bg-text: var(--color-p-table-bg-striped-text);
			}
		}

		&-hover {
			tbody > tr:hover > * {
				--color-s-table-bg: var(--color-p-table-bg-hover);
				--color-s-table-bg-text: var(--color-p-table-bg-hover-text);
			}
		}

		tbody > tr.selected > * {
			--color-s-table-bg: var(--color-p-table-bg-selected);
			--color-s-table-bg-text: var(--color-p-table-bg-selected-text);
		}
	}
}