/* ======================================================================== *
 * 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";
@use "../../common/palette";
@use "../../common/themeMap.module";

@mixin enchanted-button-base-styles(
  $button: 'button',
  $button-outlined: 'button-outlined',
  $button-outlined-focused: 'button-outlined-focused',
  $button-start-icon: 'button-start-icon',
  $button-start-icon-rtl-margin: 'button-start-icon-rtl-margin',
  $button-end-icon: 'button-end-icon',
  $button-start-icon-small-without-padding: 'button-start-icon-small-without-padding',
  $button-contained: 'button-contained',
  $button-contained-inverse: 'button-contained-inverse',
  $button-contained-focused: 'button-contained-focused',
  $button-contained-focused-inverse: 'button-contained-focused-inverse',
  $button-contained-disabled: 'button-contained-disabled',
  $button-contained-disabled-inverse: 'button-contained-disabled-inverse',
  $button-enchanted-text: 'button-enchanted-text',
  $button-enchanted-text-inverse: 'button-enchanted-text-inverse',
  $button-enchanted-text-disabled: 'button-enchanted-text-disabled',
  $button-enchanted-text-disabled-inverse: 'button-enchanted-text-disabled-inverse',
  $button-enchanted-text-focused: 'button-enchanted-text-focused',
  $button-enchanted-text-focused-inverse: 'button-enchanted-text-focused-inverse',
  $button-enchanted-outlined: 'button-enchanted-outlined',
  $button-enchanted-outlined-disabled: 'button-enchanted-outlined-disabled',
  $button-enchanted-outlined-focused: 'button-enchanted-outlined-focused',
){
  &::part(#{$button}) {
    @include common.button;
    align-items: center;
    border-radius: 2px;
  }
  &::part(#{$button}):hover{
    background-color: palette.$outline-color;
  }
  &::part(#{$button}):focus{
    border-radius: 4px;
    outline: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06) 1px solid;
    outline-offset: 2px;
  }
  &::part(#{$button-outlined}) {
    @include common.button;
    outline: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06) solid 1px;
  }

  &::part(#{$button-outlined-focused}) {
    @include common.button;
    outline: palette.$outline-color solid 1px;
    border-radius: 4px;
  }

  &::part(#{$button-start-icon}) {
    color: palette.clr(light, background, paper);
    height: 16px;
    margin-right: 4px;
    width: 16px;
    filter: invert(49%) sepia(85%) saturate(7510%) hue-rotate(219deg) brightness(87%) contrast(97%);
  }

  &::part(#{$button-start-icon-rtl-margin}) {
    color: palette.clr(light, background, paper);
    height: 16px;
    margin-left: 4px;
    width: 16px;
    filter: invert(49%) sepia(85%) saturate(7510%) hue-rotate(219deg) brightness(87%) contrast(97%);
  }

  &::part(#{$button-end-icon}) {
    color: palette.clr(light, background, paper);
    height: 16px;
    margin-right: 4px;
    width: 16px;
    display:flex;
    justify-content: space-between;
  }

  &::part(#{$button-start-icon-small-without-padding}) {
    height: 16px;
    width: 16px;
  }

  /* styles for contained variant of enchanted-button */
  &::part(#{$button-contained}),
  &::part(#{$button-contained-inverse}) {
    @include common.button;
  }

  &::part(#{$button-contained-disabled}),
  &::part(#{$button-contained-disabled-inverse}) {
    @include common.button-disabled;
    background-color: palette.clr(light, action, disabledBackground);
    border: 1px solid map.get(themeMap.$enchantedPalette, NG150);
  }

  &::part(#{$button-contained-focused}),
  &::part(#{$button-contained-focused-inverse}) {
    @include common.enchanted-button-focused;
    @include common.button; 
  }
  &::part(#{$button-contained}):hover {
    background-color: palette.clr(light, primary, dark);
    color: palette.clr(light, background, paper);
    --icon-theme-color: #{palette.clr(light, background, paper)};   
  }
  &::part(#{$button-contained}):active,
  &::part(#{$button-contained-inverse}):active {
    @include common.enchanted-button-focused;
    background-color: palette.clr(light, primary, dark);
    color: palette.clr(light, background, paper); 
    --icon-theme-color: #{palette.clr(light, background, paper)};
  }
  &::part(#{$button-contained-inverse}) {
    background-color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE09);
    color: palette.clr(light, text, primary);
    --icon-theme-color: #{palette.clr(light, text, primary)};
  }
  &::part(#{$button-contained-focused-inverse}) {
    outline: palette.clr(light, action, focusInverse) 1px solid;
    background-color: palette.clr(light, primary, darkInverse);
    color: palette.clr(light, text, primary);
    --icon-theme-color: #{palette.clr(light, text, primary)};
  }
  &::part(#{$button-contained-inverse}):hover {
    background-color: palette.clr(light, primary, darkInverse);
    color: palette.clr(light, text, primary);
    --icon-theme-color: #{palette.clr(light, text, primary)};   
  }
  &::part(#{$button-contained-inverse}):active {
    outline: palette.clr(light, action, focusInverse) 1px solid;
    background-color: palette.clr(light, primary, darkInverse);
    color: palette.clr(light, text, primary);
    --icon-theme-color: #{palette.clr(light, text, primary)}; 
  }

  /* styles for text variant of enchanted-button */
  &::part(#{$button-enchanted-text}),
  &::part(#{$button-enchanted-text-inverse}) {
    @include common.button;
    border: none !important;
    background-color: palette.clr(light, background, paper);
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
  }
  &::part(#{$button-enchanted-text-disabled}),
  &::part(#{$button-enchanted-text-disabled-inverse}) {
    @include common.button-disabled;
    background-color: palette.clr(light, background, paper);
    border: none;
  }
  &::part(#{$button-enchanted-text-focused}),
  &::part(#{$button-enchanted-text-focused-inverse}) {
    @include common.enchanted-button-focused;
    @include common.button;
    border: none;
    background-color: palette.clr(light, background, paper);
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
  }
  &::part(#{$button-enchanted-text-focused}):hover {
    background-color: palette.clr(light, action, hover);
  }
  &::part(#{$button-enchanted-text}):hover,
  &::part(#{$button-enchanted-text-inverse}):hover {
    border: none !important;
    background-color: palette.clr(light, action, hover);
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06); 
  }
  &::part(#{$button-enchanted-text}):active,
  &::part(#{$button-enchanted-text-inverse}):active {
    @include common.enchanted-button-focused;
    border: none !important;
    background-color: palette.clr(light, action, hover);
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06); 
  }
  &::part(#{$button-enchanted-text-inverse}) {
    color: palette.clr(light, primary, inverse);
    background-color: palette.clr(light, background, dark);
  }
  &::part(#{$button-enchanted-text-disabled-inverse}) {
    background-color: palette.clr(light, background, dark);
    color: palette.clr(light, action, disabledInverse) !important;
  }
  &::part(#{$button-enchanted-text-focused-inverse}) {
    outline: palette.clr(light, action, focusInverse) 1px solid;
    background-color: palette.clr(light, background, dark);
    color: palette.clr(light, primary, inverse);
  }
  &::part(#{$button-enchanted-text-inverse}):hover {
    background-color: palette.clr(light, action, hoverInverse);
    color: palette.clr(light, primary, darkInverse);
  }
  &::part(#{$button-enchanted-text-inverse}):active {
    outline: palette.clr(light, action, focusInverse) 1px solid;
    background-color: palette.clr(light, background, dark);
    color: palette.clr(light, primary, inverse);
  }

  /* styles for outlined variant of enchanted-button */
  &::part(#{$button-enchanted-outlined}) {
    @include common.button;
    border: 1px solid map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    background-color: palette.clr(light, background, paper);
  }
  &::part(#{$button-enchanted-outlined-disabled}) {
    @include common.button-disabled;
    background-color: palette.clr(light, background, paper);
    border: 1px solid map.get(themeMap.$enchantedPalette, NG150);
    filter: saturate(2%) hue-rotate(50deg) brightness(103%) contrast(102%);
  }
  &::part(#{$button-enchanted-outlined-focused}) {
    @include common.enchanted-button-focused;
    @include common.button;
    border: 1px solid map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06) !important;
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    background-color: palette.clr(light, background, paper);
  }
  &::part(#{$button-enchanted-outlined}):hover {
    border: 1px solid map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    background-color: palette.clr(light, action, hover);
  }
  &::part(#{$button-enchanted-outlined}):active {
    @include common.enchanted-button-focused;
    border: 1px solid map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    color: map.get(themeMap.$enchantedPalette, HCLSOFTWAREBLUE06);
    background-color: palette.clr(light, action, hover);
  }
  
}
