{"version":3,"file":"ComponentCard.mjs","sources":["../../../../admin/src/components/ComponentCard/ComponentCard.tsx"],"sourcesContent":["import type { MouseEvent } from 'react';\n\nimport { Box, Flex, Typography } from '@strapi/design-system';\nimport { Cross } from '@strapi/icons';\nimport get from 'lodash/get';\nimport { styled } from 'styled-components';\n\nimport { useDataManager } from '../DataManager/useDataManager';\n\nimport { ComponentIcon } from './ComponentIcon';\n\nimport type { Internal, Struct } from '@strapi/types';\n\ninterface ComponentCardProps {\n  component: string;\n  dzName: string;\n  index: number;\n  isActive?: boolean;\n  isInDevelopmentMode?: boolean;\n  onClick?: () => void;\n  forTarget: Struct.ModelType;\n  targetUid: Internal.UID.Schema;\n  disabled?: boolean;\n}\n\nconst CloseButton = styled(Box)`\n  position: absolute;\n  display: none;\n  top: 5px;\n  right: 0.8rem;\n\n  svg {\n    width: 1rem;\n    height: 1rem;\n\n    path {\n      fill: ${({ theme }) => theme.colors.primary600};\n    }\n  }\n`;\n\nconst ComponentBox = styled(Flex)`\n  width: 14rem;\n  height: 8rem;\n  position: relative;\n  border: 1px solid ${({ theme }) => theme.colors.neutral200};\n  background: ${({ theme }) => theme.colors.neutral100};\n  border-radius: ${({ theme }) => theme.borderRadius};\n  max-width: 100%;\n\n  &.active,\n  &:focus,\n  &:hover {\n    border: 1px solid ${({ theme }) => theme.colors.primary200};\n    background: ${({ theme }) => theme.colors.primary100};\n    color: ${({ theme }) => theme.colors.primary600};\n\n    ${CloseButton} {\n      display: block;\n    }\n\n    /* > ComponentIcon */\n    > div:first-child {\n      background: ${({ theme }) => theme.colors.primary200};\n      color: ${({ theme }) => theme.colors.primary600};\n\n      svg {\n        path {\n          fill: ${({ theme }) => theme.colors.primary600};\n        }\n      }\n    }\n  }\n`;\n\nexport const ComponentCard = ({\n  component,\n  dzName,\n  index,\n  isActive = false,\n  isInDevelopmentMode = false,\n  onClick,\n  forTarget,\n  targetUid,\n  disabled,\n}: ComponentCardProps) => {\n  const { components, removeComponentFromDynamicZone } = useDataManager();\n  const type = get(components, component);\n  const { icon, displayName } = type?.info || {};\n\n  const onClose = (e: MouseEvent<HTMLButtonElement>) => {\n    e.stopPropagation();\n    removeComponentFromDynamicZone({\n      forTarget,\n      targetUid,\n      dzName,\n      componentToRemoveIndex: index,\n    });\n  };\n\n  return (\n    <ComponentBox\n      alignItems=\"center\"\n      direction=\"column\"\n      className={isActive ? 'active' : ''}\n      borderRadius=\"borderRadius\"\n      justifyContent=\"center\"\n      paddingLeft={4}\n      paddingRight={4}\n      shrink={0}\n      onClick={onClick}\n      role=\"tab\"\n      tabIndex={isActive ? 0 : -1}\n      cursor=\"pointer\"\n      aria-selected={isActive}\n      aria-controls={`dz-${dzName}-panel-${index}`}\n      id={`dz-${dzName}-tab-${index}`}\n    >\n      <ComponentIcon icon={icon} isActive={isActive} />\n\n      <Box marginTop={1} maxWidth=\"100%\">\n        <Typography variant=\"pi\" fontWeight=\"bold\" ellipsis>\n          {displayName}\n        </Typography>\n      </Box>\n\n      {isInDevelopmentMode && !disabled && (\n        <CloseButton cursor=\"pointer\" tag=\"button\" onClick={onClose}>\n          <Cross />\n        </CloseButton>\n      )}\n    </ComponentBox>\n  );\n};\n"],"names":["CloseButton","styled","Box","theme","colors","primary600","ComponentBox","Flex","neutral200","neutral100","borderRadius","primary200","primary100","ComponentCard","component","dzName","index","isActive","isInDevelopmentMode","onClick","forTarget","targetUid","disabled","components","removeComponentFromDynamicZone","useDataManager","type","get","icon","displayName","info","onClose","e","stopPropagation","componentToRemoveIndex","_jsxs","alignItems","direction","className","justifyContent","paddingLeft","paddingRight","shrink","role","tabIndex","cursor","aria-selected","aria-controls","id","_jsx","ComponentIcon","marginTop","maxWidth","Typography","variant","fontWeight","ellipsis","tag","Cross"],"mappings":";;;;;;;;AAyBA,MAAMA,WAAAA,GAAcC,MAAAA,CAAOC,GAAAA,CAAI;;;;;;;;;;;YAWnB,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAACC,UAAU,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