// External Dependencies.
import React, { ReactElement } from 'react';

// Divi Dependencies.
import {
	ModuleContainer,
	ElementComponents,
} from '@divi/module';

// Local Dependencies.
import { ActiveFiltersEditProps } from './types';
import { ModuleStyles } from './styles';
import { convertAttributes } from '../../utils';
import { ModuleScriptData } from './module-script-data';
import { moduleClassnames } from './module-classnames';

declare global {
	interface Window {
		JetEngineDiviViews: any;
	}
}

/**
 * Static Module edit component of visual builder.
 *
 * @since ??
 *
 * @param {ActiveFiltersEditProps} props React component props.
 *
 * @returns {ReactElement}
 */
const ActiveFiltersEdit = (props: ActiveFiltersEditProps): ReactElement => {
	const {
		attrs,
		id,
		name,
		elements,
	} = props;
	const preparedAttrs = convertAttributes( attrs as Record<string, any> );
	const filtersLabel = preparedAttrs.filters_label || 'Active filters:';
	const fallback = (
		<div className="jet-smart-filters-active jet-active-filters jet-filter">
			<div className="jet-active-filters__title">{filtersLabel}</div>
			<div className="jet-active-filters__list">
				<div className="jet-active-filter">Category: Example</div>
				<div className="jet-active-filter">Price: $10–$50</div>
			</div>
		</div>
	);

	return (
		<ModuleContainer
			attrs={attrs}
			elements={elements}
			id={id}
			name={name}
			stylesComponent={ModuleStyles}
			classnamesFunction={moduleClassnames}
			scriptDataComponent={ModuleScriptData}
		>
			{elements.styleComponents({
				attrName: 'module',
			})}
			{
				<>
					<ElementComponents
						attrs={attrs?.module?.decoration ?? {}}
						id={id}
					/>
					{ fallback }
				</>
			}
		</ModuleContainer>
	);
}

export {
	ActiveFiltersEdit,
};
