"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.privacySettingConfigs = exports.default = exports.PrivacySettingsDialog = void 0;
var _PrivacySettingsTable = _interopRequireDefault(require("./PrivacySettingsTable"));
var _index = require("../Button/index");
var _index2 = require("../Dialog/index");
var _privacySettings = require("./privacySettings");
var _i18n = require("../i18n");
var _react = require("react");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const privacySettingConfigs = [{
  settingsKey: 'c3',
  translationKey: 'advertising'
}, {
  settingsKey: 'c4',
  translationKey: 'socialMedia'
}, {
  settingsKey: 'c2',
  translationKey: 'webAnalytics'
}];
exports.privacySettingConfigs = privacySettingConfigs;
/**
 * The PrivacySettingsDialog allows users to adjust their privacy settings.
 * Typically these settings are accessed from a button in the footer of a CMS
 * website. Props allow for customizing on a per-domain basis.
 */
const PrivacySettingsDialog = props => {
  const [localPrivacySettings, setLocalPrivacySettings] = (0, _react.useState)((0, _privacySettings.getPrivacySettings)());
  function setPrivacySetting(settingsKey, value) {
    setLocalPrivacySettings({
      ...localPrivacySettings,
      [settingsKey]: value
    });
  }
  function savePrivacySettings() {
    (0, _privacySettings.setPrivacySettings)(localPrivacySettings);
    props.onExit();
  }
  const {
    domain,
    privacyPolicyUrl,
    thirdPartyPoliciesUrl,
    ...dialogProps
  } = props;
  const privacySettingsProperties = privacySettingConfigs.map(config => ({
    ...config,
    value: localPrivacySettings[config.settingsKey]
  }));
  let intro = (0, _i18n.t)('privacy.introText', {
    domain
  });
  intro += ' ' + (0, _i18n.t)('privacy.privacyPolicy', {
    url: privacyPolicyUrl
  });
  if (thirdPartyPoliciesUrl) {
    intro += ' ' + (0, _i18n.t)('privacy.thirdPartyPolicies', {
      url: thirdPartyPoliciesUrl
    });
  }
  intro += '.';
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index2.Dialog, {
    ...dialogProps,
    heading: (0, _i18n.t)('privacy.dialogTitle', {
      domain
    }),
    size: "full",
    actions: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Button, {
      variation: "solid",
      onClick: savePrivacySettings,
      children: (0, _i18n.t)('privacy.save')
    }),
    isOpen: props.isOpen,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
      className: "ds-u-margin-top--0",
      dangerouslySetInnerHTML: {
        __html: intro
      }
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PrivacySettingsTable.default, {
      domain: domain,
      privacySettings: privacySettingsProperties,
      setPrivacySetting: setPrivacySetting
    })]
  });
};
exports.PrivacySettingsDialog = PrivacySettingsDialog;
var _default = PrivacySettingsDialog;
exports.default = _default;