"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.WorkpadConfig = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _var_config = require("../var_config");
var _constants = require("../../../common/lib/constants");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

const strings = {
  getApplyStylesheetButtonLabel: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.applyStylesheetButtonLabel', {
    defaultMessage: `Apply stylesheet`,
    description: '"stylesheet" refers to the collection of CSS style rules entered by the user.'
  }),
  getFlipDimensionAriaLabel: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.swapDimensionsAriaLabel', {
    defaultMessage: `Swap the page's width and height`
  }),
  getFlipDimensionTooltip: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.swapDimensionsTooltip', {
    defaultMessage: 'Swap the width and height'
  }),
  getGlobalCSSLabel: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.globalCSSLabel', {
    defaultMessage: `Global CSS overrides`
  }),
  getGlobalCSSTooltip: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.globalCSSTooltip', {
    defaultMessage: `Apply styles to all pages in this workpad`
  }),
  getNameLabel: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.nameLabel', {
    defaultMessage: 'Name'
  }),
  getPageHeightLabel: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.heightLabel', {
    defaultMessage: 'Height'
  }),
  getPageSizeBadgeAriaLabel: sizeName => _i18n.i18n.translate('xpack.canvas.workpadConfig.pageSizeBadgeAriaLabel', {
    defaultMessage: `Preset page size: {sizeName}`,
    values: {
      sizeName
    }
  }),
  getPageSizeBadgeOnClickAriaLabel: sizeName => _i18n.i18n.translate('xpack.canvas.workpadConfig.pageSizeBadgeOnClickAriaLabel', {
    defaultMessage: `Set page size to {sizeName}`,
    values: {
      sizeName
    }
  }),
  getPageWidthLabel: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.widthLabel', {
    defaultMessage: 'Width'
  }),
  getUSLetterButtonLabel: () => _i18n.i18n.translate('xpack.canvas.workpadConfig.USLetterButtonLabel', {
    defaultMessage: 'US Letter',
    description: 'This is referring to the dimensions of U.S. standard letter paper.'
  })
};
const WorkpadConfig = props => {
  const [css, setCSS] = (0, _react.useState)(props.css);
  const {
    size,
    name,
    setSize,
    setName,
    setWorkpadCSS,
    variables,
    setWorkpadVariables
  } = props;
  const rotate = () => setSize({
    width: size.height,
    height: size.width
  });
  const badges = [{
    name: '1080p',
    size: {
      height: 1080,
      width: 1920
    }
  }, {
    name: '720p',
    size: {
      height: 720,
      width: 1280
    }
  }, {
    name: 'A4',
    size: {
      height: 842,
      width: 590
    }
  }, {
    name: strings.getUSLetterButtonLabel(),
    size: {
      height: 792,
      width: 612
    }
  }];
  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, {
    label: strings.getNameLabel(),
    display: "rowCompressed"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFieldText, {
    compressed: true,
    value: name,
    onChange: e => setName(e.target.value),
    "data-test-subj": "canvas-workpad-name-text-field"
  })), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, {
    size: "s"
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, {
    gutterSize: "s",
    alignItems: "center"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, {
    label: strings.getPageWidthLabel(),
    display: "rowCompressed"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFieldNumber, {
    compressed: true,
    onChange: e => setSize({
      width: Number(e.target.value),
      height: size.height
    }),
    value: size.width
  }))), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, {
    grow: false
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, {
    display: "rowCompressed",
    hasEmptyLabelSpace: true
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiToolTip, {
    position: "bottom",
    content: strings.getFlipDimensionTooltip()
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiButtonIcon, {
    iconType: "merge",
    color: "text",
    onClick: rotate,
    "aria-label": strings.getFlipDimensionAriaLabel()
  })))), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, {
    label: strings.getPageHeightLabel(),
    display: "rowCompressed"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFieldNumber, {
    compressed: true,
    onChange: e => setSize({
      height: Number(e.target.value),
      width: size.width
    }),
    value: size.height
  })))), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, {
    size: "s"
  }), /*#__PURE__*/_react.default.createElement("div", null, badges.map((badge, i) => /*#__PURE__*/_react.default.createElement(_eui.EuiBadge, {
    key: `page-size-badge-${i}`,
    color: "hollow",
    onClick: () => setSize(badge.size),
    "aria-label": strings.getPageSizeBadgeAriaLabel(badge.name),
    onClickAriaLabel: strings.getPageSizeBadgeOnClickAriaLabel(badge.name)
  }, badge.name))), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, {
    size: "m"
  }), /*#__PURE__*/_react.default.createElement(_var_config.VarConfig, {
    variables: variables,
    setVariables: setWorkpadVariables
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: "canvasSidebar__expandable"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiAccordion, {
    id: "accordion-global-css",
    className: "canvasSidebar__accordion",
    style: {
      marginBottom: 0
    },
    buttonContent: /*#__PURE__*/_react.default.createElement(_eui.EuiToolTip, {
      content: strings.getGlobalCSSTooltip(),
      position: "left",
      className: "canvasArg__tooltip"
    }, /*#__PURE__*/_react.default.createElement("span", null, strings.getGlobalCSSLabel()))
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "canvasSidebar__accordionContent"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiTextArea, {
    "aria-label": strings.getGlobalCSSTooltip(),
    value: css,
    compressed: true,
    onChange: e => setCSS(e.target.value),
    rows: 10
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, {
    size: "s"
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiButton, {
    size: "s",
    onClick: () => setWorkpadCSS(css || _constants.DEFAULT_WORKPAD_CSS)
  }, strings.getApplyStylesheetButtonLabel()), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, {
    size: "xs"
  })))));
};
exports.WorkpadConfig = WorkpadConfig;
WorkpadConfig.propTypes = {
  size: _propTypes.default.object.isRequired,
  name: _propTypes.default.string.isRequired,
  css: _propTypes.default.string,
  variables: _propTypes.default.array,
  setSize: _propTypes.default.func.isRequired,
  setName: _propTypes.default.func.isRequired,
  setWorkpadCSS: _propTypes.default.func.isRequired,
  setWorkpadVariables: _propTypes.default.func.isRequired
};