define("view/tkcalendar/out-single", ["require", "exports", "module", "view/taskdetail/single", "model/task", "configs/dict", "utils/timeformat", "dao/calendardb", "service/prefs", "utils/dom", "utils/analytics", "configs/status", "utils/condition", "utils/reminder-util", "service/task", "service/userProfile", "hbs!template/out_single_subscribe"], function(e, t) {
    var i = e("view/taskdetail/single").View,
      n = e("model/task").Model,
      s = e("configs/dict"),
      a = e("utils/timeformat"),
      r = e("dao/calendardb"),
      o = e("service/prefs"),
      l = e("utils/dom"),
      c = e("utils/analytics"),
      d = e("configs/status"),
      u = e("utils/condition"),
      h = e("utils/reminder-util"),
      p = e("service/task"),
      m = e("service/userProfile");
    t.View = Backbone.View.extend({
      id: "out-single-task-detail",
      className: "out-detail pop-shadow",
      template: e("hbs!template/out_single_subscribe"),
      popTaskClass: "pop-task",
      events: {},
      message: function() {
        this.listenTo(Backbone, "deleteOutSingleTask", this.deleteTask), this.listenTo(Backbone, "hideOutSingleTask", this.hideView)
      },
      initialize: function(e) {
        return _.extend(this, e), this.message(), this.initTask(), this.render(), this.initPosition(), this.focusTitle(), this.activeTask(), d.hasOutDetail = !0, this.$el
      },
      render: function() {
        this.model && u.isSubscribeCalendarTask(this.model) ? this.renderSubscribe() : this.renderNormal(), this.$elDate.append(this.$el), this.renderScrollbar(), l.adjustDetailHeight()
      },
      renderScrollbar: function() {
        this.$(".antiscroll-wrap").antiscroll()
      },
      renderNormal: function(e) {
        this.taskDetailView && this.taskDetailView.close(), this.taskDetailView = new i({
          model: this.model
        }), this.$el.append(this.taskDetailView.$el)
      },
      renderSubscribe: function() {
        var e = "";
        this.model.get("repeatFlag") && (e = h.exposeRepeat({}, this.model).preview), this.$el.html(this.template({
          model: this.model.toJSON(),
          repeatTip: e
        })), this.$el.addClass("subscribe")
      },
      renderOutBg: function() {
        var e = '<div class="out-bg"></div>';
        this.$container = $("#js-c-scroll-container").append(e), this.$bg = this.$container.find(".out-bg")
      },
      _renderEmptyTask: function() {
        this.$t = $('<div class="c-task ' + this.popTaskClass + '"></div>'), this.$elDate.find(".c-tasks").prepend(this.$t)
      },
      _removeEmptyTask: function() {
        this.$t && this.$t.remove()
      },
      activeTask: function() {
        this.parent ? (this.parent.$el.addClass(this.popTaskClass),
          this.parent.renderProjectInfo(100)) : this._renderEmptyTask()
      },
      unActiveTask: function() {
        this.parent ? (this.parent.$el.removeClass(this.popTaskClass), this.parent.renderProjectInfo(20)) : this._removeEmptyTask()
      },
      initPosition: function() {
        var e = this.$el.closest(".c-col"),
          t = e.offset().top,
          i = e.outerWidth(),
          n = this.$el.outerHeight(),
          s = this.$el.outerWidth(),
          a = 7,
          r = 2,
          o = e.position().top + a,
          l = i + r,
          c = window.innerHeight - t - n,
          d = window.innerWidth - e.offset().left - l - s;
        o = c > 0 ? o : c - a, l = d > 0 ? l : -(s + r), this.$el.css({
          top: o,
          left: l
        })
      },
      focusTitle: function() {
        this.taskDetailView && (this.taskDetailView.titleEditor.showEditor(), this.taskDetailView.titleEditor.$el.find(".task-title").focus())
      },
      saveOrDelete: function() {
        if (Backbone.trigger("hideTimeCard"), this.model.get("title").trim().length || !this.model.isNew() || this.model.isDirty) {
          var e = this.dueDate,
            t = moment(this.model.get("dueDate")).format("YYYY-MM-DD"),
            i = r.db.getTaskByDueDateForTKCalendar(e);
          if (e == t) i.add(this.model, {
            merge: !0
          });
          else {
            var n = r.db.getTaskByDueDateForTKCalendar(t);
            n.add(this.model, {
              merge: !0
            }), i.remove(this.model)
          }
          r.db.add(this.model), c.c_task("add")
        } else this.model.destroy()
      },
      initTask: function() {
        if (this.dueDate = this.dueDate || moment(this.model.get("dueDate")).format("YYYY-MM-DD"), !this.model) {
          var e = a.prefMoment().utc().format(s.format.atomTime);
          this.model = new n({
            id: ObjectId(),
            title: "",
            content: "",
            dueDate: moment(this.dueDate).format(s.format.atomTime),
            timeZone: o.get("timeZone"),
            priority: 0,
            status: 0,
            sortOrder: p.getMinSortOrder(m.get("inboxId")),
            modifiedTime: e,
            createdTime: e
          }), this.model.local = !0
        }
      },
      hideView: function() {
        d.hasOutDetail = !1, this.saveOrDelete(), this.onClose()
      },
      deleteTask: function() {
        setTimeout(function() {
          d.hasOutDetail = !1
        }), this.onClose()
      },
      onClose: function() {
        this.unActiveTask(), this.taskDetailView && this.taskDetailView.onClose(), this.$bg && this.$bg.remove(), this.remove()
      }
    })
  })