import "choerodon-ui/pro/lib/form/style";
import _Form from "@hzero-front-ui/c7n-ui/lib/FormPro";
import "choerodon-ui/pro/lib/text-field/style";
import _TextField from "choerodon-ui/pro/lib/text-field";
import "choerodon-ui/pro/lib/icon/style";
import _Icon from "choerodon-ui/pro/lib/icon";
import "choerodon-ui/pro/lib/select/style";
import _Select from "choerodon-ui/pro/lib/select";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

import React, { useEffect, Fragment, useState } from 'react';
import { observer } from 'mobx-react-lite';
import _ from 'lodash';
import MdEditor from "../../../../../../components/MdEditor";
import Tips from "../../../../../../components/new-tips";
import "../index.less";
var Option = _Select.Option,
    OptGroup = _Select.OptGroup;
export default observer(function (props) {
  var appTagStore = props.appTagStore,
      tagStore = props.tagStore,
      projectId = props.projectId,
      appServiceId = props.appServiceId;
  var appTagCreateDs = appTagStore.appTagCreateDs,
      formatMessage = appTagStore.formatMessage;

  var _useState = useState(''),
      _useState2 = _slicedToArray(_useState, 2),
      release = _useState2[0],
      setRelease = _useState2[1];

  var _useState3 = useState(3),
      _useState4 = _slicedToArray(_useState3, 2),
      size = _useState4[0],
      setSize = _useState4[1];

  function handleNoteChange(value) {
    setRelease(value);
    appTagCreateDs.current.set('release', value);
  }

  function changeSize(e) {
    e.stopPropagation();
    setSize(size + 10);
    tagStore.queryBranchData({
      projectId: projectId,
      appServiceId: appServiceId,
      size: size + 10
    });
  }

  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(_Form, {
    layout: "vertical",
    dataSet: appTagCreateDs,
    className: "c7n-sidebar-form c7n-tag-create",
    style: {
      width: '5.12rem'
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "apptag-formitem"
  }, /*#__PURE__*/React.createElement(_Icon, {
    type: "local_offer",
    className: "c7n-apptag-icon"
  }), /*#__PURE__*/React.createElement(_TextField, {
    name: "tag",
    addonAfter: /*#__PURE__*/React.createElement(Tips, {
      helpText: formatMessage({
        id: 'apptag.name.tip'
      })
    })
  })), /*#__PURE__*/React.createElement("div", {
    className: "apptag-formitem"
  }, /*#__PURE__*/React.createElement(_Icon, {
    type: "wrap_text",
    className: "c7n-apptag-icon"
  }), /*#__PURE__*/React.createElement(_Select, {
    name: "ref",
    addonAfter: /*#__PURE__*/React.createElement(Tips, {
      helpText: formatMessage({
        id: 'apptag.tip'
      })
    }),
    renderer: renderer,
    optionRenderer: optionRenderer
  }, /*#__PURE__*/React.createElement(OptGroup, {
    label: formatMessage({
      id: 'apptag.branch'
    })
  }, _.map(tagStore.branchData, function (item) {
    return /*#__PURE__*/React.createElement(Option, {
      key: item.branchName,
      value: item.branchName,
      title: item.branchName
    }, item.branchName);
  }), tagStore.branchTotal > size && size > 0 ? /*#__PURE__*/React.createElement(Option, {
    key: "more",
    title: formatMessage({
      id: 'loadMore'
    })
  }, /*#__PURE__*/React.createElement("div", {
    role: "none",
    onClick: changeSize,
    className: "c7n-option-popover c7n-dom-more"
  }, formatMessage({
    id: 'loadMore'
  }))) : null)))), /*#__PURE__*/React.createElement("div", {
    className: "c7n-creation-title"
  }, formatMessage({
    id: 'apptag.release.title'
  })), /*#__PURE__*/React.createElement(MdEditor, {
    value: release,
    textMaxLength: 1000,
    onChange: handleNoteChange
  }));
});

var renderer = function renderer(_ref) {
  var text = _ref.text;
  return !text ? null : /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(_Icon, {
    className: "apptag-branch-icon",
    type: "branch"
  }), text);
};

var optionRenderer = function optionRenderer(data) {
  var text = data.text;
  if (typeof text !== 'string') return text;
  return !text ? null : /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(_Icon, {
    className: "apptag-branch-icon",
    type: "branch"
  }), text);
};