// Compiled by ClojureScript 1.9.562 {}
goog.provide('weathergen.ui.trees');
goog.require('cljs.core');
goog.require('weathergen.ui.common');
goog.require('taoensso.timbre');
goog.require('javelin.core');
goog.require('hoplon.jquery');
goog.require('hoplon.core');
/**
 * Helper function for the tree control.
 */
weathergen.ui.trees.tree_STAR_ = (function weathergen$ui$trees$tree_STAR_(expand_state,levels,items,level_number){
var vec__36445 = levels;
var seq__36446 = cljs.core.seq.call(null,vec__36445);
var first__36447 = cljs.core.first.call(null,seq__36446);
var seq__36446__$1 = cljs.core.next.call(null,seq__36446);
var level = first__36447;
var more_levels = seq__36446__$1;
var map__36448 = level;
var map__36448__$1 = ((((!((map__36448 == null)))?((((map__36448.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__36448.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__36448):map__36448);
var formatter = cljs.core.get.call(null,map__36448__$1,new cljs.core.Keyword(null,"formatter","formatter",-483008823));
var children = cljs.core.get.call(null,map__36448__$1,new cljs.core.Keyword(null,"children","children",-940561982));
var attrs = cljs.core.get.call(null,map__36448__$1,new cljs.core.Keyword(null,"attrs","attrs",-2090668713));
return weathergen.ui.common.styled.call(null,new cljs.core.Keyword(null,"garden","garden",-1966516149),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"li","li",723558921),new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"margin-left","margin-left",2015598377),"-28px"], null)], null),hoplon.core.ol.call(null,new cljs.core.Keyword(null,"css","css",1135045163),new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"list-style-type","list-style-type",-1703248598),"none"], null),hoplon.core.loop_tpl_STAR_.call(null,items,((function (vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (item__29615__auto__){
var vec__36450 = javelin.core.cell_map.call(null,cljs.core.identity,javelin.core.formula.call(null,((function (vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (item){
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [item], null);
});})(vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
).call(null,item__29615__auto__));
var item = cljs.core.nth.call(null,vec__36450,(0),null);
var kids = (cljs.core.truth_(children)?children.call(null,item):javelin.core.cell.call(null,null));
var expanded_QMARK_ = javelin.core.cell.call(null,true);
hoplon.core.do_watch.call(null,expand_state,((function (kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (_,n){
if(cljs.core._EQ_.call(null,n,new cljs.core.Keyword(null,"all-expanded","all-expanded",1437674225))){
return cljs.core.reset_BANG_.call(null,expanded_QMARK_,true);
} else {
if(cljs.core._EQ_.call(null,n,new cljs.core.Keyword(null,"all-collapsed","all-collapsed",437702622))){
return cljs.core.reset_BANG_.call(null,expanded_QMARK_,false);
} else {
if(cljs.core._EQ_.call(null,cljs.core.first.call(null,n),new cljs.core.Keyword(null,"expand-through-level","expand-through-level",-1840001384))){
var e = (level_number < cljs.core.second.call(null,n));
return cljs.core.reset_BANG_.call(null,expanded_QMARK_,e);
} else {
return null;
}
}
}
});})(kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
);

return hoplon.core.li.call(null,(cljs.core.truth_(attrs)?attrs.call(null,item):cljs.core.PersistentArrayMap.EMPTY),weathergen.ui.common.inl.call(null,weathergen.ui.common.inl.call(null,new cljs.core.Keyword(null,"css","css",1135045163),new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"width","width",-384071477),"15px",new cljs.core.Keyword(null,"font-size","font-size",-1847940346),"120%",new cljs.core.Keyword(null,"vertical-align","vertical-align",651007333),"top"], null),(function (){var con__29625__auto__ = (new cljs.core.Delay(((function (kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (){
return hoplon.core.div.call(null,new cljs.core.Keyword(null,"css","css",1135045163),new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"display","display",242065432),"inline-block",new cljs.core.Keyword(null,"cursor","cursor",1011937484),"pointer",new cljs.core.Keyword(null,"position","position",-2011731912),"relative",new cljs.core.Keyword(null,"background","background",-863952629),"white"], null),new cljs.core.Keyword(null,"click","click",1912301393),((function (kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (){
return javelin.core.dosync_STAR_.call(null,((function (kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (){
cljs.core.swap_BANG_.call(null,expanded_QMARK_,cljs.core.not);

return cljs.core.reset_BANG_.call(null,expand_state,null);
});})(kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
);
});})(kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
,hoplon.core.div.call(null,new cljs.core.Keyword(null,"css","css",1135045163),javelin.core.formula.call(null,((function (kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (expanded_QMARK___$1){
return new cljs.core.PersistentArrayMap(null, 8, [new cljs.core.Keyword(null,"display","display",242065432),"inline-block",new cljs.core.Keyword(null,"width","width",-384071477),(0),new cljs.core.Keyword(null,"height","height",1025178622),(0),new cljs.core.Keyword(null,"border-left","border-left",-1150760178),"5px solid transparent",new cljs.core.Keyword(null,"border-right","border-right",-668932860),"5px solid transparent",new cljs.core.Keyword(null,"border-top","border-top",-158897573),"7px solid black",new cljs.core.Keyword(null,"vertical-align","vertical-align",651007333),"middle",new cljs.core.Keyword(null,"transform","transform",1381301764),[cljs.core.str.cljs$core$IFn$_invoke$arity$1("rotate("),cljs.core.str.cljs$core$IFn$_invoke$arity$1((cljs.core.truth_(expanded_QMARK___$1)?(0):(-90))),cljs.core.str.cljs$core$IFn$_invoke$arity$1("deg)")].join('')], null);
});})(kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
).call(null,expanded_QMARK_)));
});})(kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
,null));
var alt__29626__auto__ = (new cljs.core.Delay(((function (con__29625__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (){
return "";
});})(con__29625__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
,null));
var tpl__29627__auto__ = ((function (con__29625__auto__,alt__29626__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (p__29628__auto__){
return cljs.core.deref.call(null,(function (){var or__23148__auto__ = (cljs.core.truth_(p__29628__auto__)?con__29625__auto__:alt__29626__auto__);
if(cljs.core.truth_(or__23148__auto__)){
return or__23148__auto__;
} else {
return cljs.core.atom.call(null);
}
})());
});})(con__29625__auto__,alt__29626__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
;
return javelin.core.formula.call(null,tpl__29627__auto__).call(null,javelin.core.formula.call(null,((function (con__29625__auto__,alt__29626__auto__,tpl__29627__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (G__36453,G__36454){
return G__36453.call(null,G__36454);
});})(con__29625__auto__,alt__29626__auto__,tpl__29627__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
).call(null,cljs.core.seq,kids));
})()),formatter.call(null,expanded_QMARK_,item)),(function (){var con__29625__auto__ = (new cljs.core.Delay(((function (kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (){
return weathergen.ui.trees.tree_STAR_.call(null,expand_state,more_levels,kids,(level_number + (1)));
});})(kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
,null));
var alt__29626__auto__ = (new cljs.core.Delay(((function (con__29625__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (){
return null;
});})(con__29625__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
,null));
var tpl__29627__auto__ = ((function (con__29625__auto__,alt__29626__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (p__29628__auto__){
return cljs.core.deref.call(null,(function (){var or__23148__auto__ = (cljs.core.truth_(p__29628__auto__)?con__29625__auto__:alt__29626__auto__);
if(cljs.core.truth_(or__23148__auto__)){
return or__23148__auto__;
} else {
return cljs.core.atom.call(null);
}
})());
});})(con__29625__auto__,alt__29626__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
;
return javelin.core.formula.call(null,tpl__29627__auto__).call(null,javelin.core.formula.call(null,((function (con__29625__auto__,alt__29626__auto__,tpl__29627__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs){
return (function (G__36455,G__36456){
var and__23136__auto__ = G__36455;
if(cljs.core.truth_(and__23136__auto__)){
return G__36456;
} else {
return and__23136__auto__;
}
});})(con__29625__auto__,alt__29626__auto__,tpl__29627__auto__,kids,expanded_QMARK_,vec__36450,item,vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
).call(null,expanded_QMARK_,kids));
})());
});})(vec__36445,seq__36446,first__36447,seq__36446__$1,level,more_levels,map__36448,map__36448__$1,formatter,children,attrs))
)));
});
/**
 * Returns a collapable tree with hierarchy defined by `levels`, a seq
 *   of maps with `:formatter` and `:children` keys, each a function of a
 *   single item in the hierarchy. The formatter returns UI for that
 *   item, and children (if present) returns items that will be rendered
 *   as children.
 */
weathergen.ui.trees.tree = (function weathergen$ui$trees$tree(expand_state,levels,items){
return weathergen.ui.trees.tree_STAR_.call(null,expand_state,levels,items,(0));
});
