{"size": 1024, "ext": "js", "max_stars_repo_path": "packages/styles/src/create-system/createSystem.js", "max_stars_repo_name": "fabiankaegy/g2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/styles/src/create-system/createSystem.js", "max_issues_repo_name": "fabiankaegy/g2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/styles/src/create-system/createSystem.js", "max_forks_repo_name": "fabiankaegy/g2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 17.3559322034, "max_line_length": 75, "alphanum_fraction": 0.626953125}
import baseGet from 'dash-get';

import { THEME } from '../theme';

/**
 * TODO: DEPRECATE THIS. NO LONGER NEEDED AS DYNAMIC STYLES
 * ARE HELD AS CSS VARIABLES.
 */

// Defaults
const __SYSTEM_CONFIG_DEFAULT__ = { ...THEME };

export const createSystem = (initialValue = __SYSTEM_CONFIG_DEFAULT__) => {
	const state = {
		lastGet: null,
	};
	const config = {};

	// Method to set value from system config store
	const set = (key, value) => {
		config[key] = value;
	};

	// Method to get value from system config store
	const get = (key) => {
		const value = baseGet(config, key);
		state.lastGet = { key, value };

		return value;
	};

	// Hydrate system config store with defaults
	for (const [key, value] of Object.entries(initialValue)) {
		if (key) {
			set(key, value);
		}
	}

	const getConfig = () => ({ ...config });

	const debug = () =>
		console.log({
			config,
			state,
		});

	const log = () => console.log(config);

	return {
		debug,
		get,
		getConfig,
		log,
		set,
	};
};

export default createSystem;
