text: import { BitrixVue } from 'ui.vue';
  import { Loc } from 'main.core';
  import './style.css';
  
  export var PersonalDocsDetail = {
      init: function (parameters) {
          this.result = parameters.result || {};
          this.params = parameters.params || {};
          this.params.paymentList = parameters.paymentList || {};
          this.params.url = parameters.url || "";
          this.params.SLIDER_WIDTH = this.params.SLIDER_WIDTH || window.outerWidth;
  
          this.template = parameters.template || '';
          this.signedParamsString = parameters.signedParamsString || '';
          this.siteId = parameters.siteId || '';
          this.siteTemplateId = parameters.siteTemplateId || '';
          this.ajaxUrl = this.params.AJAX_PATH || '';
          this.templateFolder = parameters.templateFolder || '';
  
          if (BX.Main.gridManager != undefined && this.params.GRID_ID) {
              this.grid = BX.Main.gridManager.getInstanceById(this.params.GRID_ID);
          }
  
          if (BX.SidePanel != undefined) {
              BX.SidePanel.Instance.bindAnchors({
                  rules: [{
                      condition: ["/personal/docs/\.+",],
                      stopParameters: [],
                      mobileFriendly: true,
                      options: {
                          cacheable: true,
                          autoFocus: true,
                          printable: true,
                          allowChangeHistory: false,
                          allowChangeTitle: true,
                          contentClassName: "light-sidepanel",
                          width: this.params.SLIDER_WIDTH,
                          animationDuration: this.SLIDER_DURATION,
                          label: {
                              class: 'dark',
                              contentClassName: "light",
                              text: BX.message("DOC_"),
                              color: "#000000",
                              bgColor: "#ebf1f4",
                              opacity: 100
                          },
                          events: {
                              onOpenStart: BX.proxy(this.SidePanelOpenStart, this),
                              onLoad: BX.proxy(this.SidePanelLoad, this),
                          }
                      },
                  }, {
                      condition: ["/personal/orders/\.+",],
                      stopParameters: [],
                      mobileFriendly: true,
                      options: {
                          cacheable: true,
                          autoFocus: true,
                          printable: true,
                          allowChangeHistory: true,
                          allowChangeTitle: true,
                          contentClassName: "light-sidepanel",
                          width: this.params.SLIDER_WIDTH,
                          animationDuration: this.SLIDER_DURATION,
                          label: {
                              class: 'dark',
                              contentClassName: "light",
                              text: BX.message("ORDER_"),
                              color: "#000000",
                              bgColor: "#ebf1f4",
                              opacity: 100
                          },
                          events: {
                              onOpenStart: BX.proxy(this.SidePanelOpenStart, this),
                              onLoad: BX.proxy(this.SidePanelLoad, this),
                          }
                      },
                  },
                  ]
              });
          }
      },
      copyToBasket: function copyToBasket(doc_id, istochnik) {
  
            return this.showRequest(this.params.AJAX_PATH + "?id=" + doc_id + "&istochnik=" + istochnik + "&action=COPY_TO_BASKET&access=Y", {
              printable: true,
              contentClassName: "light-sidepanel",
              width: '500',
              allowChangeHistory: false,
              cacheable: true,
              label: {
                class: 'dark',
                text: "Корзина ",
                color: "#000000",
                //цвет текста
                bgColor: "#ebf1f4",
                //цвет фона
                opacity: 100 //прозрачность фона
  
              },
              events: {
                  onOpenStart: BX.proxy(this.SidePanelOpenStart, this),
                  onLoad: BX.proxy(this.SidePanelLoad, this),
                  onCloseByEsc: BX.proxy(this.SidePanelEscHide, this),
                  onClose: BX.proxy(this.SidePanelHide, this),
                  onCloseComplete: BX.proxy(this.SidePanelDestroy, this)
              }
            });
      },
      sendRequest: function (data) {
          return BX.ajax.runComponentAction(
              'germes:sale.personal.docs.detail',
              'action',
              {
                  mode: 'class',
                  method: 'POST',
                  data: this.getData(data),
              }).then(response => {
                  console.log(response);
              }, reject => {
                  console.log(reject);
              });
      },
      showRequest: function (path, params) {
          let def_params = {
              requestMethod: 'post',
              requestParams: {},
              width: '500',
              allowChangeHistory: false,
              allowChangeTitle: true,
              cacheable: true,
              label: {
                  color: "#000000",
                  bgColor: "#64ba4e",
                  opacity: 100
              }
          };
          if (params?.requestParams == undefined) params.requestParams = {};
          params.requestParams = Object.assign(params.requestParams, this.getData(), def_params.requestParams);
          params = Object.assign(def_params, params);
          return BX.SidePanel.Instance.open(path, params);
      },
      SidePanelOpenStart: function (event) {
          let slider = event.getSlider()
          debugger
          if (slider?.getWindow()?.document?.title)
              slider.getLabel().setText(slider.getWindow().document.title)
          if (slider?.options?.label?.class && slider?.getLabel()?.layout != undefined)
              slider.getLabel().layout.closeBtn.classList.add(slider.options.label.class)
      },
      SidePanelLoad: function (event) {
          let slider = event?.getSlider(),
              sliderDocument = slider?.getWindow()?.document
          if (sliderDocument?.title)
              slider.getLabel().setText(sliderDocument.title)
          if (sliderDocument) sliderDocument.addEventListener('DOMContentLoaded', function () {
              sliderDocument.body.querySelectorAll('a').forEach(tag_a => tag_a.setAttribute('target', slider.getFrameId()));
              sliderDocument.body.find('form[target]')?.attr('target', slider.getFrameId());
          })
      },
      getData: function (data) {
          data = data || {};
  
          if (this.params.ACTION_VARIABLE) {
              data[this.params.ACTION_VARIABLE] = this.lastAction;
          }
          data.via_ajax = 'Y';
          data.sessid = BX.bitrix_sessid();
          data.signedParamsString = this.signedParamsString;
  
          return data;
      },
  };
  