import "../styles/reset.css";
import "./switcher.less";
import { PropTypes as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__, SwitcherThemeType as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_SwitcherThemeType__, useFormItem as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_useFormItem__, withInstall as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_withInstall__ } from "../shared";
import { computed as __WEBPACK_EXTERNAL_MODULE_vue_computed__, createVNode as __WEBPACK_EXTERNAL_MODULE_vue_createVNode__, defineComponent as __WEBPACK_EXTERNAL_MODULE_vue_defineComponent__, ref as __WEBPACK_EXTERNAL_MODULE_vue_ref__, watch as __WEBPACK_EXTERNAL_MODULE_vue_watch__ } from "vue";
import { usePrefix as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_config_provider_fe8577a3_usePrefix__ } from "../config-provider";
import { SwitcherLoading as __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_icon_a97c79c3_SwitcherLoading__ } from "../icon";

;// external "../shared"

;// external "vue"

;// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
function _typeof(o) {
  "@babel/helpers - typeof";

  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
    return typeof o;
  } : function (o) {
    return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  }, _typeof(o);
}

;// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js

function toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}

;// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js


function toPropertyKey(t) {
  var i = toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}

;// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js

function _defineProperty(e, r, t) {
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
    value: t,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[r] = t, e;
}

;// external "../config-provider"

;// external "../icon"

;// ../../packages/switcher/src/switcher.tsx


/*
 * Tencent is pleased to support the open source community by making
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
 *
 * Copyright (C) 2025 Tencent.  All rights reserved.
 *
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
 *
 * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
 *
 * ---------------------------------------------------
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
 * the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */




var switcherType = {
  theme: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_SwitcherThemeType__(),
  size: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.size(),
  disabled: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
  showText: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
  isOutline: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
  onText: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string.def('ON'),
  offText: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string.def('OFF'),
  isSquare: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool,
  extCls: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string,
  beforeChange: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.func.def(undefined),
  trueValue: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOfType([__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool]).def(true),
  falseValue: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOfType([__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool]).def(false),
  value: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOfType([__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool]).def(false),
  modelValue: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.oneOfType([__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.string, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.number, __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool]).def(false),
  withValidate: __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_PropTypes__.bool.def(true)
};
var EVENTS;
(function (EVENTS) {
  EVENTS["CHANGE"] = "change";
  EVENTS["UPDATE"] = "update:modelValue";
})(EVENTS || (EVENTS = {}));
function EventFunction(value) {
  return value;
}
function ChangeFunction(value) {
  return !!value;
}
var switcherEmitEventsType = _defineProperty(_defineProperty({}, EVENTS.UPDATE, EventFunction), EVENTS.CHANGE, ChangeFunction);
/* harmony default export */ const switcher = (__WEBPACK_EXTERNAL_MODULE_vue_defineComponent__({
  name: 'Switcher',
  props: switcherType,
  emits: switcherEmitEventsType,
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var formItem = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_useFormItem__();
    var _usePrefix = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_config_provider_fe8577a3_usePrefix__(),
      resolveClassName = _usePrefix.resolveClassName;
    var isLoading = __WEBPACK_EXTERNAL_MODULE_vue_ref__(false);
    var isChecked = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      return props.trueValue === localValue.value;
    });
    var isModelValue = __WEBPACK_EXTERNAL_MODULE_vue_ref__(props.modelValue !== false);
    var localValue = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      return isModelValue.value ? props.modelValue : props.value;
    });
    var classObject = __WEBPACK_EXTERNAL_MODULE_vue_computed__(function () {
      var cls = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, props.extCls, !!props.extCls), "".concat(resolveClassName('switcher')), true), "".concat(resolveClassName('switcher-outline')), props.isOutline), "".concat(resolveClassName('switcher-square')), props.isSquare), 'show-label', props.showText), 'is-disabled', props.disabled), 'is-checked', isChecked.value), 'is-unchecked', !isChecked.value), 'is-loading', isLoading.value), "".concat(resolveClassName('primary')), props.theme === 'primary');
      // 显示文本则size无效，使用固定尺寸
      if (props.size && !props.showText) {
        var sizeStr = "".concat(resolveClassName("switcher-".concat(props.size)));
        cls[sizeStr] = true;
      }
      return cls;
    });
    __WEBPACK_EXTERNAL_MODULE_vue_watch__(function () {
      return props.modelValue;
    }, function () {
      isModelValue.value = true;
      if (props.withValidate) {
        var _formItem$validate;
        formItem === null || formItem === void 0 || (_formItem$validate = formItem.validate) === null || _formItem$validate === void 0 || _formItem$validate.call(formItem, 'change');
      }
    });
    __WEBPACK_EXTERNAL_MODULE_vue_watch__(function () {
      return props.value;
    }, function () {
      isModelValue.value = false;
    });
    var handleChange = function handleChange(event) {
      event.stopPropagation();
      event.preventDefault();
      if (props.disabled || isLoading.value) {
        return;
      }
      var lastValue = isChecked.value ? props.falseValue : props.trueValue;
      var lastChecked = !isChecked.value;
      var trigger = function trigger() {
        emit(EVENTS.UPDATE, lastValue);
        emit(EVENTS.CHANGE, lastChecked);
      };
      var goodJob = true;
      if (typeof props.beforeChange === 'function') {
        goodJob = props.beforeChange(lastValue);
        if (typeof goodJob.then === 'function') {
          isLoading.value = true;
          return goodJob.then(function () {
            trigger();
          })["finally"](function () {
            isLoading.value = false;
          });
        }
      }
      if (goodJob) {
        trigger();
      }
    };
    var handleKeydown = function handleKeydown(e) {
      // Enter 键盘事件可触发开关切换
      if (e.code === 'Enter' || e.key === 'Enter' || e.keyCode === 13) {
        handleChange(e);
      }
    };
    return function () {
      return __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("div", {
        "class": classObject.value,
        "tabindex": "0",
        "onClick": handleChange,
        "onKeydown": handleKeydown
      }, [isLoading.value ? __WEBPACK_EXTERNAL_MODULE_vue_createVNode__(__WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_icon_a97c79c3_SwitcherLoading__, {
        "class": "".concat(resolveClassName('switcher-loading'))
      }, null) : '', props.showText ? __WEBPACK_EXTERNAL_MODULE_vue_createVNode__("span", {
        "class": "switcher-text"
      }, [isChecked.value ? props.onText : props.offText]) : '']);
    };
  }
}));
;// ../../packages/switcher/src/index.ts
/*
 * Tencent is pleased to support the open source community by making
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
 *
 * Copyright (C) 2025 Tencent.  All rights reserved.
 *
 * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
 *
 * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
 *
 * ---------------------------------------------------
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
 * the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */


var BkSwitcher = __WEBPACK_EXTERNAL_MODULE_bkui_vue_lib_shared_edbdfb03_withInstall__(switcher);
/* harmony default export */ const src = (BkSwitcher);
export { src as default };
