"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.prefixFieldWithUserFieldsNamespace = exports.prefixFieldWithNamespace = void 0;
exports.simplifyExtendedColumns = simplifyExtendedColumns;
var _react = _interopRequireDefault(require("react"));
var _ExtendedColumn = require("../components/ExtendedColumn/ExtendedColumn");
var _fieldTypePrefixIcons = require("../utils/fieldTypePrefixIcons");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/state/simplifyExtendedColumns.tsx";
const ExtendedColumnsConfig = {
  shortText: {
    width: '150px',
    align: 'start'
  },
  dateTime: {
    width: '200px',
    align: 'center'
  },
  date: {
    width: '150px',
    align: 'center'
  },
  decimal: {
    width: '100px',
    align: 'center'
  },
  integer: {
    width: '100px',
    align: 'center'
  },
  checkbox: {
    width: '100px',
    align: 'center'
  },
  longText: {
    width: '250px',
    align: 'start'
  },
  url: {
    width: '250px',
    align: 'start'
  },
  dropdown: {
    width: '150px',
    align: 'start'
  },
  files: {
    width: '180px',
    align: 'start'
  },
  multiSelect: {
    width: '150px',
    align: 'start'
  }
};
const prefixFieldWithNamespace = (id, namespace) => `extendedFields.namespaces.${namespace}.${id}`;
exports.prefixFieldWithNamespace = prefixFieldWithNamespace;
const prefixFieldWithUserFieldsNamespace = id => prefixFieldWithNamespace(id, '_user_fields');
exports.prefixFieldWithUserFieldsNamespace = prefixFieldWithUserFieldsNamespace;
function simplifyExtendedColumns({
  fields,
  toExtendedFields,
  defaultHidden,
  getSchemaField
}) {
  return fields.map(field => {
    var _schemaField$xWixPi;
    const type = field.type;
    const id = prefixFieldWithNamespace(field.id, field.namespace);
    const schemaField = getSchemaField == null ? void 0 : getSchemaField(field.namespace, field.id);
    const isPii = field.isPii ?? Boolean(schemaField == null || (_schemaField$xWixPi = schemaField['x-wix-pii']) == null ? void 0 : _schemaField$xWixPi.enabled);
    return {
      dataExtension: field,
      id,
      dataHook: id,
      name: field.label || field.id,
      title: field.label || field.id,
      hideable: true,
      sortable: field.filterable,
      defaultHidden: defaultHidden || field.owner !== 'user',
      fieldType: type ? (0, _fieldTypePrefixIcons.toFieldType)(type) : undefined,
      isPii,
      align: type ? ExtendedColumnsConfig[type].align : undefined,
      width: type ? ExtendedColumnsConfig[type].width : undefined,
      style: type ? ExtendedColumnsConfig[type].style : undefined,
      render: row => {
        var _toExtendedFields;
        const value = toExtendedFields == null || (_toExtendedFields = toExtendedFields(row)) == null || (_toExtendedFields = _toExtendedFields.namespaces) == null || (_toExtendedFields = _toExtendedFields[field.namespace]) == null ? void 0 : _toExtendedFields[field.id];
        return /*#__PURE__*/_react.default.createElement(_ExtendedColumn.ExtendedColumn, {
          type: type,
          value: value,
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 101,
            columnNumber: 16
          }
        });
      }
    };
  });
}
//# sourceMappingURL=simplifyExtendedColumns.js.map