YUI.add("model-sync-local",function(r,t){function e(){}e._NON_ATTRS_CFG=["root"],e._hasLocalStorage=function(){var t=r.config.win.localStorage,o=r.guid();try{return t.setItem(o,o),t.removeItem(o),!0}catch(e){return!1}}(),e._data=e._data||{},e._store=e._store||{},e.prototype={root:"",storage:null,initializer:function(t){var o;"root"in(t=t||{})&&(this.root=t.root||""),!this.root&&this.model&&this.model.prototype.root&&(this.root=this.model.prototype.root),e._hasLocalStorage&&(this.storage=r.config.win.localStorage,o=this.storage.getItem(this.root)),o?(e._store[this.root]=o.split("|")||[],r.Array.each(e._store[this.root],function(t){e._data[t]=r.JSON.parse(this.storage.getItem(t))},this)):e._store[this.root]||(e._store[this.root]=[])},sync:function(t,o,e){var r,s;o=o||{};try{switch(t){case"read":r=this._isYUIModelList?this._index(o):this._show(o);break;case"create":r=this._create(o);break;case"update":r=this._update(o);break;case"delete":r=this._destroy(o)}}catch(i){s=i.message}r?e(null,r):e(s||"Data not found in LocalStorage")},generateID:function(t){return r.guid(t+"_")},_index:function(){var t=e._store[this.root];return r.Array.map(t,function(t){return e._data[t]})},_show:function(){return e._data[this.get("id")]||null},_create:function(){var t=this.toJSON();return t.id=this.generateID(this.root),e._data[t.id]=t,this.storage&&this.storage.setItem(t.id,r.JSON.stringify(t)),e._store[this.root].push(t.id),this._save(),t},_update:function(){var t=this.toJSON(),o=this.get("id");return e._data[o]=t,this.storage&&this.storage.setItem(o,t),-1===r.Array.indexOf(e._store[this.root],o)&&e._store[this.root].push(o),this._save(),t},_destroy:function(){var o=this.get("id"),t=this.storage;if(e._data[o])return delete e._data[o],t&&t.removeItem(o),e._store[this.root]=r.Array.filter(e._store[this.root],function(t){return t.id!=o}),this._save(),this.toJSON()},_save:function(){e._hasLocalStorage&&this.storage&&this.storage.setItem(this.root,e._store[this.root].join("|"))}},r.namespace("ModelSync").Local=e},"patched-v3.18.7",{requires:["model","json-stringify"]});