"use strict";

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