@use 'sass:map';
@use '../tokens/utilities_formatted';

@use '../variables/sizing' as *;
@use '../variables/type';
@use '../variables/commons';

/*
  Utilities are generated with our utility API using bellow $utilities map.

  The utility map contains a keyed list of utility groups which accept the following options:

  | Option            | Type     | Default value | Description                                                                                                                                                                                                                              |
  |-------------------|----------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
  | property          | Required | –             | Name of the property, this can be a string or an array of strings (e.g., horizontal paddings or margins).                                                                                                                                |
  | values            | Required | –             | List of values, or a map if you don’t want the class name to be the same as the value. If null is used as map key, class is not prepended to the class name.                                                                             |
  | class             | Optional | null          | Name of the generated class. If not provided and property is an array of strings, class will default to the first element of the property array. If not provided and property is a string, the values keys are used for the class names. |
  | css-var           | Optional | false         | Boolean to generate CSS variables instead of CSS rules.                                                                                                                                                                                  |
  | css-variable-name | Optional | null          | Custom un-prefixed name for the CSS variable inside the ruleset.                                                                                                                                                                         |
  | local-vars        | Optional | null          | Map of local CSS variables to generate in addition to the CSS rules.                                                                                                                                                                     |
  | state             | Optional | null          | List of pseudo-class variants (e.g., :hover or :focus) to generate.                                                                                                                                                                      |
  | responsive        | Optional | false         | Boolean indicating if responsive classes should be generated.                                                                                                                                                                            |

  Our API is based on bootstrap utility API, more information is available here: https://getbootstrap.com/docs/5.3/utilities/api/
*/

$position-values: (
  0: 0,
  50: 50%,
  100: 100%,
);

