@use "../../../css/mixins" as m;

// custom icon used because the standard one has hard coded colors.
$_icon-status-cancel: url('data:image/svg+xml,<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.9971 2C17.9335 2 19.7542 2.36766 21.458 3.10254C23.1617 3.8374 24.6442 4.83504 25.9043 6.09473C27.1642 7.35432 28.1622 8.83534 28.8975 10.5381C29.6325 12.2411 30 14.061 30 15.9971C30 17.9335 29.6324 19.7542 28.8975 21.458C28.1626 23.1617 27.165 24.6442 25.9053 25.9043C24.6457 27.1642 23.1647 28.1622 21.4619 28.8975C19.7589 29.6325 17.939 30 16.0029 30C14.0665 30 12.2458 29.6324 10.542 28.8975C8.83829 28.1626 7.35588 27.165 6.0957 25.9053C4.83572 24.6457 3.83782 23.1647 3.10254 21.4619C2.36746 19.7589 2.00004 17.939 2 16.0029C2 14.0665 2.36766 12.2458 3.10254 10.542C3.8374 8.83829 4.83504 7.35588 6.09473 6.0957C7.35432 4.83573 8.83535 3.83781 10.5381 3.10254C12.2411 2.36746 14.061 2.00004 15.9971 2ZM21.3545 9C20.9061 9.00003 20.5078 9.16358 20.1904 9.48047L16 13.6709L11.8096 9.48047C11.4972 9.16854 11.1006 9.01383 10.6602 9.00684C10.2068 9.00009 9.80152 9.16076 9.48047 9.48145C9.16361 9.7988 9 10.1971 9 10.6455C9.00003 11.0939 9.16374 11.4923 9.48047 11.8096L13.6709 16L9.48047 20.1904C9.16865 20.5027 9.01391 20.8986 9.00684 21.3389C8.99998 21.7924 9.16066 22.1984 9.48145 22.5195C9.7988 22.8364 10.1972 23 10.6455 23C11.0941 23 11.4932 22.8355 11.8105 22.5186L16 18.3291L20.1973 22.5264C20.5097 22.8385 20.9062 22.993 21.3467 23C21.7999 23.0067 22.2054 22.8468 22.5264 22.5264C22.8521 22.2002 23 21.7901 23 21.3545C23 20.9116 22.847 20.5183 22.5264 20.1973L18.3291 16L22.5195 11.8096C22.8314 11.4972 22.9862 11.1006 22.9932 10.6602C22.9999 10.2068 22.8392 9.80152 22.5186 9.48047C22.2012 9.16359 21.8029 9 21.3545 9Z" fill="currentColor"/></svg>');

