"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StyledToggleButton = void 0;
const ButtonBase_1 = require("@mui/material/ButtonBase");
const ToggleButton_1 = __importStar(require("@mui/material/ToggleButton"));
const ToggleButtonGroup_1 = require("@mui/material/ToggleButtonGroup");
const Button_1 = require("../Button");
const styled_1 = require("../styled");
const constants_1 = require("./constants");
const getSize = (size) => {
    return constants_1.SIZES[size || 'medium'];
};
const getColor = ({ color = 'primary', isSelected, state = 'default', theme, isDisabled, }) => {
    if (isDisabled) {
        return theme.palette.grey[500];
    }
    if (state === 'hover' && isSelected) {
        return theme.palette[color][900];
    }
    if (state === 'active' || isSelected) {
        return theme.palette[color][800];
    }
    return theme.palette.grey[800];
};
const getBgColor = ({ color = 'primary', isSelected, state = 'default', theme, isDisabled, variant, }) => {
    if (isDisabled) {
        return theme.palette.background.default;
    }
    if (state === 'hover' && isSelected) {
        return theme.palette[color][200];
    }
    if (state === 'hover') {
        return theme.palette.background.elementHover;
    }
    if (state === 'active' || isSelected) {
        return theme.palette[color][100];
    }
    return variant === 'plain' ? theme.palette.background.default : 'transparent';
};
const getBorderColor = ({ state = 'default', color = 'primary', theme, isSelected, }) => {
    if (state === 'hover' && isSelected) {
        return theme.palette[color][900];
    }
    if (state === 'active' || isSelected) {
        return theme.palette[color][800];
    }
    return theme.palette.components.border.default;
};
const toggleButtonColorStyle = ({ theme, color, selected, disabled, state = 'default', variant = 'transparent', }) => (0, styled_1.css) `
  color: ${getColor({ theme, color, isSelected: selected, isDisabled: disabled, state })};

  background-color: ${getBgColor({ theme, color, isSelected: selected, isDisabled: disabled, state, variant })};
  border-color: ${getBorderColor({ theme, color, isSelected: selected, state })};
`;
exports.StyledToggleButton = (0, styled_1.styled)(ToggleButton_1.default, {
    shouldForwardProp: (prop) => !['$color', '$variant'].includes(prop),
}) `
  gap: ${({ theme }) => theme.spacing(1)};

  height: ${({ size }) => getSize(size)};

  font-size: ${({ theme }) => theme.typography.h6.fontSize};
  font-weight: ${({ theme }) => theme.typography.fontWeightRegular};
  line-height: ${({ theme }) => theme.typography.h6.lineHeight};

  border-radius: ${({ theme }) => theme.shape.medium};
  
  ${({ theme, $color, disabled, $variant }) => toggleButtonColorStyle({ theme, color: $color, disabled, variant: $variant })}

  &:hover {
    ${({ theme, $color, disabled }) => toggleButtonColorStyle({ theme, color: $color, disabled, state: 'hover' })};
  }
  
  &:active {
    z-index: 3;

    ${({ theme, $color, disabled }) => toggleButtonColorStyle({ theme, color: $color, disabled, state: 'active' })};
  }
  
  &.${ToggleButton_1.toggleButtonClasses.selected} {
    z-index: 2;

    ${({ theme, $color, disabled }) => toggleButtonColorStyle({ theme, color: $color, disabled, selected: true })}

    &:hover {
      ${({ theme, $color, disabled }) => toggleButtonColorStyle({ theme, color: $color, selected: true, disabled, state: 'hover' })};
    }
    
    &:active {
      ${({ theme, $color, disabled }) => toggleButtonColorStyle({ theme, color: $color, selected: true, disabled, state: 'active' })};
    }
  }

  &.${Button_1.buttonClasses.focusVisible} {
    z-index: 3;
    
    border-color: ${({ theme }) => theme.palette.components.focused};
  }
  
  &.${ButtonBase_1.buttonBaseClasses.root}.${ToggleButtonGroup_1.toggleButtonGroupClasses.grouped}:not(:first-of-type) {
     border-left-color: ${({ theme, $color }) => getBorderColor({ theme, color: $color })};

    &:hover {
      border-left-color: ${({ theme, $color }) => getBorderColor({ theme, color: $color, state: 'hover' })};
    }

    &:active {
      border-left-color: ${({ theme, $color }) => getBorderColor({ theme, color: $color, state: 'active' })};
    }

    &.${ToggleButton_1.toggleButtonClasses.selected} {
      border-left-color: ${({ theme, $color }) => getBorderColor({ theme, color: $color, isSelected: true })};

      &:hover {
        border-left-color: ${({ theme, $color }) => getBorderColor({
    theme,
    color: $color,
    isSelected: true,
    state: 'hover',
})};
      }

      &:active {
        border-left-color: ${({ theme, $color }) => getBorderColor({
    theme,
    color: $color,
    isSelected: true,
    state: 'active',
})};
      }
    }
    
    &.${Button_1.buttonClasses.focusVisible} {
      z-index: 3;

      border-left-color: ${({ theme }) => theme.palette.components.focused};
    }
  }

  &.${Button_1.buttonClasses.disabled} {
    border-color: ${({ theme }) => theme.palette.components.border.default};
  }
`;