$utilities: (
  'border': (
    property: border,
    class: border,
    values: (
      null: var(--post-border-width, map.get(utilities_formatted.$border-default, width)) solid
      map.get(utilities_formatted.$border-default, color),
      0: 0,
    ),
  ),
  'border-top': (
    property: border-block-start,
    class: border-top,
    values: (
      null: var(--post-border-width, map.get(utilities_formatted.$border-default, width)) solid
      map.get(utilities_formatted.$border-default, color),
      0: 0,
    ),
  ),
  'border-end': (
    property: border-inline-end,
    class: border-end,
    values: (
      null: var(--post-border-width, map.get(utilities_formatted.$border-default, width)) solid
      map.get(utilities_formatted.$border-default, color),
      0: 0,
    ),
  ),
  'border-bottom': (
    property: border-block-end,
    class: border-bottom,
    values: (
      null: var(--post-border-width, map.get(utilities_formatted.$border-default, width)) solid
      map.get(utilities_formatted.$border-default, color),
      0: 0,
    ),
  ),
  'border-start': (
    property: border-inline-start,
    class: border-start,
    values: (
      null: var(--post-border-width, map.get(utilities_formatted.$border-default, width)) solid
      map.get(utilities_formatted.$border-default, color),
      0: 0,
    ),
  ),
  'border-width': (
    css-var: true,
    css-variable-name: border-width,
    class: border,
    values: utilities_formatted.$border-width,
  ),
  'rounded': (
    property: border-radius,
    class: rounded,
    values: map.merge(
      utilities_formatted.$border-radius,
      (
        pill: 50rem,
        circle: 50%,
      )
    ),
  ),
  'rounded-top': (
    property: border-start-start-radius border-start-end-radius,
    class: rounded-top,
    values: map.merge(
      utilities_formatted.$border-radius,
      (
        pill: 50rem,
        circle: 50%,
      )
    ),
  ),
  'rounded-end': (
    property: border-start-end-radius border-end-end-radius,
    class: rounded-end,
    values: map.merge(
      utilities_formatted.$border-radius,
      (
        pill: 50rem,
        circle: 50%,
      )
    ),
  ),
  'rounded-bottom': (
    property: border-end-end-radius border-end-start-radius,
    class: rounded-bottom,
    values: map.merge(
      utilities_formatted.$border-radius,
      (
        pill: 50rem,
        circle: 50%,
      )
    ),
  ),
  'rounded-start': (
    property: border-end-start-radius border-start-start-radius,
    class: rounded-start,
    values: map.merge(
      utilities_formatted.$border-radius,
      (
        pill: 50rem,
        circle: 50%,
      )
    ),
  ),
  'grid-gutter-x': (
    responsive: true,
    property: --post-grid-gutter-x,
    class: gx g,
    values: utilities_formatted.$gap,
  ),
  'grid-gutter-y': (
    responsive: true,
    property: --post-grid-gutter-y,
    class: gy g,
    values: utilities_formatted.$gap,
  ),
  'width': (
    responsive: true,
    property: width,
    class: w,
    values: map.merge(utilities_formatted.$gap, $post-percentage-sizes),
  ),
  'height': (
    responsive: true,
    property: height,
    class: h,
    values: map.merge(utilities_formatted.$gap, $post-percentage-sizes),
  ),
  'max-width': (
    responsive: true,
    property: max-width,
    class: max-w,
    values: map.merge(utilities_formatted.$gap, $post-percentage-sizes),
  ),
  'max-height': (
    responsive: true,
    property: max-height,
    class: max-h,
    values: map.merge(utilities_formatted.$gap, $post-percentage-sizes),
  ),
  'min-width': (
    responsive: true,
    property: min-width,
    class: min-w,
    values: map.merge(utilities_formatted.$gap, $post-percentage-sizes),
  ),
  'min-height': (
    responsive: true,
    property: min-height,
    class: min-h,
    values: map.merge(utilities_formatted.$gap, $post-percentage-sizes),
  ),
  'viewport-width': (
    responsive: true,
    property: width,
    class: vw,
    values: $post-viewport-width-sizes,
  ),

  'viewport-height': (
    responsive: true,
    property: height,
    class: vh,
    values: $post-viewport-height-sizes,
  ),

  'min-viewport-width': (
    responsive: true,
    property: min-width,
    class: min-vw,
    values: $post-viewport-width-sizes,
  ),

  'min-viewport-height': (
    responsive: true,
    property: min-height,
    class: min-vh,
    values: $post-viewport-height-sizes,
  ),

  'max-viewport-width': (
    responsive: true,
    property: max-width,
    class: max-vw,
    values: $post-viewport-width-sizes,
  ),

  'max-viewport-height': (
    responsive: true,
    property: max-height,
    class: max-vh,
    values: $post-viewport-height-sizes,
  ),
  'align': (
    property: vertical-align,
    class: align,
    values: baseline top middle bottom text-bottom text-top,
  ),
  'float': (
    responsive: true,
    property: float,
    values: (
      start: inline-start,
      end: inline-end,
      none: none,
    ),
  ),
  'opacity': (
    property: opacity,
    values: (
      0: 0,
      25: 0.25,
      50: 0.5,
      75: 0.75,
      100: 1,
    ),
  ),
  'margin-top': (
    responsive: true,
    property: margin-top,
    class: mt my m,
    values: utilities_formatted.$margin,
  ),
  'margin-end': (
    responsive: true,
    property: margin-right,
    class: me mx m,
    values: utilities_formatted.$margin,
  ),
  'margin-bottom': (
    responsive: true,
    property: margin-bottom,
    class: mb my m,
    values: utilities_formatted.$margin,
  ),
  'margin-start': (
    responsive: true,
    property: margin-left,
    class: ms mx m,
    values: utilities_formatted.$margin,
  ),
  'padding-top': (
    responsive: true,
    property: padding-top,
    class: pt py p,
    values: utilities_formatted.$padding,
  ),
  'padding-end': (
    responsive: true,
    property: padding-right,
    class: pe px p,
    values: utilities_formatted.$padding,
  ),
  'padding-bottom': (
    responsive: true,
    property: padding-bottom,
    class: pb py p,
    values: utilities_formatted.$padding,
  ),
  'padding-start': (
    responsive: true,
    property: padding-left,
    class: ps px p,
    values: utilities_formatted.$padding,
  ),
  'gap': (
    responsive: true,
    property: gap,
    class: gap,
    values: utilities_formatted.$gap,
  ),
  'row-gap': (
    responsive: true,
    property: row-gap,
    class: row-gap,
    values: utilities_formatted.$gap,
  ),
  'column-gap': (
    responsive: true,
    property: column-gap,
    class: column-gap,
    values: utilities_formatted.$gap,
  ),
  'flex': (
    responsive: true,
    property: flex,
    values: (
      fill: 1 1 auto,
    ),
  ),
  'flex-direction': (
    responsive: true,
    property: flex-direction,
    class: flex,
    values: row column row-reverse column-reverse,
  ),
  'flex-grow': (
    responsive: true,
    property: flex-grow,
    class: flex,
    values: (
      grow-0: 0,
      grow-1: 1,
    ),
  ),
  'flex-shrink': (
    responsive: true,
    property: flex-shrink,
    class: flex,
    values: (
      shrink-0: 0,
      shrink-1: 1,
    ),
  ),
  'flex-wrap': (
    responsive: true,
    property: flex-wrap,
    class: flex,
    values: wrap nowrap wrap-reverse,
  ),
  'justify-content': (
    responsive: true,
    property: justify-content,
    values: (
      start: flex-start,
      end: flex-end,
      center: center,
      between: space-between,
      around: space-around,
      evenly: space-evenly,
    ),
  ),
  'align-items': (
    responsive: true,
    property: align-items,
    values: (
      start: flex-start,
      end: flex-end,
      center: center,
      baseline: baseline,
      stretch: stretch,
    ),
  ),
  'align-content': (
    responsive: true,
    property: align-content,
    values: (
      start: flex-start,
      end: flex-end,
      center: center,
      between: space-between,
      around: space-around,
      stretch: stretch,
    ),
  ),
  'align-self': (
    responsive: true,
    property: align-self,
    values: (
      auto: auto,
      start: flex-start,
      end: flex-end,
      center: center,
      baseline: baseline,
      stretch: stretch,
    ),
  ),
  'order': (
    responsive: true,
    property: order,
    values: (
      first: -1,
      0: 0,
      1: 1,
      2: 2,
      3: 3,
      4: 4,
      5: 5,
      last: 6,
    ),
  ),
  'display': (
    responsive: true,
    print: true,
    property: display,
    class: d,
    values: inline inline-block block grid inline-grid table table-row table-cell flex inline-flex
    none,
  ),
  'position': (
    property: position,
    values: static relative absolute fixed sticky,
  ),
  'top': (
    property: inset-block-start,
    class: top,
    values: $position-values,
  ),
  'bottom': (
    property: inset-block-end,
    class: bottom,
    values: $position-values,
  ),
  'start': (
    property: inset-inline-start,
    class: start,
    values: $position-values,
  ),
  'end': (
    property: inset-inline-end,
    class: end,
    values: $position-values,
  ),
  'translate-middle': (
    property: transform,
    class: translate-middle,
    values: (
      null: translate(-50%, -50%),
      x: translateX(-50%),
      y: translateY(-50%),
    ),
  ),
  'overflow': (
    property: overflow,
    values: auto hidden visible scroll,
  ),
  'overflow-x': (
    property: overflow-x,
    values: auto hidden visible scroll,
  ),
  'overflow-y': (
    property: overflow-y,
    values: auto hidden visible scroll,
  ),
  'font-family': (
    property: font-family,
    class: font,
    values: (
      'sans-serif': type.$font-family-sans-serif,
    ),
  ),
  'font-style': (
    property: font-style,
    class: fst,
    values: italic normal,
  ),
  'font-weight': (
    property: font-weight,
    class: fw,
    values: (
      black: type.$font-weight-black,
      bold: type.$font-weight-bold,
      normal: type.$font-weight-normal,
    ),
  ),
  'line-height': (
    property: line-height,
    class: lh,
    values: (
      1: type.$line-height-1,
      sm: type.$line-height-sm,
      lg: type.$line-height-lg,
    ),
  ),
  'text-align': (
    responsive: true,
    property: text-align,
    class: text,
    values: (
      start: left,
      end: right,
      center: center,
    ),
  ),
  'text-decoration': (
    property: text-decoration,
    values: none underline line-through,
  ),
  'text-transform': (
    property: text-transform,
    class: text,
    values: lowercase uppercase capitalize,
  ),
  'white-space': (
    property: white-space,
    class: text,
    values: (
      wrap: normal,
      nowrap: nowrap,
    ),
  ),
  'word-wrap': (
    property: word-wrap word-break,
    class: text,
    values: (
      break: break-word,
    ),
    rtl: false,
  ),
  'elevation': (
    property: box-shadow,
    values: utilities_formatted.$elevation,
    class: elevation,
  ),
  'font-size': (
    responsive: true,
    property: font-size,
    class: fs,
    values: utilities_formatted.$font-size,
  ),
  'color': (
    property: color,
    class: text,
    values: (
      reset: inherit,
    ),
  ),
  'visibility': (
    property: visibility,
    class: null,
    values: (
      visible: visible,
      invisible: hidden,
    ),
  ),
  'user-select': (
    property: user-select,
    values: all auto none,
  ),
  'pointer-events': (
    property: pointer-events,
    class: pe,
    values: none auto,
  ),
  'z-index': (
    property: z-index,
    class: z,
    values: map.merge(commons.$zindex-map, commons.$named-zindex-map),
  ),
  'small': (
    property: font-size,
    class: null,
    values: (
      small: 80%,
    ),
  ),
);
