/**
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","ojs/ojdatasource-common","ojs/ojrowexpander"],function(b){b.df=function(f,a,d,c,e){b.l.oy(d);this.Zb=f;this.re=a;this.vE=d;this.zb=c;this.Cg=e};o_("FlattenedTreeHeaderSet",b.df,b);b.df.prototype.getData=function(f,a){var d;b.l.assert(f<=this.re&&f>=this.Zb,"index out of bounds");b.l.assert(null==a||0==a,"level out of bounds");return null!=this.Cg&&null!=this.zb?(d=this.zb.getData(f-this.Zb+this.zb.ta()),null!=d?d.get?d.get(this.Cg):d[this.Cg]:null):this.vE[f]};b.b.g("FlattenedTreeHeaderSet.prototype.getData",
{getData:b.df.prototype.getData});b.df.prototype.getMetadata=function(f,a){b.l.assert(f<=this.re&&f>=this.Zb,"index out of bounds");b.l.assert(null==a||0==a,"level out of bounds");return null!=this.Cg&&null!=this.zb?this.zb.getMetadata(f-this.Zb+this.zb.ta()):{key:this.getData(f)}};b.b.g("FlattenedTreeHeaderSet.prototype.getMetadata",{getMetadata:b.df.prototype.getMetadata});b.df.prototype.R=function(){return null!=this.Cg&&null!=this.zb?Math.min(this.zb.R(),this.re-this.Zb):Math.max(0,this.re-this.Zb)};
b.b.g("FlattenedTreeHeaderSet.prototype.getCount",{R:b.df.prototype.R});b.df.prototype.wg=function(){return 0<this.R()?1:0};b.b.g("FlattenedTreeHeaderSet.prototype.getLevelCount",{wg:b.df.prototype.wg});b.df.prototype.Ub=function(f,a){b.l.assert(f<=this.re&&f>=this.Zb,"index out of bounds");b.l.assert(null==a||0==a,"level out of bounds");return{extent:1,more:{before:!1,after:!1}}};b.b.g("FlattenedTreeHeaderSet.prototype.getExtent",{Ub:b.df.prototype.Ub});b.df.prototype.le=function(f,a){b.l.assert(f<=
this.re&&f>=this.Zb,"index out of bounds");b.l.assert(null==a||0==a,"level out of bounds");return 1};b.b.g("FlattenedTreeHeaderSet.prototype.getDepth",{le:b.df.prototype.le});b.Xh=function(f,a,d,c,e,g){b.l.oy(g);this.Mi=f;this.pr=a;this.al=d;this.or=c;this.zb=e;this.Sd=g};o_("FlattenedTreeCellSet",b.Xh,b);b.Xh.prototype.getData=function(f){var a;a=this.GW(f);if(null==a)return null;f=a[0];a=a[1];b.l.assert(f<this.zb.ta()+this.zb.R()&&a<this.Sd.length);a=this.Sd[a];f=this.zb.getData(f);return null!=
f?f.get?f.get(a):f[a]:null};b.b.g("FlattenedTreeCellSet.prototype.getData",{getData:b.Xh.prototype.getData});b.Xh.prototype.getMetadata=function(f){var a;a=this.GW(f);if(null==a)return null;f=a[0];a=a[1];b.l.assert(f<this.zb.ta()+this.zb.R()&&a<this.Sd.length);a=this.Sd[a];f=this.zb.getMetadata(f);f.keys={row:f.key,column:a};return f};b.b.g("FlattenedTreeCellSet.prototype.getMetadata",{getMetadata:b.Xh.prototype.getMetadata});b.Xh.prototype.GW=function(f){var a;b.l.Ff(f);if(null==this.zb||0==this.zb.length)return null;
a=f.row-this.Mi+this.zb.ta();f=f.column;b.l.em(a,null);b.l.em(f,null);b.l.assert(0<=a&&0<=f);return[a,f]};b.Xh.prototype.ta=function(b){return"row"===b?this.Mi:"column"===b?this.al:0};b.b.g("FlattenedTreeCellSet.prototype.getStart",{ta:b.Xh.prototype.ta});b.Xh.prototype.R=function(b){return"row"===b?Math.min(this.pr-this.Mi,this.zb.R()):"column"===b?this.or-this.al:0};b.b.g("FlattenedTreeCellSet.prototype.getCount",{R:b.Xh.prototype.R});b.ab=function(f,a){b.ab.q.constructor.call(this,f,a)};o_("FlattenedTreeDataGridDataSource",
b.ab,b);b.b.ga(b.ab,b.ca,"oj.FlattenedTreeDataGridDataSource");b.ab.prototype.Init=function(){b.ab.q.Init.call(this);this.Sd=b.ab.q.Dy.call(this,"columns");this.Cg=b.ab.q.Dy.call(this,"rowHeader")};b.b.g("FlattenedTreeDataGridDataSource.prototype.Init",{Init:b.ab.prototype.Init});b.ab.prototype.ug=function(b){return"row"===b?"estimate":"actual"};b.b.g("FlattenedTreeDataGridDataSource.prototype.getCountPrecision",{ug:b.ab.prototype.ug});b.ab.prototype.R=function(b){return"row"===b?-1:"column"===b?
this.Sd.length:0};b.b.g("FlattenedTreeDataGridDataSource.prototype.getCount",{R:b.ab.prototype.R});b.ab.prototype.If=function(f,a,d){var c,e;c=f.axis;if("column"===c)c=f.start+f.count,c>this.R("column")&&(c=this.R("column")-f.start),e=new b.df(f.start,c,this.Sd);else if("row"===c){if(null!=this.Cg){this.Zk={range:f,callbacks:a,callbackObjects:d};return}e=new b.Fd(f.start,f.start,c,null)}null!=e&&null!=a&&null!=a.success&&(null==d&&(d={}),a.success.call(d.success,e,f))};b.b.g("FlattenedTreeDataGridDataSource.prototype.fetchHeaders",
{If:b.ab.prototype.If});b.ab.prototype.tg=function(f,a,d){var c,e,g,h;for(c=0;c<f.length;c++)if(e=f[c],"row"==e.axis){g=e.start;h=e.count;break}b.ab.q.Ho.call(this,{start:g,count:h},{success:function(b){this.PJ(b,f,a,d,0)}.bind(this),error:function(b){this.kfa(b,{start:g,count:h},a,d)}.bind(this)})};b.b.g("FlattenedTreeDataGridDataSource.prototype.fetchCells",{tg:b.ab.prototype.tg});b.ab.prototype.keys=function(f){var a,d;a=f.row;d=f.column;return new Promise(function(c){a>b.ab.q.Zna.call(this).end||
d>this.Sd.length?c(null):c({row:b.ab.q.getKey.call(this,a),column:this.Sd[d]})}.bind(this))};b.b.g("FlattenedTreeDataGridDataSource.prototype.keys",{keys:b.ab.prototype.keys});b.ab.prototype.zg=function(f){var a,d,c,e,g;c=f.row;e=f.column;return new Promise(function(f){a=b.ab.q.Ii.call(this,c);for(g=0;g<this.Sd.length;g++)if(this.Sd[g]===e){d=g;break}0<=a||0<=d?f({row:a,column:d}):f(null)}.bind(this))};b.b.g("FlattenedTreeDataGridDataSource.prototype.indexes",{zg:b.ab.prototype.zg});b.ab.prototype.sort=
function(f,a,d){return b.ab.q.getWrappedDataSource.call(this).sort(f,{success:function(){this.Rfa(a,d)}.bind(this),error:a.error})};b.b.g("FlattenedTreeDataGridDataSource.prototype.sort",{sort:b.ab.prototype.sort});b.ab.prototype.Rfa=function(b,a){this.refresh();b.success&&(null==a&&(a={}),b.success.call(a.success))};b.ab.prototype.move=function(f,a,d,c){b.ab.q.getWrappedDataSource.call(this).move(f,a,d,c)};b.b.g("FlattenedTreeDataGridDataSource.prototype.move",{move:b.ab.prototype.move});b.ab.prototype.getCapability=
function(f){return"default"===b.ab.q.getWrappedDataSource.call(this).getCapability(f)?"column":"none"};b.b.g("FlattenedTreeDataGridDataSource.prototype.getCapability",{getCapability:b.ab.prototype.getCapability});b.ab.prototype.Ky=function(f,a){b.ab.q.Ky.call(this,f,a)};b.ab.prototype.PJ=function(f,a,d,c){var e,g,h,k,l,m;for(e=0;e<a.length;e++)g=a[e],"row"==g.axis?(h=g.start,k=g.count):"column"==g.axis&&(l=g.start,m=g.count,l+m>this.R("column")&&(m=this.R("column")-l));this.Zk&&(e=this.Zk.range,e.start==
h&&e.count==k&&this.VJ(f,e,this.Zk.callbacks,this.Zk.callbackObjects),this.Zk=null);f=new b.Xh(h,h+k,l,l+m,f,this.Sd);d.success&&(null==c&&(c={}),d.success.call(c.success,f,a))};b.ab.prototype.kfa=function(b,a,d,c){var e;this.Zk&&(e=this.Zk.range,e.start==a.start&&e.count==a.count&&(a=this.Zk.callbacks,e=this.Zk.callbackObjects,a.error&&(null==e&&(e={}),a.error.call(e.error,b))),this.Zk=null);d.error&&(null==c&&(c={}),d.success.call(c.error,b))};b.ab.prototype.VJ=function(f,a,d,c){f=new b.df(a.start,
a.start+a.count,this.Sd,f,this.Cg);d.success&&(null==c&&(c={}),d.success.call(c.success,f,a))};b.ab.prototype.nE=function(f,a,d){var c,e,g,h;c=null;this.Cg&&(c=new b.df(f,f+d.R(),this.Sd,d,this.Cg));a=new b.Xh(f,f+d.R(),0,this.Sd.length,d,this.Sd);g=[];h=[];for(e=0;e<d.R();e++)g.push({row:this.Yg(f+e).key}),h.push({row:f+e,column:-1});f={source:this,operation:"insert"};f.result=a;c&&(f.header=c);f.keys=g;f.indexes=h;b.ab.q.handleEvent.call(this,"change",f)};b.ab.prototype.ME=function(f){var a,d,c;
a=[];c=[];for(d=0;d<f.length;d++)a.push({row:f[d].key}),c.push({row:f[d].index,column:-1});f={source:this,operation:"delete"};f.keys=a;f.indexes=c;b.ab.q.handleEvent.call(this,"change",f)};b.ab.prototype.TN=function(f,a){a.success.call(null,new b.Pe(null,f.start))}});