import { Component, Element, h, Prop } from '@stencil/core';
import { state as selectedProcessor } from '@store/selected-processor';
export class ScPaymentMethodChoice {
  isSelected() {
    if (this.methodId) {
      return (selectedProcessor === null || selectedProcessor === void 0 ? void 0 : selectedProcessor.id) === this.processorId && (selectedProcessor === null || selectedProcessor === void 0 ? void 0 : selectedProcessor.method) == this.methodId;
    }
    return !(selectedProcessor === null || selectedProcessor === void 0 ? void 0 : selectedProcessor.method) && (selectedProcessor === null || selectedProcessor === void 0 ? void 0 : selectedProcessor.id) === this.processorId;
  }
  getAllOptions() {
    const parentGroup = this.el.closest('sc-payment') || this.el.parentElement;
    if (!parentGroup) {
      return [];
    }
    return [...parentGroup.querySelectorAll(this.el.tagName)];
  }
  getSiblingItems() {
    return this.getAllOptions().filter(choice => choice !== this.el);
  }
  hasOthers() {
    var _a;
    return !!((_a = this.getSiblingItems()) === null || _a === void 0 ? void 0 : _a.length);
  }
  render() {
    const Tag = this.hasOthers() ? 'sc-toggle' : 'div';
    return (h(Tag, { "show-control": true, borderless: true, open: this.isSelected(), onScShow: () => {
        selectedProcessor.id = this.processorId;
        selectedProcessor.manual = !!this.isManual;
        selectedProcessor.method = this.methodId;
      } },
      this.hasOthers() && h("slot", { name: "summary", slot: "summary" }),
      this.card && !this.hasOthers() ? (h("sc-card", null,
        h("slot", null))) : (h("slot", null))));
  }
  static get is() { return "sc-payment-method-choice"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["sc-payment-method-choice.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-payment-method-choice.css"]
  }; }
  static get properties() { return {
    "methodId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The method id"
      },
      "attribute": "method-id",
      "reflect": true
    },
    "processorId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The processor ID"
      },
      "attribute": "processor-id",
      "reflect": false
    },
    "isManual": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Is this a manual processor"
      },
      "attribute": "is-manual",
      "reflect": false
    },
    "card": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Should we show this in a card?"
      },
      "attribute": "card",
      "reflect": false
    }
  }; }
  static get elementRef() { return "el"; }
}
