'use client' import type { ResourceOpenScope } from '@/models/access-control' import { memo, useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import OpenScopeConfirmDialog from './open-scope-confirm-dialog' import OpenScopeOption from './open-scope-option' import TitleInfotip from './title-infotip' type ResourceOpenScopeSectionProps = { value?: ResourceOpenScope disabled: boolean onChange?: (openScope: ResourceOpenScope) => void } function ResourceOpenScopeSection({ value, disabled, onChange, }: ResourceOpenScopeSectionProps) { const { t } = useTranslation() const [pendingOpenScope, setPendingOpenScope] = useState(null) const resourceOpenScopeDescription = t('accessRule.resourceOpenScopeDescription', { ns: 'permission' }) const handleRequestChange = useCallback((nextOpenScope: ResourceOpenScope) => { if (nextOpenScope === value) return setPendingOpenScope(nextOpenScope) }, [value]) const handleCancelChange = useCallback(() => { setPendingOpenScope(null) }, []) const handleConfirmChange = useCallback(() => { if (!pendingOpenScope) return onChange?.(pendingOpenScope) setPendingOpenScope(null) }, [onChange, pendingOpenScope]) return (

{t('accessRule.resourceOpenScope', { ns: 'permission' })}

) } export default memo(ResourceOpenScopeSection)