import{dd as w,de as S,df as b,G as E,ao as c,y as h,dg as N,s as F,v as g,w as m,V as O,X as R,dh as x,f,a3 as z,ai as D,z as $,D as j,di as C,b9 as P}from"./index-BPRWoLf4.js";var y,A=w.named("MappingStore").props({fetching:!1,errorMsg:"",valueField:"value",map:S.frozen({})}).actions(function(d){var s=b(function(e,n,a){var r,t,i;return E(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,3,4]),d.fetching=!0,[4,e.fetcher(n,a)];case 1:if(r=o.sent(),r.ok)t=C(r.data),d.setMap(Array.isArray(t.options)?t.options:Array.isArray(t.items)?t.items:Array.isArray(t.records)?t.records:t);else throw new Error(r.msg||"fetch error");return[3,4];case 2:return i=o.sent(),d.errorMsg=i.message,[3,4];case 3:return d.fetching=!1,[7];case 4:return[2]}})});return{load:s,setMap:function(e){Array.isArray(e)&&(e=e.reduce(function(n,a){if(a==null)return n;if(c(a)){var r=Object.keys(a);r.length===1||r.length==2&&r.includes("$$id")?(r=r.filter(function(t){return t!=="$$id"}),n[r[0]]=a[r[0]]):r.length>1&&(n[a[d.valueField]]=a)}return n},{})),c(e)&&(d.map=h({},e))}}}),G=N(function(d){return A.create({id:P(),storeType:A.name},d.env)})((y=function(d){F(s,d);function s(e){var n=d.call(this,e)||this;return e.store.syncProps(e,void 0,["valueField","map"]),n}return s.prototype.componentDidMount=function(){this.reload()},s.prototype.componentDidUpdate=function(e){var n=this.props,a=this.props,r=a.store,t=a.source,i=a.data;if(r.syncProps(n,e,t?["valueField"]:["valueField","map"]),g(t)){var o=m(e.source,e.data,"| raw"),u=m(t,i,"| raw");o!==u&&r.setMap(u)}else O(e.source,n.source,e.data,n.data)&&this.reload()},s.prototype.reload=function(){var e,n=this.props,a=n.source,r=n.data,t=n.env,i=this.props.store;if(g(a))i.setMap(m(a,r,"| raw"));else if(R(a,r)){var o=x(a,"get");o.cache=(e=o.cache)!==null&&e!==void 0?e:30*1e3,i.load(t,o,r)}},s.prototype.renderSingleValue=function(e,n,a){var r,t=this.props,i=t.className,o=t.style,u=t.placeholder,v=t.classnames,l=t.store,V=f.createElement("span",{className:"text-muted"},u),p=l.map,_=void 0;e=typeof e=="string"?e.trim():e;var M=a?o:void 0;return typeof e<"u"&&p&&(_=(r=this.renderValue(p,e))!==null&&r!==void 0?r:e===!0&&p[1]?p[1]:e===!1&&p[0]?p[0]:p["*"])!==void 0&&(V=this.renderViewValue(_,e)),f.createElement("span",{key:"map-".concat(n),className:v("MappingField",i),style:M},V)},s.prototype.renderViewValue=function(e,n){var a=this.props,r=a.render,t=a.itemSchema,i=a.renderViewValue,o=a.data,u=a.labelField,v=a.name;if(i)return i(e,n);if(!t){var l=e;return c(e)&&(u===void 0||u===""?e.hasOwnProperty("type")?l=h({name:v},l):l=e.label:l=e[u||"label"]),c(l)&&l.type==="tag"&&!c(l.label)&&l.label!=null?r("mapping-tag",l,{value:null}):r("tpl",l)}return r("mappingItemSchema",t,h({data:z(o,c(e)?e:{item:e})},(t==null?void 0:t.type)==="tag"?{value:null}:{}))},s.prototype.renderValue=function(e,n){var a=this.props.renderValue;return a?a(e,n):e[n]},s.prototype.render=function(){var e=this,n=this.props,a=n.style,r=n.defaultValue,t=n.data,i=D(this.props);return r&&g(r)&&r===i&&(i=m(r,t,"| raw")),Array.isArray(i)?f.createElement("span",{style:a},i.map(function(o,u){return e.renderSingleValue(o,u)})):this.renderSingleValue(i,0,!0)},s}(f.Component),y.defaultProps={placeholder:"-",map:{"*":"通配值"}},y)),K=function(d){F(s,d);function s(){return d!==null&&d.apply(this,arguments)||this}return s.prototype.render=function(){return f.createElement(G,h({},this.props))},s=$([j({type:"mapping",alias:["map"],name:"mapping"})],s),s}(f.Component);export{G as MappingField,K as MappingFieldRenderer,A as Store};
