import { __ } from '@wordpress/i18n';
import { useAnalyticsSettings } from '../SettingsStore';
import { Card, PageHeader, SettingRow, SettingsLayout, Select, SwitchRow } from '../controls';
import SheetPreview from '../preview/SheetPreview';

const TEXT_DOMAIN = 'stock-sync-with-google-sheet-for-woocommerce';

const VISIBILITY = [
	{ value: 'units', label: __( 'Only how many they sold', TEXT_DOMAIN ) },
	{ value: 'units_revenue', label: __( 'How many they sold and the income', TEXT_DOMAIN ) },
	{ value: 'units_revenue_earnings', label: __( 'Units, income and their earnings', TEXT_DOMAIN ) },
];

export function Vendors() {
	const { v, set } = useAnalyticsSettings();
	return (
		<SettingsLayout preview={ <SheetPreview page="vendors" /> }>
			<PageHeader
				title={ __( 'Vendors', TEXT_DOMAIN ) }
				description={ __( 'Give each vendor analytics for their own products.', TEXT_DOMAIN ) }
			/>
			<Card>
				<SwitchRow id="vendors.enabled" label={ __( 'Show analytics to vendors', TEXT_DOMAIN ) } checked={ v( 'vendors.enabled' ) } onChange={ set( 'vendors.enabled' ) } />
				<SettingRow id="vendors.visibility" label={ __( 'What vendors can see', TEXT_DOMAIN ) } help={ __( 'Vendors only ever see their own products.', TEXT_DOMAIN ) }>
					<Select id="vendors.visibility" value={ v( 'vendors.visibility' ) } onChange={ set( 'vendors.visibility' ) } options={ VISIBILITY } />
				</SettingRow>
			</Card>
		</SettingsLayout>
	);
}

export function Stores() {
	const { v, set } = useAnalyticsSettings();
	return (
		<SettingsLayout preview={ <SheetPreview page="stores" /> }>
			<PageHeader
				title={ __( 'Connected stores', TEXT_DOMAIN ) }
				description={ __( 'Other stores get one tab each, plus an “All stores” tab.', TEXT_DOMAIN ) }
			/>
			<Card>
				<SwitchRow id="stores.enabled" label={ __( 'Include my connected stores', TEXT_DOMAIN ) } checked={ v( 'stores.enabled' ) } onChange={ set( 'stores.enabled' ) } />
				<SettingRow id="stores.collect_time" label={ __( 'Gather store sales at', TEXT_DOMAIN ) } help={ __( 'Uses your store time.', TEXT_DOMAIN ) }>
					<input id="stores.collect_time" type="time" className="ssgsw-ui-input" value={ v( 'stores.collect_time' ) } onChange={ ( e ) => set( 'stores.collect_time' )( e.target.value ) } />
				</SettingRow>
			</Card>
		</SettingsLayout>
	);
}
