import React, { useMemo } from 'react';
import { buttonFrom } from '../Button/utils.js';
import { LegacyCard } from '../LegacyCard/LegacyCard.js';
import { SettingAction } from '../SettingAction/SettingAction.js';
import { globalIdGeneratorFactory } from '../../utilities/unique-id/unique-id-factory.js';

const getUniqueSettingToggleId = globalIdGeneratorFactory('SettingToggle');
/**
 * @deprecated The SettingToggle component will be removed in v12.0.0.
 * See the "With primitive components" example to learn how to compose
 * setting toggles with layout and typography primitives.
 * https://polaris.shopify.com/components/deprecated/setting-toggle
 */

function SettingToggle({
  enabled,
  action,
  children
}) {
  const id = useMemo(getUniqueSettingToggleId, []);

  if (process.env.NODE_ENV === 'development') {
    // eslint-disable-next-line no-console
    console.warn(`Deprecation: <SettingToggle /> is deprecated. This component will be removed in a future major version of Polaris. Use the primitive layout and typography components to compose a setting toggle card.
      See the "With primitive components" example in https://polaris.shopify.com/components/deprecated/setting-toggle`);
  }

  const actionMarkup = action ? buttonFrom(action, {
    role: 'switch',
    id,
    ariaChecked: enabled ? 'true' : 'false',
    size: 'slim'
  }) : null;
  return /*#__PURE__*/React.createElement(LegacyCard, {
    sectioned: true
  }, /*#__PURE__*/React.createElement(SettingAction, {
    action: actionMarkup
  }, /*#__PURE__*/React.createElement("label", {
    htmlFor: id
  }, children)));
}

export { SettingToggle };
