import {css, keyframes, styled} from '@mui/material/styles';
import ChevronRight from 'herein-icon/chevron-right';

const customizations = css`
    .rc-cascader-dropdown {
        min-height: auto;
        position: absolute;
        background-color: white;
    }

    .rc-cascader-dropdown-hidden {
        display: none;
    }

    .rc-cascader-menus {
        display: flex;
        flex-wrap: nowrap;
        padding: 0.25rem 0;
        border: 1px solid #f1f1f1;
        box-shadow:
            0 4px 6px -1px rgba(0, 0, 0, 0.1),
            0 2px 4px -1px rgba(0, 0, 0, 0.06);
        border-radius: 0.375rem;
    }

    .rc-cascader-menu {
        padding: 0 0.25rem;
        flex: none;
        margin: 0;
        list-style: none;
        border-left: 1px solid #f1f1f1;
        border-right: 0;
        height: 11rem;
        min-width: 6.25rem;
        overflow: auto;

        &:first-of-type {
            border-left: 0;
        }
    }

    .rc-cascader-menu-item {
        position: relative;
        display: flex;
        align-items: center;
        flex-wrap: nowrap;
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
        border-radius: 0.125rem;
        cursor: pointer;

        &:hover {
            background-color: #ebf4ff;
        }
    }

    .rc-cascader-menu-item-selected {
        background-color: #3b82f6;
    }

    .rc-cascader-menu-item-active {
        background-color: #eff6ff;
    }

    .rc-cascader-menu-item-disabled {
        opacity: 0.5;
    }

    .rc-cascader-menu-item-content {
        flex: 1;
        color: #171717;
        font-weight: 400;
        font-size: 1rem;
    }

    .rc-cascader-menu-item-expand-icon {
        display: flex;
    }

    .rc-cascader-checkbox {
        display: inline-block;
        vertical-align: middle;
        position: relative;
        cursor: pointer;
        height: 1.25rem;
        width: 1.25rem;
        border: 1px solid #d1d1d1;
        border-radius: 0.375rem;
        overflow: hidden;
    }

    .rc-cascader-checkbox-checked {
        background-color: #2563eb;

        &::before {
            display: block;
            position: absolute;
            top: 2px;
            left: 6px;
            width: 6px;
            height: 12px;
            content: '';
            border: solid #fff;
            border-width: 0 3px 3px 0;
            transform: rotate(45deg);
            box-sizing: border-box;
        }
    }

    .rc-cascader-checkbox-indeterminate {
        background-color: #2563eb;

        &::after {
            content: '';
            position: absolute;
            box-sizing: border-box;
            background-color: #fff;
            top: 50%;
            left: 50%;
            width: 10px;
            height: 2px;
            transform: translate(-50%, -50%);
        }
    }

    .rc-cascader-rtl {
        direction: rtl;

        .rc-cascader-menu {
            padding: 0 0.25rem;
            flex: none;
            margin: 0;
            list-style: none;
            border-right: 1px solid #f1f1f1;
            border-left: 0;

            &:first-of-type {
                border-right: 0;
            }
        }
    }
`;

const ChevronRightIcon = styled(ChevronRight)`
    color: ${({theme}) => theme.palette.gray[500]};
`;

const spin = keyframes`
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
`;

const Spinner = styled('div')`
    border-color: ${({theme}) => theme.palette.gray[200]};
    width: 16px;
    height: 16px;
    animation: ${spin} 1s linear infinite;
    border-radius: 9999px;
    border-width: 4px;
    border-style: solid;
    border-top-color: ${({theme}) => theme.palette.primary[600]};
`;

export const CascadeSelectSingleStyle = {
    customizations,
    ChevronRightIcon,
    Spinner,
};
