dcAssetItemDetails/dcAssetItemDetails.js

/*************************************************************************
 *
 * VLOCITY, INC. CONFIDENTIAL
 * __________________
 *
 *  [2014] - [2020] Vlocity, Inc.
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Vlocity, Inc. and its suppliers,
 * if any. The intellectual and technical concepts contained
 * herein are proprietary to Vlocity, Inc. and its suppliers and may be
 * covered by U.S. and Foreign Patents, patents in process, and are
 * protected by trade secret or copyright law. Dissemination of this
 * information and reproduction, modification or reverse-engineering
 * of this material, is prohibited unless prior written permission
 * is obtained from Vlocity, Inc.
 *
 */
import { LightningElement, track, api } from "lwc";
import { DCBaseComponent } from "c/dcBaseComponent";
import { images } from "c/dcMockData";

/**
 * @class DCAssetItemDetails
 * @extends {LitElement} Extend the LitElement base class
 *
 * @classdesc
 * c-dc-asset-item-details is a component used for displaying asset details for each asset.
 * @property {Array} asset - object containing a single asset.
 *
 * @example
 * Sample Usage -
 *
 * Include the component in your template by adding c-dc-asset-item-details  custom tag
 *
 * <c-dc-asset-item-details asset={childAsset} is-parent=false></c-dc-asset-item-details>
 *
 * | Attribute Name    | Type Expected                                                                   | Required |
 * |-------------------|---------------------------------------------------------------------------------|----------|
 * | asset             | It expects an object which contains a current asset from asset list             |   Yes    |
 * | isParent          | It expects a boolean value determines if current asset is parent                |   Yes    |
 *
 *  KEY INFO -
 *
 *  events fire : none
 *
 *  events registered : none
 *
 *  Dependency - c-dc-asset-item-details is a child component of c-dc-asset-details.
 *  It is used inside c-dc-asset-details for displaying child assets.
 *
 *
 *                | Parent Component         | Expected Children Components |
 *                |--------------------------|------------------------------|
 *                | c-dc-asset-details       |   none                       |
 *
 * Sample with slots -
 *
 * <c-dc-asset-item-details >
 *    <span slot="{slot_name}">
 *      Custom HTML elements goes here
 *    </span>
 * </c-dc-asset-item-details >
 *
 * List of available slots -
 *
 * | Slot names                  | Dynamic     | Description                        | Impact                                 |
 * |--------------------------   |-------------|------------------------------------|----------------------------------------|
 * | nds-dc-asset-item-details   | -           | Wrapper for asset item details     | Replaces each asset detail view        |
 *
 */

export default class DCAssetItemDetails extends DCBaseComponent(
  LightningElement
) {
  @track asset = [];
  @track currencySymbol = "$";

  @api
  set asset(val) {
    if (val) {
      this._asset = val;
    }
  }
  get asset() {
    return this._asset;
  }

  @api
  set isParent(val) {
    if (val) {
      this._isParent = val == "true";
    }
  }
  get isParent() {
    return this._isParent;
  }

  connectedCallback() {
    this.icons = images;
  }

  /**
   * This function is used as getter for asset item css class
   * @memberof DCAssetItemDetails
   */
  get assetItemClass() {
    if (this.isParent) {
      return "nds-dc-asset-each-item nds-dc-asset-each-item_parent";
    } else {
      return "nds-dc-asset-each-item";
    }
  }

  /**
   * Method to fetch promotion string from getPromotions utility
   * @memberof DCAssetItemDetails
   */
  get assetPromotions() {
    return this.getPromotions(this.asset);
  }
}