/**
 *
 */
"use strict";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

if (window.DolphyApp) (function () {
  var _Vue = Vue,
      reactive = _Vue.reactive,
      ref = _Vue.ref;
  var xTab = ref(null);
  var xTabList = ref([]);
  var xTabMap = ref({});
  var xPage = ref(null);
  var xTitle = ref(null); // -----------------

  var PageTool = {};
  Object.defineProperty(PageTool, 'setTitle', {
    writable: false,
    value: function (_value) {
      function value(_x) {
        return _value.apply(this, arguments);
      }

      value.toString = function () {
        return _value.toString();
      };

      return value;
    }(function (value) {
      xTitle.value = value;
    })
  });
  Object.defineProperty(PageTool, 'setTabList', {
    writable: false,
    value: function (_value2) {
      function value(_x2) {
        return _value2.apply(this, arguments);
      }

      value.toString = function () {
        return _value2.toString();
      };

      return value;
    }(function (value) {
      if (!Array.isArray(value)) value = [];
      xTabList.value = value;
      xTabMap.value = value.reduce(function (carry, item) {
        carry[item.name] = item;
        return carry;
      }, {});
    })
  });
  Object.defineProperty(PageTool, 'loadTabList', {
    writable: false,
    value: function value(hookName) {
      var $hooks = DolphyApp.$dolphy.$hooks;
      var tabList = $hooks.applyFilters(hookName, []);
      if (!Array.isArray(tabList)) tabList = [];
      this.setTabList(tabList);
    }
  });
  Object.defineProperty(PageTool, 'fetchTabs', {
    writable: false,
    value: function value(page) {
      var _this = this;

      var _DolphyApp$$dolphy = DolphyApp.$dolphy,
          $preloader = _DolphyApp$$dolphy.$preloader,
          $api = _DolphyApp$$dolphy.$api,
          $message = _DolphyApp$$dolphy.$message;
      var url = $api.of('account').url('tabs', {
        page: page
      });
      $preloader.start();
      $api.get(url).then(function (resp) {
        if (Array.isArray(resp.data)) {
          _this.setTabList(resp.data);

          _this.updateActiveTab();
        }
      })["catch"](function (error) {
        $message.handle(error);
      })["finally"](function () {
        $preloader.stop();
      });
    }
  });
  Object.defineProperty(PageTool, 'initialize', {
    writable: false,
    value: function value() {
      var page = this.getQueryParam('page');
      if (page) this.fetchTabs(page);
    }
  });
  Object.defineProperty(PageTool, 'setActivePage', {
    writable: false,
    value: function (_value3) {
      function value(_x3) {
        return _value3.apply(this, arguments);
      }

      value.toString = function () {
        return _value3.toString();
      };

      return value;
    }(function (value) {
      xPage.value = value;
    })
  });
  Object.defineProperty(PageTool, 'setActiveTab', {
    writable: false,
    value: function (_value4) {
      function value(_x4) {
        return _value4.apply(this, arguments);
      }

      value.toString = function () {
        return _value4.toString();
      };

      return value;
    }(function (value) {
      xTab.value = value;
    })
  });
  Object.defineProperty(PageTool, 'isActiveTab', {
    writable: false,
    value: function value(tab) {
      var tabName = typeof tab === 'string' ? tab : tab.name;
      return xTab.value && xTab.value === tabName;
    }
  });
  Object.defineProperty(PageTool, 'updateActiveTab', {
    writable: false,
    value: function value() {
      var tab = this.getActiveTab();
      this.setActiveTab(tab);
    }
  });
  Object.defineProperty(PageTool, 'navigate', {
    writable: false,
    value: function value(tab) {
      var search = document.location.search;
      var params = new URLSearchParams(search);

      if (_typeof(tab) === 'object') {
        params.set('tab', tab.name);
      } else if (typeof tab === 'string') {
        params.set('tab', tab);
      }

      window.history.pushState({}, '', '?' + params.toString());
      this.updateActiveTab();
    }
  });
  Object.defineProperty(PageTool, 'getQueryParam', {
    writable: false,
    value: function value(name, defaultValue) {
      var search = document.location.search;
      var params = new URLSearchParams(search);

      if (params.has(name)) {
        return params.get(name);
      }

      return defaultValue || null;
    }
  });
  Object.defineProperty(PageTool, 'getActivePage', {
    writable: false,
    value: function value(defaultValue) {
      return this.getQueryParam('page', defaultValue);
    }
  });
  Object.defineProperty(PageTool, 'getActiveTab', {
    writable: false,
    value: function value(defaultValue) {
      var tabName = this.getQueryParam('tab', null);
      if (tabName) return tabName;

      if (xTabList.value.length) {
        var tab = xTabList.value[0];
        return tab.name;
      }

      return defaultValue;
    }
  }); // -------------------------------

  window.addEventListener('popstate', function (e) {
    PageTool.updateActiveTab();
  }); // -------------------------------

  DolphyApp.onInit(function (app) {
    app.mixin({
      computed: {
        title: function title() {
          return xTitle.value;
        },
        tabList: function tabList() {
          return xTabList.value;
        },
        activePage: function activePage() {
          return xPage.value;
        },
        activeTab: function activeTab() {
          return xTab.value;
        },
        activeTabComponent: function activeTabComponent() {
          if (xTab.value in xTabMap.value) {
            return xTabMap.value[xTab.value].component;
          }

          return null;
        }
      }
    });
  });
  DolphyApp.add('$page', PageTool);
})();
if (window.DolphyApp) (function () {
  var _Vue2 = Vue,
      ref = _Vue2.ref,
      computed = _Vue2.computed;
  DolphyApp.onInit(function (app) {
    app.component('color-input', {
      props: {
        modelValue: String
      },
      template: "\n      <input type=\"text\">\n      ",
      data: function data() {
        return {
          media: null,
          picker: null
        };
      },
      methods: {
        open: function open() {
          var type = this.type,
              title = this.title,
              multiple = this.multiple,
              mediaButtonText = this.mediaButtonText;
          this.$emit('update:modelValue', value);
        }
      },
      mounted: function mounted() {
        var _this2 = this;

        var $el = this.$el,
            modelValue = this.modelValue;
        this.picker = new JSColor($el, {
          format: 'rgba',
          previewSize: 120,
          hideOnLeave: true,
          width: 300,
          height: 150,
          onInput: function onInput() {
            var value = _this2.picker.toRGBAString();

            _this2.$emit('update:modelValue', value);
          }
        });

        if (modelValue) {
          this.picker.fromString(modelValue);
        }
      }
    });
  });
})();
if (window.DolphyApp) (function () {
  DolphyApp.onInit(function (app) {
    app.component('page-content', {
      template: "\n      <div id=\"dolphy-page\" class=\"dolphy-page\" :class=\"{'drawer': drawer}\">\n        <div class=\"dolphy-page__left\" v-if=\"tabList.length\">\n          <div class=\"close-btn\" @click=\"closeDrawer($event)\">\n            <i class=\"fa fa-times\"></i>\n          </div>\n\n          <ul @click=\"closeDrawer($event)\">\n            <li v-for=\"tab in tabList\" :class=\"{'active': $dolphy.$page.isActiveTab(tab)}\">\n              <a href=\"\" @click=\"navigate($event, tab)\">{{ tab.text }}</a>\n            </li>\n          </ul>\n        </div>\n\n        <div class=\"dolphy-page__right\">\n          <div class=\"dolphy-page__nav\">\n            <span class=\"nav-btn\" @click=\"openDrawer($event)\">\n              <i class=\"fa fa-bars\"></i>\n            </span>\n          </div>\n\n          <div class=\"dolphy-page__content\">\n            <slot></slot>\n          </div>\n\n          <div class=\"dolphy-page__overlay\" @click=\"closeDrawer($event)\"></div>\n        </div>\n      </div>\n      ",
      setup: function setup() {
        var _DolphyApp = DolphyApp,
            $page = _DolphyApp.$dolphy.$page;
        $page.updateActiveTab();
      },
      data: function data() {
        return {
          drawer: false
        };
      },
      methods: {
        navigate: function navigate(e, tab) {
          e.preventDefault();
          var $page = this.$dolphy.$page;
          $page.navigate(tab.name);
        },
        openDrawer: function openDrawer(e) {
          e.preventDefault();
          this.drawer = true;
        },
        closeDrawer: function closeDrawer(e) {
          e.preventDefault();
          this.drawer = false;
        },
        toggleDrawer: function toggleDrawer(e) {
          e.preventDefault();
          this.drawer = !this.drawer;
        }
      }
    });
  });
})();
if (window.DolphyApp) (function () {
  var _Vue3 = Vue,
      ref = _Vue3.ref,
      computed = _Vue3.computed,
      watch = _Vue3.watch;
  DolphyApp.onInit(function (app) {
    app.component('media-input', {
      props: {
        type: {
          type: Array,
          validator: function validator(value) {
            return Array.isArray(value);
          },
          "default": function _default() {
            return ['image'];
          }
        },
        title: {
          type: String,
          "default": function _default() {
            return 'Select Media';
          }
        },
        multiple: {
          type: Boolean,
          validator: function validator(value) {
            return [true, false].indexOf(value) >= 0;
          },
          "default": function _default() {
            return false;
          }
        },
        buttonText: {
          type: String,
          "default": function _default() {
            return 'Select Media';
          }
        },
        mediaButtonText: {
          type: String,
          "default": function _default() {
            return 'Use this Media';
          }
        },
        modelValue: Array
      },
      template: "\n      <div class=\"dolphy-media-input\">\n        <div class=\"dolphy-media-input__info\">\n          <span>{{ (files.length) ? files[0].filename : 'No file selected' }}</span>\n          &nbsp;&nbsp;\n          <span class=\"dol-text-bold\" v-if=\"files.length > 1\">...and {{ (files.length - 1) }} more</span>\n        </div>\n\n        <div class=\"dolphy-media-input__button\" @click=\"open($event)\">\n          <span>{{ buttonText }}</span>\n        </div>\n      </div>\n      ",
      data: function data() {
        return {
          media: null,
          files: []
        };
      },
      setup: function setup(props) {
        var parseModelValue = function parseModelValue(modelValue) {
          var fileUrlArray = !Array.isArray(modelValue) ? [modelValue] : modelValue;
          this.files = fileUrlArray.map(function (fileUrl) {
            var index = fileUrl.lastIndexOf('/');
            var filename = fileUrl.substr(index + 1);
            return {
              filename: filename
            };
          });
        };

        return {
          parseModelValue: parseModelValue
        };
      },
      watch: {
        modelValue: function modelValue(newValue) {
          this.parseModelValue(newValue);
        }
      },
      methods: {
        open: function open() {
          var _this3 = this;

          var type = this.type,
              title = this.title,
              multiple = this.multiple,
              mediaButtonText = this.mediaButtonText;

          if (this.media) {
            this.media.open();
            return;
          }

          this.media = wp.media({
            title: title,
            button: {
              text: mediaButtonText
            },
            multiple: multiple,
            library: {
              type: type
            }
          });
          this.media.on('select', function () {
            var selection = _this3.media.state().get('selection').toJSON(); // this.files = selection;


            var value = !multiple ? selection[0].url : selection.map(function (file) {
              return file.url;
            });

            _this3.$emit('update:modelValue', value);
          });
          this.media.open();
        }
      },
      mounted: function mounted() {
        var modelValue = this.modelValue;
        this.parseModelValue(modelValue);
      }
    });
  });
})();
if (window.DolphyApp) (function () {
  var $hooks = DolphyApp.$dolphy.$hooks;
  DolphyApp.accountComponent('dolphy', '/dolphy', {
    setup: function setup() {
      var _DolphyApp2 = DolphyApp,
          $page = _DolphyApp2.$dolphy.$page;
      $page.setTitle('Dolphy Settings');
      $page.initialize();
    }
  });
})();
if (window.DolphyApp) (function () {
  var $hooks = DolphyApp.$dolphy.$hooks;
  DolphyApp.accountComponent('dolphy-security', '/security', {
    setup: function setup() {
      var _DolphyApp3 = DolphyApp,
          $page = _DolphyApp3.$dolphy.$page;
      $page.setTitle('Dolphy Security');
      $page.initialize();
    },
    mounted: function mounted() {// console.log(this);
    }
  });
})();
if (window.DolphyApp) (function () {
  var _Vue4 = Vue,
      ref = _Vue4.ref;
  DolphyApp.accountComponent('dolphy-settings-access', '/dolphy/access', {
    data: function data() {
      return {// form: {}
      };
    },
    setup: function setup(props) {
      return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
        var _DolphyApp$$dolphy2, $api, $preloader, form, url, resp;

        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _DolphyApp$$dolphy2 = DolphyApp.$dolphy, $api = _DolphyApp$$dolphy2.$api, $preloader = _DolphyApp$$dolphy2.$preloader;
                form = ref({});
                $preloader.start();
                _context.prev = 3;
                url = $api.admin.url('settings_access');
                _context.next = 7;
                return $api.get(url);

              case 7:
                resp = _context.sent;
                form.value = resp.data;
                _context.next = 14;
                break;

              case 11:
                _context.prev = 11;
                _context.t0 = _context["catch"](3);
                swal('', _context.t0.message, '');

              case 14:
                $preloader.stop();
                return _context.abrupt("return", {
                  form: form
                });

              case 16:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, null, [[3, 11]]);
      }))();
    },
    methods: {
      submit: function submit(e) {
        var _this4 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
          var form, _this4$$dolphy, $api, $preloader, url, resp;

          return regeneratorRuntime.wrap(function _callee2$(_context2) {
            while (1) {
              switch (_context2.prev = _context2.next) {
                case 0:
                  e.preventDefault();
                  form = _this4.form, _this4$$dolphy = _this4.$dolphy, $api = _this4$$dolphy.$api, $preloader = _this4$$dolphy.$preloader;
                  $preloader.start();
                  _context2.prev = 3;
                  url = $api.admin.url('settings_access');
                  _context2.next = 7;
                  return $api.post(url, form);

                case 7:
                  resp = _context2.sent;
                  swal('', 'Settings Successfully Saved!', 'success');
                  _context2.next = 14;
                  break;

                case 11:
                  _context2.prev = 11;
                  _context2.t0 = _context2["catch"](3);
                  swal('', _context2.t0.message, 'error');

                case 14:
                  $preloader.stop();

                case 15:
                case "end":
                  return _context2.stop();
              }
            }
          }, _callee2, null, [[3, 11]]);
        }))();
      }
    }
  });
})();
if (window.DolphyApp) (function () {
  DolphyApp.accountComponent('dolphy-general', '/dolphy/general', {// activeTabComponent
  });
})();
if (window.DolphyApp) (function () {
  var _Vue5 = Vue,
      ref = _Vue5.ref,
      reactive = _Vue5.reactive,
      inject = _Vue5.inject;
  var _DolphyApp4 = DolphyApp,
      $dolphy = _DolphyApp4.$dolphy;
  DolphyApp.accountComponent('dolphy-security-2fa', '/security/2fa', {
    data: function data() {
      return {
        form: {}
      };
    },
    inject: ['TwoFAService'],
    setup: function setup(props, ctx) {
      return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
        var TwoFAService, $preloader, $message, info, resp;
        return regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                TwoFAService = inject('TwoFAService');
                $preloader = $dolphy.$preloader, $message = $dolphy.$message;
                info = ref({});
                $preloader.start();
                _context3.prev = 4;
                _context3.next = 7;
                return TwoFAService.getInfo();

              case 7:
                resp = _context3.sent;
                info.value = resp.data;
                _context3.next = 14;
                break;

              case 11:
                _context3.prev = 11;
                _context3.t0 = _context3["catch"](4);
                $message.handle(_context3.t0);

              case 14:
                $preloader.stop();
                return _context3.abrupt("return", {
                  info: info
                });

              case 16:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee3, null, [[4, 11]]);
      }))();
    },
    methods: {
      download: function download() {
        var backup = this.info.backup;
        var text = backup.join("\n");
        var file = new Blob([text], {
          type: 'text/plain'
        });
        var a = document.createElement('a');
        a.download = 'dolphy-2fa-backup-codes.txt';
        a.href = URL.createObjectURL(file);
        a.click();
        setTimeout(function () {
          return URL.revokeObjectURL(file);
        });
      },
      submit: function submit(form) {
        var _this5 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
          var $api, $preloader, $message, $dialog, TwoFAService, _this5$info, backup, secret, data, resp, info;

          return regeneratorRuntime.wrap(function _callee4$(_context4) {
            while (1) {
              switch (_context4.prev = _context4.next) {
                case 0:
                  $api = $dolphy.$api, $preloader = $dolphy.$preloader, $message = $dolphy.$message, $dialog = $dolphy.$dialog;
                  TwoFAService = _this5.TwoFAService, _this5$info = _this5.info, backup = _this5$info.backup, secret = _this5$info.secret;
                  $preloader.start();
                  _context4.prev = 3;

                  if (form.code) {
                    _context4.next = 6;
                    break;
                  }

                  throw 'Kindly enter the code from your Authenticator App.';

                case 6:
                  data = _objectSpread({
                    secret: secret,
                    backup: backup
                  }, form);
                  _context4.next = 9;
                  return TwoFAService.enable(data);

                case 9:
                  resp = _context4.sent;
                  _context4.next = 12;
                  return TwoFAService.getInfo();

                case 12:
                  info = _context4.sent;
                  _this5.info = info.data;
                  $dialog.alert('Success', resp.data);
                  _context4.next = 20;
                  break;

                case 17:
                  _context4.prev = 17;
                  _context4.t0 = _context4["catch"](3);
                  $message.handle(_context4.t0);

                case 20:
                  $preloader.stop();

                case 21:
                case "end":
                  return _context4.stop();
              }
            }
          }, _callee4, null, [[3, 17]]);
        }))();
      },
      disable: function disable() {
        var _this6 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
          var $preloader, $message, $dialog, TwoFAService, msg, disable, resp, info;
          return regeneratorRuntime.wrap(function _callee5$(_context5) {
            while (1) {
              switch (_context5.prev = _context5.next) {
                case 0:
                  $preloader = $dolphy.$preloader, $message = $dolphy.$message, $dialog = $dolphy.$dialog;
                  TwoFAService = _this6.TwoFAService;
                  msg = 'Do you really want to DISABLE Two-Factor Authentication for this account?';
                  _context5.next = 5;
                  return $dialog.confirm('Disable Two-Factor Authentication', msg);

                case 5:
                  disable = _context5.sent;

                  if (!(disable === false)) {
                    _context5.next = 8;
                    break;
                  }

                  return _context5.abrupt("return");

                case 8:
                  $preloader.start();
                  _context5.prev = 9;
                  _context5.next = 12;
                  return TwoFAService.disable();

                case 12:
                  resp = _context5.sent;
                  _context5.next = 15;
                  return TwoFAService.getInfo();

                case 15:
                  info = _context5.sent;
                  _this6.info = info.data;
                  $dialog.alert('Success', resp.data, 'success');
                  _context5.next = 23;
                  break;

                case 20:
                  _context5.prev = 20;
                  _context5.t0 = _context5["catch"](9);
                  $message.handle(_context5.t0);

                case 23:
                  $preloader.stop();

                case 24:
                case "end":
                  return _context5.stop();
              }
            }
          }, _callee5, null, [[9, 20]]);
        }))();
      }
    }
  });
})();
if (window.DolphyApp) (function () {
  var $element = document.querySelector('#dolphy-admin');
  if (!$element) return;
  var app = new DolphyApp({
    setup: function setup() {
      var _DolphyApp5 = DolphyApp,
          $page = _DolphyApp5.$dolphy.$page;
      var page = $page.getActivePage();
      $page.setActivePage(page);
    }
  });
  app.mount($element);
})();