"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CustomColumnsCTAButton = void 0;
exports._CustomColumnsCTAButton = _CustomColumnsCTAButton;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _bexCore = require("@wix/bex-core");
var _mobxReactLite = require("mobx-react-lite");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _CustomColumnsPanelEntry = require("./CustomColumnsPanelEntry");
var _bi = require("@wix/bex-core/bi");
var _ResponsiveButton = require("../ResponsiveButton/ResponsiveButton");
var _SchemaContext = require("../../providers/SchemaContext");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomColumnsPanel/CustomColumnsCTAButton.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _CustomColumnsCTAButton({
  state,
  onColumnClick,
  dragAndDrop
}) {
  const {
    container: {
      translate: t,
      experiments
    },
    toolbar: {
      responsive
    }
  } = state;
  const analyticsButtonDiscoverability = experiments == null ? void 0 : experiments.get('specs.analytics.CustomColumnsWithLabelAndNewIcon');
  (0, _react.useEffect)(() => {
    _CustomColumnsPanelEntry.CustomColumnsPanelEntry.CustomColumnsDragAndDrop = dragAndDrop;
    state.panels.registerSidePanel('customColumns', _CustomColumnsPanelEntry.CustomColumnsPanelEntry);
  }, []);
  (0, _react.useEffect)(() => {
    if (state.customColumnsState) {
      state.customColumnsState.onColumnClick = onColumnClick;
    }
  }, [onColumnClick, state.customColumnsStateInitialized]);
  const schemaCtx = (0, _SchemaContext.useSchemaContext)();
  const isSchema = !!(schemaCtx != null && schemaCtx.schema);
  const isEditable = !!state.collectionDataExtension || isSchema;
  const text = t(isEditable ? 'cairo.table.manage-fields.button.cta' : 'cairo.table.custom-columns.button.cta');
  const props = {
    size: 'small',
    priority: 'secondary',
    dataHook: 'custom-columns-button',
    onClick: () => {
      const isOpened = state.panels.toggleSidePanel('customColumns');
      state.reportBi((0, _bexCore.withoutDefaults)(_bi.cairoFiltersPanelUsed)({
        isOpened,
        feature: 'Custom Columns',
        origin: 'Custom Columns CTA'
      }));
    }
  };
  const getButton = () => {
    if (analyticsButtonDiscoverability === 'b' || analyticsButtonDiscoverability === 'c') {
      return /*#__PURE__*/_react.default.createElement(_designSystem.Button, (0, _extends2.default)({}, props, {
        prefixIcon: analyticsButtonDiscoverability === 'b' ? /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.AdjustSmall, {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 80,
            columnNumber: 15
          }
        }) : /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.TableChartSmall, {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 82,
            columnNumber: 15
          }
        }),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 76,
          columnNumber: 9
        }
      }), text);
    }
    return /*#__PURE__*/_react.default.createElement(_ResponsiveButton.ResponsiveButton, (0, _extends2.default)({
      state: responsive.actions,
      icon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.AdjustSmall, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 94,
          columnNumber: 15
        }
      })
    }, props, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 92,
        columnNumber: 7
      }
    }), text);
  };
  return getButton();
}
const CustomColumnsCTAButton = exports.CustomColumnsCTAButton = (0, _mobxReactLite.observer)(_CustomColumnsCTAButton);
//# sourceMappingURL=CustomColumnsCTAButton.js.map