// Compiled by ClojureScript 1.10.520 {}
goog.provide('weathergen.ui.textarea');
goog.require('cljs.core');
goog.require('clojure.string');
goog.require('hoplon.core');
goog.require('javelin.core');
goog.require('weathergen.ui.common');
/**
 * Like textarea, but better.
 * @param {...*} var_args
 */
weathergen.ui.textarea.textarea2 = (function() { 
var weathergen$ui$textarea$textarea2__delegate = function (args__30233__auto__){
var vec__35686 = hoplon.core.parse_args.call(null,args__30233__auto__);
var attrs = cljs.core.nth.call(null,vec__35686,(0),null);
var _ = cljs.core.nth.call(null,vec__35686,(1),null);
var map__35689 = attrs;
var map__35689__$1 = (((((!((map__35689 == null))))?(((((map__35689.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35689.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35689):map__35689);
var change = cljs.core.get.call(null,map__35689__$1,new cljs.core.Keyword(null,"change","change",-1163046502));
var placeholder = cljs.core.get.call(null,map__35689__$1,new cljs.core.Keyword(null,"placeholder","placeholder",-104873083));
var value = cljs.core.get.call(null,map__35689__$1,new cljs.core.Keyword(null,"value","value",305978217));
var css = cljs.core.get.call(null,map__35689__$1,new cljs.core.Keyword(null,"css","css",1135045163));
var attrs__$1 = cljs.core.dissoc.call(null,attrs,new cljs.core.Keyword(null,"value","value",305978217),new cljs.core.Keyword(null,"change","change",-1163046502),new cljs.core.Keyword(null,"placeholder","placeholder",-104873083),new cljs.core.Keyword(null,"css","css",1135045163));
var placeholder_STAR_ = javelin.core.formula.call(null,((function (map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (G__35691){
return G__35691;
});})(map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
).call(null,placeholder);
var interim = javelin.core.cell.call(null,null);
var editing_QMARK_ = javelin.core.cell.call(null,false);
var placeholder_QMARK_ = javelin.core.formula.call(null,((function (placeholder_STAR_,interim,editing_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (G__35693,G__35694,G__35695,G__35692){
return ((G__35692.call(null,G__35693)) && (G__35694.call(null,G__35695)));
});})(placeholder_STAR_,interim,editing_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
).call(null,editing_QMARK_,clojure.string.blank_QMARK_,value,cljs.core.not);
var elem = hoplon.core.div.call(null);
hoplon.core.do_watch.call(null,value,((function (elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (___$1,n){
if(cljs.core.truth_(cljs.core.deref.call(null,editing_QMARK_))){
return null;
} else {
return elem.innerText = n;
}
});})(elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
);

hoplon.core.do_watch.call(null,editing_QMARK_,((function (elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (___$1,n){
if(cljs.core.truth_(n)){
cljs.core.reset_BANG_.call(null,interim,cljs.core.deref.call(null,value));

return elem.innerText = cljs.core.deref.call(null,interim);
} else {
var v = elem.innerText;
if(cljs.core.truth_(change)){
change.call(null,v);
} else {
}

if((((cljs.core.count.call(null,v) === (0))) || (cljs.core._EQ_.call(null,"\n",v)))){
return elem.innerText = cljs.core.deref.call(null,placeholder_STAR_);
} else {
return null;
}
}
});})(elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
);

elem.call(null,new cljs.core.Keyword(null,"contenteditable","contenteditable",-770210530),"true",new cljs.core.Keyword(null,"click","click",1912301393),((function (elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (){
return cljs.core.reset_BANG_.call(null,editing_QMARK_,true);
});})(elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
,new cljs.core.Keyword(null,"input","input",556931961),((function (elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (___$1){
var v = elem.innerText;
cljs.core.reset_BANG_.call(null,interim,v);

if(cljs.core.truth_(change)){
return change.call(null,v);
} else {
return null;
}
});})(elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
,new cljs.core.Keyword(null,"css","css",1135045163),javelin.core.formula.call(null,((function (elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (placeholder_QMARK___$1,css__$1){
return cljs.core.merge.call(null,new cljs.core.PersistentArrayMap(null, 8, [new cljs.core.Keyword(null,"white-space","white-space",-707351930),"pre-wrap",new cljs.core.Keyword(null,"color","color",1011675173),(cljs.core.truth_(placeholder_QMARK___$1)?"#999":null),new cljs.core.Keyword(null,"cursor","cursor",1011937484),"text",new cljs.core.Keyword(null,"background","background",-863952629),"white",new cljs.core.Keyword(null,"border-color","border-color",-2059162761),"#aaa",new cljs.core.Keyword(null,"border-width","border-width",-1512605390),weathergen.ui.common.px.call(null,(1)),new cljs.core.Keyword(null,"border-style","border-style",-485574304),"solid",new cljs.core.Keyword(null,"padding","padding",1660304693),weathergen.ui.common.px.call(null,(5),(3),(3),(3))], null),css__$1);
});})(elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
).call(null,placeholder_QMARK_,css),new cljs.core.Keyword(null,"focus","focus",234677911),((function (elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (e){
return cljs.core.reset_BANG_.call(null,editing_QMARK_,true);
});})(elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
,new cljs.core.Keyword(null,"blur","blur",-453500461),((function (elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_){
return (function (e){
return cljs.core.reset_BANG_.call(null,editing_QMARK_,false);
});})(elem,placeholder_STAR_,interim,editing_QMARK_,placeholder_QMARK_,map__35689,map__35689__$1,change,placeholder,value,css,attrs__$1,vec__35686,attrs,_))
,attrs__$1);

return elem;
};
var weathergen$ui$textarea$textarea2 = function (var_args){
var args__30233__auto__ = null;
if (arguments.length > 0) {
var G__35696__i = 0, G__35696__a = new Array(arguments.length -  0);
while (G__35696__i < G__35696__a.length) {G__35696__a[G__35696__i] = arguments[G__35696__i + 0]; ++G__35696__i;}
  args__30233__auto__ = new cljs.core.IndexedSeq(G__35696__a,0,null);
} 
return weathergen$ui$textarea$textarea2__delegate.call(this,args__30233__auto__);};
weathergen$ui$textarea$textarea2.cljs$lang$maxFixedArity = 0;
weathergen$ui$textarea$textarea2.cljs$lang$applyTo = (function (arglist__35697){
var args__30233__auto__ = cljs.core.seq(arglist__35697);
return weathergen$ui$textarea$textarea2__delegate(args__30233__auto__);
});
weathergen$ui$textarea$textarea2.cljs$core$IFn$_invoke$arity$variadic = weathergen$ui$textarea$textarea2__delegate;
return weathergen$ui$textarea$textarea2;
})()
;
