<commit_before>/**
 * DashboardSharingSettings Module component.
 *
 * Site Kit by Google, Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import PropTypes from 'prop-types';
import { Tooltip } from '@material-ui/core';

/**
 * WordPress dependencies
 */
import { __, sprintf } from '@wordpress/i18n';
import { Icon, info } from '@wordpress/icons';
import {
	createInterpolateElement,
	useCallback,
	useEffect,
	useState,
} from '@wordpress/element';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import ModuleIcon from '../../ModuleIcon';
import { Select } from '../../../material-components';
import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants';
import { CORE_SITE } from '../../../googlesitekit/datastore/site/constants';
import UserRoleSelect from '../UserRoleSelect';
import SettingsOverlay from '../../settings/SettingsOverlay';
import { CORE_UI } from '../../../googlesitekit/datastore/ui/constants';
import {
	EDITING_MANAGEMENT_KEY,
	EDITING_USER_ROLES_KEY,
	SHARING_SETINGS_SAVING_KEY,
	SHARING_SETTINGS_SLUG_KEY,
} from './constants';
const { useSelect, useDispatch } = Data;

const viewAccessOptions = [
	{
		value: 'owner',
		label: __( 'Only Me', 'google-site-kit' ),
	},
	{
		value: 'all_admins',
		label: __( 'All Admins', 'google-site-kit' ),
	},
];