// QGDS specific tag variables
.tag-list {
  //Status - Low emphasis
  $tag-emphasis: "low";
  //Status - Low -- General variables
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-color: var(--#{$prefix}color-default-color-light-text-default);
  --#{$prefix}tag-status-#{$tag-emphasis}-border: 1px solid transparent;

  //Status - Low -- Neutral
  $tag-type: "neutral";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-neutral-lightest);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-border-color: var(--#{$prefix}core-default-color-neutral-light);

  //Status - Low -- Success
  $tag-type: "success";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-success-lighter);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-border-color: var(--#{$prefix}core-default-color-status-success-default);

  //Status - Low -- Warning
  $tag-type: "warning";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-caution-lightest);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-border-color: var(--#{$prefix}core-default-color-status-caution-default);

  //Status - Low -- Error
  $tag-type: "error";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-error-lighter);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-border-color: var(--#{$prefix}core-default-color-status-error-default);

  //Status - Low -- Information
  $tag-type: "information";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-info-lighter);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-border-color: var(--#{$prefix}core-default-color-status-info-default);

  //Status - High emphasis
  $tag-emphasis: "high";
  //Status - High -- General variables
  --#{$prefix}tag-status-#{$tag-emphasis}-border: none;

  //Status - High -- Neutral
  $tag-type: "neutral";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-color: var(--#{$prefix}core-default-color-neutral-black);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-neutral-light);

  //Status - High -- Success
  $tag-type: "success";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-color: var(--#{$prefix}core-default-color-neutral-white);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-success-darker);

  //Status - High -- Warning
  $tag-type: "warning";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-color: var(--#{$prefix}core-default-color-neutral-black);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-caution-default);

  //Status - High -- Error
  $tag-type: "error";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-color: var(--#{$prefix}core-default-color-neutral-white);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-error-default);

  //Status - High -- Information
  $tag-type: "information";
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-color: var(--#{$prefix}core-default-color-neutral-white);
  /* prettier-ignore */
  --#{$prefix}tag-status-#{$tag-emphasis}-#{$tag-type}-bg: var(--#{$prefix}core-default-color-status-info-darker);
}

// General styling rules.
.tag-list {
  list-style-type: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;

  .tag-item {
    --_padding-y: 0;
    --_padding-x: 0.5rem;
    --_height: 1.5rem;
    --_border-width: 1px;
    --_icon-size: 1rem;
    --qld-focus-color: #{$qld-light-focus}; // because we use component-scoped context (.tag-dark) not global .dark, need to set focus color here.
    //
    display: inline-flex;
    align-items: center;
    color: var(--#{$prefix}light-text-lighter);
    // margin: 0 1rem 1rem 0;
    padding: var(--_padding-y) var(--_padding-x);
    list-style-type: none;
    border: var(--_border-width) solid var(--#{$prefix}neutral-lighter);
    border-radius: 1rem;
    font-size: 0.875rem;
    line-height: 1.4;

    &.tag-large {
      --_padding-y: 0.5rem;
      --_padding-x: 1rem;
      --_height: 2.5rem;
      --_icon-size: 1.5rem;
      font-size: 1rem;
      border-radius: calc(var(--_height) / 2);
    }

    &.tag-link {
      color: var(--#{$prefix}light-link);
      border-color: var(--#{$prefix}light-link);

      a {
        text-decoration: none;

        &:focus {
          outline: none;
        }
      }

      @include m.focusable($isFocusWithin: true);

      &:hover,
      &:active,
      &:focus,
      &:focus-within {
        color: var(--#{$prefix}light-link-on-action);
        background-color: var(--#{$prefix}light-action-primary-hover);
        text-decoration: underline;
        text-underline-offset: var(--#{$prefix}link-underline-offset);

        a {
          color: var(--#{$prefix}light-link-on-action);
        }
      }
    }

    &.tag-link:not(.tag-large) {
      &:hover,
      &:active,
      &:focus,
      &:focus-within {
        text-underline-offset: 0.1rem;
      }
    }

    &.tag-info {
      color: var(--#{$prefix}light-text-lighter);
      border: 0;
      background-color: var(--#{$prefix}neutral-lightest);
    }
  }

  .tag-clear-filter-button {
    @include m.unset-button-styles();
    @include m.focusable($offsetOutline: -2px);
    --_size: calc(var(--_height) - (var(--_border-width) * 2));
    --_icon: var(--qgds-icon-alert-cancel);
    height: var(--_size);
    width: var(--_size);
    margin-block: calc(var(--_padding-y) * -1);
    margin-right: calc(var(--_padding-x) * -1);
    line-height: 1;
    vertical-align: middle;
    border-radius: calc(var(--_size) / 2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--#{$prefix}light-action-secondary);

    &:before {
      content: "";
      height: var(--_icon-size);
      width: var(--_icon-size);
      background-color: currentColor;
      mask-image: var(--_icon);
      mask-size: contain;
      mask-repeat: no-repeat;
    }

    &:hover {
      color: var(--#{$prefix}light-action-secondary-hover);
    }

    &:focus-visible,
    &:hover {
      --_icon: #{$_icon-status-cancel};
    }
  }

  &.tag-status {
    .tag-item {
      &.tag-low {
        color: var(--#{$prefix}tag-status-low-color);
        border: var(--#{$prefix}tag-status-low-border);

        &.tag-neutral {
          background: var(--#{$prefix}tag-status-low-neutral-bg);
          border-color: var(--#{$prefix}tag-status-low-neutral-border-color);
        }
        &.tag-success {
          background: var(--#{$prefix}tag-status-low-success-bg);
          border-color: var(--#{$prefix}tag-status-low-success-border-color);
        }
        &.tag-warning {
          background: var(--#{$prefix}tag-status-low-warning-bg);
          border-color: var(--#{$prefix}tag-status-low-warning-border-color);
        }
        &.tag-error {
          background: var(--#{$prefix}tag-status-low-error-bg);
          border-color: var(--#{$prefix}tag-status-low-error-border-color);
        }
        &.tag-information {
          background: var(--#{$prefix}tag-status-low-information-bg);
          border-color: var(
            --#{$prefix}tag-status-low-information-border-color
          );
        }
      }

      &.tag-high {
        border: var(--#{$prefix}tag-status-high-border);

        &.tag-neutral {
          color: var(--#{$prefix}tag-status-high-neutral-color);
          background: var(--#{$prefix}tag-status-high-neutral-bg);
        }
        &.tag-success {
          color: var(--#{$prefix}tag-status-high-success-color);
          background: var(--#{$prefix}tag-status-high-success-bg);
        }
        &.tag-warning {
          color: var(--#{$prefix}tag-status-high-warning-color);
          background: var(--#{$prefix}tag-status-high-warning-bg);
        }
        &.tag-error {
          color: var(--#{$prefix}tag-status-high-error-color);
          background: var(--#{$prefix}tag-status-high-error-bg);
        }
        &.tag-information {
          color: var(--#{$prefix}tag-status-high-information-color);
          background: var(--#{$prefix}tag-status-high-information-bg);
        }
      }
    }
  }

  &.tag-dark,
  .dark &:not(.tag-dark):not(.tag-dark-alt):not(.tag-alt) {
    background-color: var(--#{$prefix}dark-background);

    .tag-item {
      --qld-focus-color: #{$qld-dark-focus}; // because we use component-scoped context (.tag-dark) not global .dark, need to set focus color correctly here.
      color: var(--#{$prefix}dark-text-lighter);
      border-color: var(--#{$prefix}dark-alt-border);
    }

    .tag-link {
      color: var(--#{$prefix}dark-link);
      border-color: var(--#{$prefix}dark-link);

      a {
        color: var(--#{$prefix}dark-link);
      }

      &:hover,
      &:active,
      &:focus,
      &:focus-within {
        background-color: var(--#{$prefix}dark-action-primary-hover);
        border-color: var(--#{$prefix}dark-action-primary-hover);
        color: var(--#{$prefix}dark-link-on-action);

        a {
          color: var(--#{$prefix}dark-link-on-action);
        }
      }
    }

    .tag-info {
      background-color: var(--#{$prefix}dark-background-shade);
      color: var(--#{$prefix}dark-text-lighter);
    }

    .tag-clear-filter-button {
      color: var(--#{$prefix}dark-action-secondary);

      &:hover {
        color: var(--#{$prefix}dark-action-secondary-hover);
      }
    }
  }

  &.tag-alt {
    background-color: var(--#{$prefix}light-alt-background);

    .tag-item {
      color: var(--#{$prefix}light-text-lighter);
      border-color: var(--#{$prefix}light-alt-border);
    }

    .tag-link:hover,
    .tag-link:active,
    .tag-link:focus {
      color: var(--#{$prefix}white) !important;
    }

    .tag-link {
      color: var(--#{$prefix}light-link);
      border-color: var(--#{$prefix}light-link);
    }
  }

  &.tag-light {
    background-color: var(--#{$prefix}light-background);

    .tag-item {
      color: var(--#{$prefix}light-text-lighter);
      border-color: var(--#{$prefix}light-border);
    }

    .tag-link {
      color: var(--#{$prefix}light-link);
      border-color: var(--#{$prefix}light-link);
    }

    .tag-info {
      background-color: var(--#{$prefix}light-background-shade);
    }

    .tag-clear-filter-button {
      color: var(--#{$prefix}light-action-secondary);

      &:hover {
        color: var(--#{$prefix}light-action-secondary-hover);
      }
    }
  }

  &.tag-dark-alt,
  .dark-alt &:not(.tag-dark, .tag-dark-alt, .tag-alt) {
    background-color: var(--#{$prefix}dark-alt-background);

    .tag-item {
      --qld-focus-color: #{$qld-dark-focus}; // because we use component-scoped context (.tag-dark) not global .dark, need to set focus color correctly here.

      a {
        color: var(--#{$prefix}dark-text-lighter);
      }

      color: var(--#{$prefix}dark-text-lighter);
      border-color: var(--#{$prefix}dark-border);
    }

    .tag-info {
      background-color: var(--#{$prefix}dark-alt-background-shade);
      color: var(--#{$prefix}dark-text-lighter);
    }

    .tag-link {
      &:hover,
      &:active,
      &:focus,
      &:focus-within {
        background-color: var(--#{$prefix}dark-action-primary-hover);
        border-color: var(--#{$prefix}dark-link-on-action);
        color: var(--#{$prefix}dark-link-on-action);

        a {
          color: var(--#{$prefix}dark-link-on-action);
        }
      }
    }

    .tag-clear-filter-button {
      color: var(--#{$prefix}dark-action-secondary);

      &:hover {
        color: var(--#{$prefix}dark-action-secondary-hover);
      }
    }
  }
}
