@use 'sass:meta';
@use 'sass:list';
@use 'sass:string';

/// Takes a given string and returns true if it is a reserved word in CSS or
/// Sass, and returns false if it is not a reserved word.
///
/// @param {String} $word - The word being checked to see if it is reserved.
///
/// @return {Bool} Returns true if $word is reserved, otherwise returns false.
///
/// @access public
/// @group Utilities
///
/// @throw Invalid data type for $word
@function is-reserved($word) {
  $reserved-words: (
    'align-content', 'align-items', 'align-self', 'animation', 'background',
    'border', 'color', 'cursor', 'display', 'flex', 'font', 'grid', 'height',
    'justify-content', 'margin', 'padding', 'position', 'width', 'charset',
    'import', 'media', 'font-face', 'keyframes', 'supports',
    'namespace', 'active', 'hover', 'hsl', 'hsla', 'first-child', 'last-child',
    'nth-child', 'after', 'before', 'first-letter', 'first-line', 'use', 'import',
    'mixin', 'include', 'function', 'extend', 'error', 'warn', 'if', 'else',
    'for', 'each', 'while', 'return', 'forward', 'debug', 'darken', 'rgb'
    'lighten', 'mix', 'rgba', 'adjust-color', 'scale-color', 'add', 'subtract',
    'map', 'list', 'box-shadow', 'text-shadow', 'transition', 'transform',
    'opacity', 'visibility', 'z-index', 'clip-path', 'filter',
    'backface-visibility', 'overflow', 'white-space', 'vertical-align',
    'text-align', 'line-height', 'focus', 'disabled', 'checked', 'not', 'root',
    'target', 'empty', 'nth-of-type', 'placeholder', 'selection', 'content',
    'at-root', 'default', 'global', 'optional', 'min', 'max', 'inspect',
    'unquote', 'quote', 'percentage', 'round', 'ceil', 'floor', 'abs', 'random',
    'meta', 'sass', 'string', 'selector', 'unicode-bidi', 'direction', 'columns',
    'column-span', 'column-width', 'column-count', 'column-fill', 'column-gap',
    'column-rule', 'column-rule-width', 'column-rule-style', 'column-rule-color',
    'break-before', 'break-inside', 'break-after', 'page-break-before',
    'page-break-inside', 'page-break-after', 'orphans', 'widows', 'zoom',
    'max-zoom', 'min-zoom', 'user-zoom', 'orientation', 'fill', 'stroke',
    'src', 'letter-spacing', 'quotes', 'hanging-punctuation',
    'counter-increment', 'counter-reset', 'clamp', 'fit-content', 'min-content',
    'max-content', 'min-height', 'min-width', 'max-height', 'max-width',
    'px', 'pt', 'cm', 'mm', 'q', 'x', 'ex', 'em', 'em', 'dpi', 'dppx', 'dpcm',
    'rem', 'Hz', 'kHz', 'deg', 'rad', 'turn', 'rotate', 'vw', 'vh', 'vmin',
    'vmax', 'svw', 'svh', 'svmin', 'svmax', 'lvw', 'lvh', 'lvmin', 'lvmax',
    'dvw', 'dvh', 'dvmin', 'dvmax', 'lh', 'rlh', 'vb', 'vi', 'svb', 'svi',
    'lvb', 'lvi', 'dvb', 'dvi', 'lch', 'hwb', 'font-family',
    'font-size', 'font-weight', 'font-style', 'font-variant', 'font-size-adjust',
    'font-stretch', 'background-color', 'background-image',
    'background-attachment', 'background-position', 'background-position-x',
    'background-position-y', 'background-clip', 'background-origin',
    'background-size', 'background-repeat', 'image-rendering', 'caret-color',
    'box-decoration-break', 'box-shadow', 'outline', 'outline-width',
    'outline-style', 'outline-color', 'outline-offset', 'table-layout',
    'caption-side', 'empty-cells', 'list-style', 'list-style-position',
    'list-style-type', 'list-style-image', 'text-transform',
    'text-align', 'text-align-last', 'text-decoration', 'text-emphasis',
    'text-emphasis-position', 'text-emphasis-style', 'text-emphasis-color',
    'text-indent', 'text-justify', 'text-outline', 'text-wrap', 'text-overflow',
    'ellipsis', 'text-overflow-mode', 'text-shadow', 'word-spacing',
    'word-wrap', 'word-break', 'overflow-wrap', 'tab-size',
    'hyphens', 'interpolation-mode', 'transition-delay',
    'transition-timing-function', 'transition-duration', 'transition-property',
    'transform-style', 'transform-origin', 'animation-name',
    'animation-duration', 'animation-play-state', 'animation-timing-function',
    'animation-delay', 'animation-iteration-count', 'animation-direction',
    'animation-fill-mode' '-webkit', '-moz', '-ms', '-o', 'calc', 'rotateX',
    'rotateY', 'rotateZ', 'rotate3d', 'scale', 'scaleX', 'scaleY', 'scaleZ',
    'scale3d', 'skew', 'skewX', 'skewY', 'skewZ', 'matrix', 'matrix3d',
    'translate', 'translateX', 'translateY', 'translateZ', 'translate3d',
    'perspective', 'perspective-origin', 'perspective-origin-x',
    'perspective-origin-y', 'perspective-origin-z', 'saturate', 'sepia',
    'invert', 'grayscale', 'hue-rotate', 'drop-shadow', 'contrast',
    'brightness', 'blur', 'abs', 'sign', 'exp', 'log', 'hypot', 'sqrt',
    'pow', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'mod',
    'pi', 'e', 'infinity', '-infinity', 'NaN',
    'color-contrast', 'devoce-cmyk', 'light-dark', 'color-scheme',
    'linear-gradient', 'radial-gradient', 'conic-gradient',
    'repeating-linear-gradient', 'repeating-radial-gradient',
    'repeating-conic-gradient', 'image', 'image-set', 'cross-fade', 'element',
    'paint', 'counter', 'counters', 'symbols', 'circle', 'ellipse',
    'comma', 'space', 'inset', 'rect', 'xywh', 'path', 'clip', 'attr', 'env',
    'url', 'yar', 'repeat', 'stylistic', 'styleset', 'character-variant',
    'swash', 'ornaments' 'annotation', 'linear', 'cubic-bezier', 'steps',
    'ease', 'ease-in', 'ease-out', 'ease-in-out', 'scroll', 'view', 'slash',
    'min-resolution', 'max-resolution', 'prefers-color-scheme',
    'prefers-reduced-motion', 'border-style', 'border-color', 'border-width',
    'border-radius', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
    'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
    'border-top-style', 'border-top-color', 'border-top-width',
    'border-top-left-radius', 'border-top-right-radius',
    'border-bottom-style', 'border-bottom-color', 'border-bottom-width',
    'border-bottom-left-radius', 'border-bottom-right-radius',
    'border-left-style', 'border-left-color', 'border-left-width',
    'border-right-style', 'border-right-color', 'border-right-width',
    'focus-visible', 'focus-within', 'focusring', 'display-p3', 'from', 'as',
    'math' 'aspect-ratio', 'object-fit', 'object-position', 'flex-grow',
    'flex-shrink', 'flex-basis', 'flex-direction', 'flex-wrap',
    'grid-template', 'grid-template-columns', 'grid-template-rows',
    'grid-column', 'grid-row', 'grid-area', 'grid-gap', 'grid-row-gap',
    'grid-column-gap', 'column-gap', 'row-gap', 'gap', 'place-items',
    'place-content', 'place-self', 'overflow-x', 'overflow-y', 'counter-style',
    'counter-set', 'all', 'isolation', 'mix-blend-mode', 'background-blend-mode',
    'scroll-behavior', 'scroll-snap-type', 'scroll-snap-align',
    'scroll-snap-stop', 'scroll-padding', 'scroll-margin', 'touch-action',
    'pointer-events', 'writing-mode', 'text-orientation', 'line-break',
    'resize', 'user-select', 'nav-index', 'nav-up', 'nav-right', 'nav-down',
    'nav-left', 'document', 'page', 'viewport', 'region', 'backdrop-filter',
    'block', 'block-size', 'border-block', 'border-block-color',
    'border-block-end', 'border-block-end-color', 'border-block-end-style',
    'border-block-end-width', 'border-block-start', 'border-block-start-color',
    'border-block-start-style', 'border-block-start-width', 'border-block-style',
    'border-block-width', 'border-collapse', 'border-spacing',
    'animation-composition', 'box-align', 'box-pack',
    'box-snap', 'box-suppress', 'break-all', 'clear', 'contain',
    'content-visibility', 'continue', 'env()', 'flex-flow', 'font-display',
    'font-kerning', 'font-language-override', 'font-optical-sizing',
    'font-palette', 'font-synthesis', 'font-variation-settings',
    'forced-color-adjust', 'grid-auto-columns', 'grid-auto-flow',
    'grid-auto-rows', 'hyphenate-character', 'image-orientation',
    'image-resolution', 'inline-size', 'inset-block', 'inset-block-end',
    'inset-block-start', 'inset-inline', 'inset-inline-end',
    'inset-inline-start', 'justify-items', 'justify-self', 'justify-tracks',
    'line-clamp', 'logical-height', 'logical-width', 'margin-block',
    'margin-block-end', 'margin-block-start', 'margin-inline',
    'margin-inline-end', 'margin-inline-start', 'mask', 'mask-border',
    'mask-clip', 'mask-composite', 'mask-image', 'mask-mode', 'mask-origin',
    'mask-position', 'mask-repeat', 'mask-size', 'mask-type',
    'masonry-auto-flow', 'math-style', 'object-max-fit', 'object-min-fit',
    'offset', 'offset-anchor', 'offset-distance', 'offset-path', 'offset-rotate',
    'outline-radius', 'overflow-anchor', 'overflow-block', 'overflow-clip-box',
    'overflow-clip-margin', 'overflow-inline', 'overscroll-behavior',
    'overscroll-behavior-block', 'overscroll-behavior-inline',
    'overscroll-behavior-x', 'overscroll-behavior-y', 'padding-block',
    'padding-block-end', 'padding-block-start', 'padding-inline',
    'padding-inline-end', 'padding-inline-start', 'page-break', 'paint-order',
    'place-holder-shown', 'pointer', 'quotes-auto', 'range', 'ruby-align',
    'ruby-merge', 'ruby-position', 'scrollbar-color', 'scrollbar-gutter',
    'scrollbar-width', 'shape-image-threshold', 'shape-margin', 'shape-outside',
    'size', 'speak', 'speak-as', 'syntax', 'tab-align', 'table-baseline',
    'text-combine-upright', 'text-edge', 'text-grid', 'text-group-align',
    'text-spacing', 'transform-box', 'transition-composition', 'user-zoom',
    'vector-effect', 'will-change', 'word-boundary-detection',
    'word-boundary-expansion', 'wrap-flow', 'wrap-through', 'writing-mode',
    'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed'
    'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded',
    'small-caps', 'all-small-caps', 'italic', 'oblique', 'bold', 'inherit',
    'initial', 'revert', 'revert-layer', 'unset', 'none', 'always', 'never',
    'auto', 'first', 'last', 'force-end', 'allow-end',
  );

  @if meta.type-of($word) != 'string' {
    @error 'Invalid value of [ #{$word} ] passed to ' +
        'the [ is-reserved ] function. Value of $word must be a string.';
  }

  $word: string.to-lower-case($word);

  @return not not list.index($reserved-words, $word);
}
