/* ======================================================================== *
 * Copyright 2025 HCL America Inc.                                          *
 * 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.                                           *
 * ======================================================================== */

@use "sass:map";
@use "../../common/palette";
@use "../../common/themeMap.module";
@use "../../common/typography";

@mixin enchanted-select-base-styles(
  $part-button: 'button',
  $part-button-outlined: 'button-outlined',
  $part-button-outlined-focused: 'button-outlined-focused',
  $part-button-outlined-disabled: 'button-contained-disabled',
  $part-button-contained-focused: 'button-contained-focused',
  $part-button-contained-disabled: 'button-contained-disabled',
  $part-button-text: 'button-text',
  $part-button-end-icon: 'button-end-icon',
  $part-button-start-icon-small-without-padding: 'button-start-icon-small-without-padding',
  $part-div: 'div',
) {
  & {
    width: 100%;
  }
  
  &::part(#{$part-div}) {
    position: relative;
    width: 100%;
  }
  
  &::part(div-label) {
    display: flex;
    justify-content: space-between;
    align-items: right;
    margin-inline-end: 4px;
  }

  &::part(label) {
    @include typography.font-default;
    font-size: 12px;
    font-style: normal;
    font-weight: 600;
    color: palette.clr(light, text, secondary);
  }

  &::part(label-disabled) {
    color: palette.clr(light, text, disabled);
  }

  &::part(remove-label) {
    @include typography.caption;
    color: palette.clr(light, primary, main);
    cursor: pointer;
  }

  &::part(remove-label-disabled) {
    color: palette.clr(light, text, disabled);
    cursor: unset;
  }

  &::part(#{$part-button-text}) {
    overflow: hidden;
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
    color: palette.clr(light, text, primary);
    margin-inline-end: 12px;
  }

  &[placeholder]:not([placeholder=''])::part(#{$part-button-text}) {
    @include typography.body2italic;
    letter-spacing: 0.35px;
    color: palette.clr(light, text, secondary);
    padding-right: 1px; // to avoid text being cut off in italic
  }

  &::part(#{$part-button}),
  &::part(#{$part-button-outlined}),
  &::part(#{$part-button-outlined-focused}),
  &::part(#{$part-button-contained-focused}) {
    border: 1px solid palette.clr(light, border, tertiary);
    border-radius: 2px;
    width: 100%;
    height: 34px;
    padding: 8px;
    background-color: palette.clr(light, background, paper);
    text-align: left;
    cursor: pointer;  
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    box-sizing: border-box;
    @include typography.font-default;
    line-height:20px;
    font-size: 12px;
  }

  &::part(#{$part-button-outlined-disabled}),
  &::part(#{$part-button-contained-disabled}) {
    border: 1px solid palette.clr(light, border, tertiary);
    border-radius: 2px;
    width: 100%;
    height: 34px;
    padding: 8px;
    background-color: palette.clr(light, action, disabledBackground);
    text-align: left;
    cursor: unset;  
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    box-sizing: border-box;
    @include typography.font-default;
    line-height:20px;
    font-size: 12px;
  }

  &::part(unordered-list) {
    width: 100%;
    margin: 0;
    padding: 4px 0 4px 0;
    background-color: palette.clr(light, background, paper);
    box-shadow: #{map.get(themeMap.$enchantedPalette, shadows6)};
    border-radius: 4px;
    list-style: none;
    position:absolute;
    z-index: 10; // TODO - we need z-index layout ... I don't know if this z-index is correct
    max-height:300px;
    overflow-y: scroll;
    box-sizing: border-box;
    font-size: 12px;
  }

  /* Dropdown List Item */
  &::part(list-item) {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    cursor: pointer;
    @include typography.font-default;
    background-color: palette.clr(light, background, paper);
    color: palette.clr(light, text, primary);
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
  }

  &::part(list-item-selected) {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    cursor: pointer;
    @include typography.font-default;
    font-size: 12px;
    background-color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    color: palette.clr(light, background, paper);
  }


  &::part(list-item):focus,
  &::part(list-item-selected):focus,
  &::part(list-item):focus-visible,
  &::part(list-item-selected):focus-visible {
    outline: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06) 2px solid;
    outline-offset: -2px;
  }

  &::part(list-item):hover {
    background-color: palette.clr(light, action, activeOpacity);
    color: map.get(themeMap.$enchantedPalette, BLACK100P);
  }
  &::part(#{$part-button}):hover,
  &::part(#{$part-button-outlined}):hover,
  &::part(#{$part-button-outlined-focused}):hover {
    border: 1px solid palette.clr(light, action, active);
    border-radius: 2px;
  }
  &::part(#{$part-button}):focus,
  &::part(#{$part-button-outlined}):focus,
  &::part(#{$part-button-outlined-focused}):focus {
    border-radius: 2px;
    border: 2px solid map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
  }

  &::part(#{$part-button-contained-focused}) {
    border-radius: 2px;
    border: 2px solid map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
  }

  &::part(div):focus-within &::part(label) {
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
  }

  &::part(#{$part-button-end-icon}) {
    display: contents;
  }

  &::part(#{$part-button-start-icon-small-without-padding}) {
    display: contents;
  }
}


