import React, { useEffect, useState } from 'react' import { useTranslation } from 'next-i18next' import Switch from '~components/common/Switch' import GuidebookUnit from '../GuidebookUnit' import classNames from 'classnames' import type { SearchableObject } from '~types' import './index.scss' // Props interface Props { grid: GuidebookList editable: boolean offset: number removeGuidebook: (position: number) => void updateObject: (object: SearchableObject, position: number) => void } // Constants const EXTRA_WEAPONS_COUNT = 3 const GuidebooksGrid = ({ grid, editable, removeGuidebook, updateObject, }: Props) => { const { t } = useTranslation('common') const [enabled, setEnabled] = useState(false) const classes = classNames({ Guidebooks: true, ContainerItem: true, Disabled: !enabled, }) useEffect(() => { console.log('Grid updated') if (hasGuidebooks()) setEnabled(true) }, [grid]) function hasGuidebooks() { return grid && (grid[0] || grid[1] || grid[2]) } function onCheckedChange(checked: boolean) { setEnabled(checked) } const enabledElement = (