export default function Module( {
	moduleSlug,
	moduleName,
	management,
	ownerUsername,
	sharedOwnershipModule,
	hasOwnedModule,
} ) {
	const [ manageViewAccess, setManageViewAccess ] = useState( undefined );
	const module = useSelect( ( select ) =>
		select( CORE_MODULES ).getModule( moduleSlug )
	);
	const hasMultipleAdmins = useSelect( ( select ) =>
		select( CORE_SITE ).hasMultipleAdmins()
	);

	const isEditingUserRoles = useSelect( ( select ) =>
		select( CORE_UI ).getValue( EDITING_USER_ROLES_KEY )
	);
	// const isEditingManagement = useSelect( ( select ) =>
	// 	select( CORE_UI ).getValue( EDITING_MANAGEMENT_KEY )
	// );
	const editingModuleSlug = useSelect( ( select ) =>
		select( CORE_UI ).getValue( SHARING_SETTINGS_SLUG_KEY )
	);
	const isSaving = useSelect( ( select ) =>
		select( CORE_UI ).getValue( SHARING_SETINGS_SAVING_KEY )
	);

	const { setSharingManagement } = useDispatch( CORE_MODULES );
	const { setValue } = useDispatch( CORE_UI );

	useEffect( () => {
		setManageViewAccess( management );
	}, [ management ] );

	const handleOnChange = useCallback(
		( event ) => {
			setValue( EDITING_MANAGEMENT_KEY, true );
			setValue( SHARING_SETTINGS_SLUG_KEY, moduleSlug );
			setManageViewAccess( event.target.value );
			setSharingManagement( moduleSlug, event.target.value );
		},
		[ moduleSlug, setManageViewAccess, setSharingManagement, setValue ]
	);

	const isLocked =
		( moduleSlug !== editingModuleSlug && isEditingUserRoles ) ||
		// ( moduleSlug !== editingModuleSlug && isEditingManagement ) ||
		isSaving;

	return (
		<div
			className="googlesitekit-dashboard-sharing-settings__module googlesitekit-dashboard-sharing-settings__row"
			key={ moduleSlug }
		>
			{ /* Disable other modules when editing sharing settings for a module. */ }
			{ isLocked && <SettingsOverlay compress /> }

			<div className="googlesitekit-dashboard-sharing-settings__column--product">
				<ModuleIcon slug={ moduleSlug } size={ 48 } />

				<span className="googlesitekit-dashboard-sharing-settings__module-name">
					{ moduleName }
				</span>
			</div>

			<div className="googlesitekit-dashboard-sharing-settings__column--view"><commit_msg>Set all admins and disable management if shared ownership module.<commit_after>/**
 * DashboardSharingSettings Module component.
 *
 * Site Kit by Google, Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import PropTypes from 'prop-types';
import { Tooltip } from '@material-ui/core';

/**
 * WordPress dependencies
 */
import { __, sprintf } from '@wordpress/i18n';
import { Icon, info } from '@wordpress/icons';
import {
	createInterpolateElement,
	useCallback,
	useEffect,
	useState,
} from '@wordpress/element';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import ModuleIcon from '../../ModuleIcon';
import { Select } from '../../../material-components';
import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants';
import { CORE_SITE } from '../../../googlesitekit/datastore/site/constants';
import UserRoleSelect from '../UserRoleSelect';
import SettingsOverlay from '../../settings/SettingsOverlay';
import { CORE_UI } from '../../../googlesitekit/datastore/ui/constants';
import {
	EDITING_MANAGEMENT_KEY,
	EDITING_USER_ROLES_KEY,
	SHARING_SETINGS_SAVING_KEY,
	SHARING_SETTINGS_SLUG_KEY,
} from './constants';
const { useSelect, useDispatch } = Data;

const viewAccessOptions = [
	{
		value: 'owner',
		label: __( 'Only Me', 'google-site-kit' ),
	},
	{
		value: 'all_admins',
		label: __( 'All Admins', 'google-site-kit' ),
	},
];

export default function Module( {
	moduleSlug,
	moduleName,
	management,
	ownerUsername,
	sharedOwnershipModule,
	hasOwnedModule,
} ) {
	const [ manageViewAccess, setManageViewAccess ] = useState( undefined );
	const module = useSelect( ( select ) =>
		select( CORE_MODULES ).getModule( moduleSlug )
	);
	const hasMultipleAdmins = useSelect( ( select ) =>
		select( CORE_SITE ).hasMultipleAdmins()
	);

	const isEditingUserRoles = useSelect( ( select ) =>
		select( CORE_UI ).getValue( EDITING_USER_ROLES_KEY )
	);
	// const isEditingManagement = useSelect( ( select ) =>
	// 	select( CORE_UI ).getValue( EDITING_MANAGEMENT_KEY )
	// );
	const editingModuleSlug = useSelect( ( select ) =>
		select( CORE_UI ).getValue( SHARING_SETTINGS_SLUG_KEY )
	);
	const isSaving = useSelect( ( select ) =>
		select( CORE_UI ).getValue( SHARING_SETINGS_SAVING_KEY )
	);
	// const canSubmitSharingChanges = useSelect( ( select ) =>
	// 	select( CORE_MODULES ).canSubmitSharingChanges()
	// );

	const { setSharingManagement } = useDispatch( CORE_MODULES );
	const { setValue } = useDispatch( CORE_UI );

	useEffect( () => {
		if ( sharedOwnershipModule ) {
			setManageViewAccess( 'all_admins' );
		} else {
			setManageViewAccess( management );
		}
	}, [ management, sharedOwnershipModule ] );

	const handleOnChange = useCallback(
		( event ) => {
			setValue( EDITING_MANAGEMENT_KEY, true );
			setValue( SHARING_SETTINGS_SLUG_KEY, moduleSlug );
			setManageViewAccess( event.target.value );
			setSharingManagement( moduleSlug, event.target.value );
		},
		[ moduleSlug, setManageViewAccess, setSharingManagement, setValue ]
	);

	const isLocked =
		( moduleSlug !== editingModuleSlug && isEditingUserRoles ) || isSaving;

	return (
		<div
			className="googlesitekit-dashboard-sharing-settings__module googlesitekit-dashboard-sharing-settings__row"
			key={ moduleSlug }
		>
			{ /* Disable other modules when editing sharing settings for a module. */ }
			{ isLocked && <SettingsOverlay compress /> }

			<div className="googlesitekit-dashboard-sharing-settings__column--product">
				<ModuleIcon slug={ moduleSlug } size={ 48 } />

				<span className="googlesitekit-dashboard-sharing-settings__module-name">
					{ moduleName }
				</span>
			</div>

			<div className="googlesitekit-dashboard-sharing-settings__column--view">
{'fraction_non_alphanumeric': 0.12655651340996169, 'fraction_numerical': 0.0028735632183908046, 'mean_word_length': 4.204361370716511, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '984098', 'n_tokens_mistral': 2740, 'n_tokens_neox': 2635, 'n_words': 642}