import { generateActionComponent } from '@dvn/core/components/views/dvn-card-view/action-util';
import { generateCardItem } from '@dvn/core/models/card-config';
import { Component, Event, h, Host, Prop } from '@stencil/core';
export class DvnCardView {
  constructor() {
    this.leaned = false;
    this.clip = true;
  }
  render() {
    const { fields, item, config, overrideStyle } = this;
    const cardItem = generateCardItem(config, fields, item);
    // show cover if header config contains cover or image
    const showCover = !!config.header && !!(config.header.image || config.header.cover);
    // show image if header config contains image
    const showImage = !!config.header && !!config.header.image;
    // show header either title or image is present
    const showHeader = !!config.header && (config.header.title || showImage);
    let cardFooter = null;
    if (cardItem.footer.customViewTag) {
      const FooterTag = cardItem.footer.customViewTag;
      cardFooter = (h(FooterTag, { slot: "footer", item: item, meta: cardItem.footer.customViewTagMeta }));
    }
    else if (cardItem.footer.actions.length) {
      cardFooter = (h("dvn-card-footer", { slot: "footer", alignRight: true }, cardItem.footer.actions.map((action, index) => generateActionComponent(index, {}, item, this.action, action))));
    }
    return (h(Host, { style: this.overrideStyle },
      h("dvn-card", { cornerRadius: this.cornerRadius, elevation: 0, leaned: this.leaned, style: overrideStyle, clip: this.clip },
        showHeader &&
          h("dvn-card-header", { title: cardItem.header.title, titlePosition: cardItem.header.titlePosition, slot: "header", showCover: showCover, coverSrc: cardItem.header.coverSrc, coverPlaceholder: cardItem.header.coverPlaceholder, coverSize: cardItem.header.coverSize, coverAspectRatio: cardItem.header.coverAspectRatio, showImage: showImage, imageSrc: cardItem.header.imageSrc, imageSize: cardItem.header.imageSize, imageShape: cardItem.header.imageShape, imagePlaceholder: cardItem.header.imagePlaceholderValue, imagePlaceholderType: cardItem.header.imagePlaceholderType, imagePosition: cardItem.header.imagePosition, cornerRadius: this.cornerRadius },
            cardItem.header.actions.length > 0 &&
              h("div", { class: "header-actions-container", slot: "action" }, cardItem.header.actions.map((action, index) => generateActionComponent(index, {}, item, this.action, action))),
            cardItem.header.subtitleActions.length > 0 &&
              h("div", { class: "subtitle-actions-container", slot: "subtitle" }, cardItem.header.subtitleActions.map((action, index) => generateActionComponent(index, {}, item, this.action, action, { simpleLink: true })))),
        cardItem.body.fields.map(field => {
          if (field.customViewTag) {
            const Tag = field.customViewTag;
            return (h(Tag, { item: item, field: field }));
          }
          else {
            return (h("dvn-field-display", { infoTitle: field.label, field: field.field, value: field.value, meta: field.meta }));
          }
        }),
        cardFooter)));
  }
  static get is() { return "dvn-card-view"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-card-view.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-card-view.css"]
  }; }
  static get properties() { return {
    "config": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "CardConfig",
        "resolved": "CardConfig",
        "references": {
          "CardConfig": {
            "location": "import",
            "path": "@dvn/core/models/card-config"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "cornerRadius": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Used to remove corner radius when the card\nview is used in some container like side modal."
      },
      "attribute": "corner-radius",
      "reflect": false
    },
    "item": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DataModel",
        "resolved": "DataModel",
        "references": {
          "DataModel": {
            "location": "import",
            "path": "@dvn/core/models/data-model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "fields": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "BaseField[]",
        "resolved": "BaseField[]",
        "references": {
          "BaseField": {
            "location": "import",
            "path": "@dvn/core/doldurma/src/BaseField"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "leaned": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "leaned",
      "reflect": false,
      "defaultValue": "false"
    },
    "clip": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "clip",
      "reflect": false,
      "defaultValue": "true"
    },
    "overrideStyle": {
      "type": "any",
      "mutable": false,
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "override-style",
      "reflect": false
    }
  }; }
  static get events() { return [{
      "method": "action",
      "name": "action",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
}
