"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.PrivacySettingsTable = void 0;
var _compat = _interopRequireDefault(require("preact/compat"));
var _index = require("../ChoiceList/index");
var _index2 = require("../Table/index");
var _i18n = require("../i18n");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var PrivacySettingsTable = function PrivacySettingsTable(_ref) {
  var domain = _ref.domain,
    privacySettings = _ref.privacySettings,
    setPrivacySetting = _ref.setPrivacySetting;
  function renderToggle(settingsKey, value, category, description) {
    var choices = [{
      label: (0, _i18n.t)('privacy.allow'),
      value: '0',
      checked: value === '0'
    }, {
      label: (0, _i18n.t)('privacy.dontAllow'),
      value: '1',
      checked: value === '1'
    }];
    var label = /*#__PURE__*/_compat.default.createElement("span", {
      className: "ds-u-visibility--screen-reader"
    }, category);
    return /*#__PURE__*/_compat.default.createElement(_index.ChoiceList, {
      type: "radio",
      choices: choices,
      onChange: function onChange(event) {
        setPrivacySetting(settingsKey, event.target.value);
      },
      className: "ds-u-margin-top--0",
      label: label,
      "aria-label": description,
      name: "cookie-".concat(settingsKey)
    });
  }
  var categoryHeaderId = 'privacy-settings-header-category';
  var descriptionHeaderId = 'privacy-settings-header-description';
  var statusHeaderId = 'privacy-settings-header-status';
  function renderRow(_ref2) {
    var settingsKey = _ref2.settingsKey,
      translationKey = _ref2.translationKey,
      value = _ref2.value;
    var category = (0, _i18n.t)("privacy.".concat(translationKey, ".category"));
    var description = (0, _i18n.t)("privacy.".concat(translationKey, ".description"), {
      domain: domain
    });
    return /*#__PURE__*/_compat.default.createElement(_index2.TableRow, {
      key: settingsKey
    }, /*#__PURE__*/_compat.default.createElement(_index2.TableCell, {
      headers: categoryHeaderId,
      stackedTitle: (0, _i18n.t)('privacy.category')
    }, category), /*#__PURE__*/_compat.default.createElement(_index2.TableCell, {
      headers: descriptionHeaderId,
      stackedTitle: (0, _i18n.t)('privacy.description')
    }, description), /*#__PURE__*/_compat.default.createElement(_index2.TableCell, {
      headers: statusHeaderId,
      stackedTitle: (0, _i18n.t)('privacy.status')
    }, renderToggle(settingsKey, value, category, description)));
  }
  return /*#__PURE__*/_compat.default.createElement(_index2.Table, {
    className: "ds-c-privacy-settings-table ds-u-margin-top--2 ds-u-lg-margin--0",
    borderless: true,
    stackable: true,
    stackableBreakpoint: "md"
  }, /*#__PURE__*/_compat.default.createElement(_index2.TableHead, null, /*#__PURE__*/_compat.default.createElement(_index2.TableRow, null, /*#__PURE__*/_compat.default.createElement(_index2.TableCell, {
    id: categoryHeaderId
  }, (0, _i18n.t)('privacy.category')), /*#__PURE__*/_compat.default.createElement(_index2.TableCell, {
    id: descriptionHeaderId
  }, (0, _i18n.t)('privacy.description')), /*#__PURE__*/_compat.default.createElement(_index2.TableCell, {
    id: statusHeaderId
  }, (0, _i18n.t)('privacy.status')))), /*#__PURE__*/_compat.default.createElement(_index2.TableBody, null, privacySettings.map(renderRow)));
};
exports.PrivacySettingsTable = PrivacySettingsTable;
var _default = PrivacySettingsTable;
exports.default = _default;