import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { columnType, tableType } from './types';
import { getTablePrimaryKey } from '../dbs';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function RefTableLink({
  dbName,
  tables,
  value,
  column
}) {
  const {
    referenceTable
  } = column;
  if (!referenceTable) {
    return null;
  }
  const referenceTablePrimaryKey = getTablePrimaryKey(tables, referenceTable);
  // TODO check existing, when exists then no Create button
  return /*#__PURE__*/_jsxs("span", {
    className: "dbm-ref-table-link",
    "data-dbm-component": "RefTableLink",
    children: [/*#__PURE__*/_jsx(Link, {
      to: `/${dbName}/${referenceTable}/create?${referenceTablePrimaryKey}=${value}`,
      children: "Create"
    }), ' ', "|", ' ', /*#__PURE__*/_jsx(Link, {
      to: `/${dbName}/${referenceTable}/update?${referenceTablePrimaryKey}=${value}`,
      children: "Update"
    }), ' ', "|", ' ', /*#__PURE__*/_jsx(Link, {
      to: `/${dbName}/${referenceTable}/get?${referenceTablePrimaryKey}=${value}`,
      children: "Get"
    })]
  });
}
export default RefTableLink;
RefTableLink.propTypes = {
  dbName: PropTypes.string.isRequired,
  tables: PropTypes.arrayOf(tableType).isRequired,
  column: columnType.isRequired,
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)])
};
RefTableLink.defaultProps = {
  value: null
};
//# sourceMappingURL=RefTableLink.js.map