import styled from "styled-components";
import { CSS, Transform } from "@dnd-kit/utilities";

import { Cell, Row } from "@ax/components/TableList/TableItem/style";
import { ActionMenu } from "@ax/components";

const CheckCell = styled(Cell)`
  padding-left: 0;
  padding-right: 0;
  width: 32px;
  label {
    margin-bottom: ${(p) => p.theme.spacing.s};
  }
`;

const NameCell = styled(Cell)<{ clickable: boolean }>`
  ${(p) => p.theme.textStyle.uiL};
  padding-left: ${(p) => p.theme.spacing.xs};
  pointer-events: ${(p) => (p.clickable ? "auto" : "none")};
  color: ${(p) => p.theme.color.textHighEmphasis};
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  justify-content: flex-start;
  flex-grow: 1;
  min-width: 0;
  > * {
    min-width: 0;
    max-width: 100%;
  }
`;

const ActionsCell = styled(Cell)`
  flex: 0 0 80px;
`;

const Title = styled.div`
  width: 100%;
  ${(p) => p.theme.textStyle.uiL};
  color: ${(p) => p.theme.color.textHighEmphasis};
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  min-width: 0;
`;

const CodeCell = styled(Cell)<{ clickable: boolean }>`
  ${(p) => p.theme.textStyle.uiXS};
  pointer-events: ${(p) => (p.clickable ? "auto" : "none")};
  flex: 0 0 250px;
  min-width: 0;
  > * {
    min-width: 0;
    max-width: 100%;
  }
`;

const Code = styled.div`
  width: 100%;
  ${(p) => p.theme.textStyle.uiXS};
  color: ${(p) => p.theme.color.textMediumEmphasis};
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  min-width: 0;
`;

const StyledActionMenu = styled(ActionMenu)`
  opacity: 0;
  width: 32px;
  display: flex;
  margin-left: auto;
`;

const CategoryRow = styled(Row)<{ cssTransform: Transform | null; transition?: string }>`
  transform: ${(p) => CSS.Transform.toString(p.cssTransform)};
  transition: ${(p) => p.transition};
  &:hover {
    ${StyledActionMenu} {
      opacity: 1;
    }
  }
`;

const FlagsWrapper = styled.div`
  display: flex;
  svg {
    margin-right: 2px;
    margin-bottom: -3px; // TODO
    display: inline;
    vertical-align: baseline;
  }
`;

const HandleCell = styled(Cell)`
  flex-flow: row nowrap;
  padding: ${(p) => `0 ${p.theme.spacing.xs} 0 0`};
  align-items: center;
`;

const IconWrapperDrag = styled.div`
  display: flex;
  align-items: center;
  padding: ${(p) => `${p.theme.spacing.s} 0 ${p.theme.spacing.s} ${p.theme.spacing.xs}`};
  height: 100%;
  opacity: 1;
  svg {
    path {
      fill: ${(p) => p.theme.color.textLowEmphasis};
    }
  }
`;

export {
	CheckCell,
	NameCell,
	Title,
	ActionsCell,
	CodeCell,
	Code,
	StyledActionMenu,
	CategoryRow,
	FlagsWrapper,
	IconWrapperDrag,
	HandleCell,
};
