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