/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */

"use strict";(self.webpackChunk_nocobase_plugin_collection_fdw=self.webpackChunk_nocobase_plugin_collection_fdw||[]).push([["321"],{12:function(e,t,n){n.r(t),n.d(t,{RemoteTableSelect:function(){return s}});var r=n(156),o=n.n(r),a=n(721),l=n(505),u=n(772);function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,u=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(a.push(n.value),!t||a.length!==t);l=!0);}catch(e){u=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(u)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return c(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var s=(0,r.memo)(function(e){var t=e.remoteServerName,n=e.onChange,c=e.disabled,s=i((0,r.useState)([]),2),f=s[0],b=s[1],m=i((0,r.useState)(e.value),2),p=m[0],y=m[1],d=i((0,r.useState)(!1),2),h=d[0],v=d[1],O=(0,u.useAPIClient)(),g=(0,l.useForm)();return(0,r.useEffect)(function(){try{t?(v(!0),O.resource("databaseServers/".concat(t,"/tables")).list().then(function(t){var n=t.data;b(null==n?void 0:n.data.map(function(e){var t,n;return t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},f),n={customLabel:e.schema?"".concat(e.schema,".").concat(e.name):e.name},n=null!=n?n:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t})),y(e.value),v(!1)}).catch(function(e){console.error(e),v(!1)})):(b([]),g.setValuesIn("remoteTableName",null),null==n||n(null),y(null))}catch(e){console.log(e)}},[t]),o().createElement(a.Select,{virtual:!0,disabled:c,showSearch:!0,optionFilterProp:"customLabel",filterOption:function(e,t){return t.customLabel.toLowerCase().indexOf(e.toLowerCase())>=0},notFoundContent:h?o().createElement(a.Spin,null):o().createElement(a.Empty,{image:a.Empty.PRESENTED_IMAGE_SIMPLE}),options:f,value:p,onChange:function(e){if(e){var t=e.includes(".")?e.split("."):[null,e];g.setValuesIn("remoteTableName",e),g.setValuesIn("remoteTableInfo",{tableName:t[1],schema:t[0]}),null==n||n(e),y(e)}else g.setValuesIn("remoteTableName",null),g.setValuesIn("remoteTableInfo",{})},fieldNames:{label:"customLabel",value:"customLabel"},style:{width:"100%"}})})}}]);