import{r as T,h as i,H as B}from"./index-Bphhj8Un.js";import{B as D}from"./variant-quote-CHD0qMkY-Di-MtwAe.js";import{t as w}from"./i18n-BVaUp6qp-Fi24bvte.js";import{c as u,d as b,n as O}from"./normalizers-DnkJhVYZ-BpYOmfSj.js";import{l as L}from"./label-BEOW9ltS-Dwb4BBIM.js";import{m as P,u as M}from"./unit-eRQuaHYy-DP2VPtYp.js";import{B as H}from"./base-controller-CXhqh4cR-D2BOZI1P.js";import"./_Uint8Array-kJHDjtoP-jmGEpw_T.js";import"./isArray-CcrBs4JM-CqO_RI43.js";const I=u("high",0,b),$=u("low",0,b),V=u("min",0,b),U=u("optimum",0,b),W=["horizontal","vertical"],R=u("orientation","horizontal",t=>{const e=O(t);if(W.includes(e))return e;throw new Error(`Invalid orientation: ${e}`)}),S=u("value",0,b,t=>t>=0);function E(t,e,n,l,c,r){const o=l??e,h=c??n;if(r===void 0)return t>=o&&t<=h?"optimum":"suboptimal";const m=t<o,s=t>h,a=!m&&!s,p=r<o,d=r>h;return p?m?"optimum":a?"suboptimal":"critical":d?s?"optimum":a?"suboptimal":"critical":a?"optimum":"suboptimal"}const q=t=>{const{high:e,label:n,low:l,liveValue:c,max:r,min:o,optimum:h,orientation:m,unit:s,value:a}=t,p=m==="vertical",d=s==="%",k=d?Math.round((a-o)/(r-o)*100):a,v=d?`${Math.round((c-o)/(r-o)*100)}`:c,C=`${`${(d?100:r)+1}`.length}ch`,_=Math.min(100,Math.max(0,(a-o)/(r-o)*100)),f=E(a,o,r,l,e,h),g=l!==void 0||e!==void 0,y=g?w(`kol-meter-state-${f}`):"",x=d?w("kol-live-value",{placeholders:{value:String(v),unit:s}}):w("kol-live-value-bounded",{placeholders:{value:String(v),max:String(r),unit:s}}),A=g?`${x} – ${y}`:x,z={"kol-meter__bar-fill":!0,"kol-meter__bar-fill--optimum":f==="optimum","kol-meter__bar-fill--suboptimal":f==="suboptimal","kol-meter__bar-fill--critical":f==="critical"};return i("div",{class:{"kol-meter":!0,"kol-meter--vertical":p}},i("div",{"aria-hidden":"true",class:"kol-meter__bar"},i("div",{class:"kol-meter__bar-label"},n,g&&i("span",{class:`kol-meter__bar-state kol-meter__bar-state--${f}`}," – ",y)),p?i("div",{class:"kol-meter__bar-track"},i("div",{class:z,style:{height:`calc((100% - 6px) * ${_/100})`}})):i("svg",{xmlns:"http://www.w3.org/2000/svg",width:"100%",height:"12",overflow:"visible"},i("rect",{class:"kol-meter__bar-background",x:"1",y:"1",height:"11",rx:"5",fill:"currentColor",stroke:"currentColor","stroke-width":"3",width:"100%"}),i("rect",{class:"kol-meter__bar-border",x:"1",y:"1",height:"11",rx:"5",fill:"currentColor",stroke:"currentColor","stroke-width":"1",width:"100%"}),i("rect",{class:z,x:"3",y:"3",height:"7",rx:"3.5",fill:"currentColor",stroke:"currentColor","stroke-width":"3",style:{width:`calc(${_}% - 4px)`}})),i("span",{class:"kol-meter__value-unit"},i("span",{class:"kol-meter__value",style:p?{}:{width:C}},k)," ",i("span",{class:"kol-meter__unit"},s))),i("meter",{"aria-label":n,class:"visually-hidden",high:e,low:l,max:r,min:o,optimum:h,value:a}),i("span",{"aria-live":"polite","aria-relevant":"additions text",class:"visually-hidden"},A))},K={optional:[V,R,M],required:[L,P,S]};class N extends H{constructor(e){super(e,K),this.meterData={high:void 0,low:void 0,optimum:void 0}}componentWillLoad(e){const{high:n,label:l,low:c,max:r,min:o,optimum:h,orientation:m,unit:s,value:a}=e;this.watchHigh(n),this.watchLabel(l),this.watchLow(c),this.watchMax(r),this.watchMin(o),this.watchOptimum(h),this.watchOrientation(m),this.watchUnit(s),this.watchValue(a),this.setState("liveValue",this.getRenderProp("value")),this.startLiveValueInterval()}destroy(){this.interval&&(clearInterval(this.interval),this.interval=void 0)}getMeterData(){return this.meterData}watchHigh(e){e===void 0?this.meterData.high=void 0:I.apply(e,n=>{this.meterData.high=n})}watchLabel(e){L.apply(e,n=>{this.setRenderProp("label",n)})}watchLow(e){e===void 0?this.meterData.low=void 0:$.apply(e,n=>{this.meterData.low=n})}watchMax(e){P.apply(e,n=>{this.setRenderProp("max",n)})}watchMin(e){V.apply(e,n=>{this.setRenderProp("min",n)})}watchOptimum(e){e===void 0?this.meterData.optimum=void 0:U.apply(e,n=>{this.meterData.optimum=n})}watchOrientation(e){R.apply(e,n=>{this.setRenderProp("orientation",n)})}watchUnit(e){M.apply(e,n=>{this.setRenderProp("unit",n)})}watchValue(e){S.apply(e,n=>{this.setRenderProp("value",n)})}startLiveValueInterval(){this.interval=setInterval(()=>{const e=this.getRenderProp("value");this.getState("liveValue")!==e&&this.setState("liveValue",e)},5e3)}}const j=`/* forward the rem function */
/*
* This file defines the layer order for all CSS layers used in KoliBri.
* The order is important as it determines the cascade priority.
*
* Layer order (lowest to highest priority):
* 1. kol-a11y - Accessibility defaults and requirements
* 2. kol-global - Global component styles and resets
* 3. kol-component - Component-specific styles
* 4. kol-theme-global - Theme-specific global styles
* 5. kol-theme-component - Theme-specific component styles
*/
@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;
/*
 * This file contains all rules for accessibility.
 */
@layer kol-a11y {
  :host {
    /*
                   * Minimum size of interactive elements.
                   */
    --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));
    /*
     * No element should be used without verifying the contrast ratio of its background and font colors.
     * By initially setting the background color to white and the font color to black,
     * the contrast ratio is ensured and explicit adjustment is forced.
     */
    color: black;
    background-color: white;
    /*
     * Verdana is an accessible font that can be used without requiring additional loading time.
     */
    font-family: Verdana;
    /*
     * Letter spacing is required for all texts.
     */
    letter-spacing: inherit;
    /*
     * Word spacing is required for all texts.
     */
    word-spacing: inherit;
    /*
     * Text should be aligned left by default to provide a predictable starting point.
     */
    text-align: left;
  }
  * {
    /*
     * This rule enables the word dividing for all texts. That is important for high zoom levels.
     */
    hyphens: auto;
    /*
     * This rule enables the word dividing for all texts. That is important for high zoom levels.
     */
    word-break: break-word;
  }
  /*
   * All interactive elements should have a minimum size of to-rem(44).
   */
  /* input:not([type='checkbox'], [type='radio'], [type='range']), */
  /* option, */
  /* select, */
  /* textarea, */
  button,
  .kol-input .input {
    min-width: var(--a11y-min-size);
    min-height: var(--a11y-min-size);
  }
  /*
   * Some interactive elements should not inherit the font-family and font-size.
   */
  a,
  button,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  input,
  option,
  select,
  textarea {
    /*
     * All elements should inherit the text color from his parent element.
     */
    color: inherit;
    /*
     * All elements should inherit the font family from his parent element.
     */
    font-family: inherit;
    /*
     * All elements should inherit the font size from his parent element.
     */
    font-size: inherit;
    /*
     * Letter spacing is required for all texts.
     */
    letter-spacing: inherit;
    /*
     * Word spacing is required for all texts.
     */
    word-spacing: inherit;
  }
  /**
  * Sometimes we need the semantic element for accessibility reasons,
  * but we don't want to show it.
  *
  * - https://www.a11yproject.com/posts/how-to-hide-content/
  */
  .visually-hidden {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    white-space: nowrap;
    clip-path: inset(50%);
  }
}
@layer kol-global {
  /*
   * Dieses CSS stellt sicher, dass der Standard-Style
   * von A und Button resettet werden.
   */
  :is(a, button) {
    background-color: transparent;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    /* 100% needed for custom width from outside */
  }
  /*
   * Ensure elements with hidden attribute to be actually not visible
   * @see https://meowni.ca/hidden.is.a.lie.html
   */
  [hidden] {
    display: none !important;
  }
  .badge-text-hint {
    color: black;
    background-color: lightgray;
  }
}
@layer kol-global {
  :host {
    /*
     * The max-width is needed to prevent the table from overflowing the
     * parent node, if the table is wider than the parent node.
     */
    max-width: 100%;
    font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));
  }
  * {
    /*
     * We prefer to box-sizing: border-box for all elements.
     */
    box-sizing: border-box;
  }
  .kol-span {
    /* KolSpan is a layout component with icons in all directions and a label text in the middle. */
    display: flex;
    flex-flow: column;
    align-items: center;
    justify-content: center;
    /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */
  }
  .kol-span__container {
    display: flex;
    align-items: center;
  }
  a,
  button {
    cursor: pointer;
  }
  .kol-span .kol-span__label--hide-label .kol-span__label {
    display: none;
  }
  /* Reset browser agent style. */
  button:disabled {
    color: unset;
  }
  .disabled label,
  .disabled:focus-within label,
  [aria-disabled=true],
  [aria-disabled=true]:focus,
  [disabled],
  [disabled]:focus {
    opacity: 0.5;
    outline: none;
    cursor: not-allowed;
  }
  [aria-disabled=true]:focus .kol-span,
  [disabled]:focus .kol-span {
    outline: none !important;
  }
  .hastooltip {
    z-index: 900 !important;
  }
}
@layer kol-component {
  .kol-meter__bar {
    display: grid;
    column-gap: calc(0.8 * 1rem / var(--kolibri-root-font-size, 16));
    align-items: center;
    grid-template-areas: "LABEL LABEL LABEL" "BAR VALUE UNIT";
    grid-template-columns: 1fr auto;
  }
  .kol-meter__bar-label {
    grid-column-end: 2;
    grid-area: LABEL;
  }
  .kol-meter__bar svg {
    grid-area: BAR;
  }
  .kol-meter__bar-border {
    fill: transparent;
    stroke: black;
  }
  .kol-meter__bar-background {
    fill: lightgray;
    stroke: white;
  }
  .kol-meter__bar-fill {
    stroke: transparent;
  }
  @media (prefers-reduced-motion: no-preference) {
    .kol-meter__bar-fill {
      transition: 250ms ease-in-out 50ms;
    }
  }
  .kol-meter__bar-fill--optimum {
    color: #2ea32e;
    color: #2ea32e;
    fill: #2ea32e;
  }
  .kol-meter__bar-fill--suboptimal {
    color: #c8a000;
    color: #c8a000;
    fill: #c8a000;
  }
  .kol-meter__bar-fill--critical {
    color: #c00;
    color: #c00;
    fill: #c00;
  }
  .kol-meter__value-unit {
    display: contents;
  }
  .kol-meter__value {
    grid-area: VALUE;
    text-align: right;
  }
  .kol-meter__unit {
    grid-area: UNIT;
  }
  .kol-meter--vertical {
    display: inline-flex;
  }
  .kol-meter--vertical .kol-meter__bar {
    display: flex;
    min-height: var(--kol-meter-height, calc(128 * 1rem / var(--kolibri-root-font-size, 16)));
    row-gap: calc(4 * 1rem / var(--kolibri-root-font-size, 16));
    flex-direction: column;
    align-items: center;
  }
  .kol-meter--vertical .kol-meter__bar-label {
    text-align: center;
  }
  .kol-meter--vertical .kol-meter__bar-track {
    background: lightgray;
    outline: calc(1 * 1rem / var(--kolibri-root-font-size, 16)) solid black;
    border-radius: calc(6 * 1rem / var(--kolibri-root-font-size, 16));
    position: relative;
    width: calc(12 * 1rem / var(--kolibri-root-font-size, 16));
    min-height: 0;
    overflow: hidden;
    flex: 1;
  }
  .kol-meter--vertical .kol-meter__bar-fill {
    background: currentColor;
    border-radius: calc(3 * 1rem / var(--kolibri-root-font-size, 16));
    position: absolute;
    right: calc(3 * 1rem / var(--kolibri-root-font-size, 16));
    bottom: calc(3 * 1rem / var(--kolibri-root-font-size, 16));
    left: calc(3 * 1rem / var(--kolibri-root-font-size, 16));
  }
  @media (prefers-reduced-motion: no-preference) {
    .kol-meter--vertical .kol-meter__bar-fill {
      transition: height 250ms ease-in-out 50ms;
    }
  }
  .kol-meter--vertical .kol-meter__value-unit {
    display: contents;
  }
  .kol-meter--vertical .kol-meter__value {
    width: auto;
    text-align: center;
  }
  .kol-meter--vertical .kol-meter__unit {
    text-align: center;
  }
}`,F=class extends D{constructor(t){super(),T(this,t),this.ctrl=new N(this.stateAccess),this._orientation="horizontal",this._unit="%",this.liveValue=0}watchHigh(t){this.ctrl.watchHigh(t)}watchLabel(t){this.ctrl.watchLabel(t)}watchLow(t){this.ctrl.watchLow(t)}watchMax(t){this.ctrl.watchMax(t)}watchMin(t){this.ctrl.watchMin(t)}watchOptimum(t){this.ctrl.watchOptimum(t)}watchOrientation(t){this.ctrl.watchOrientation(t)}watchUnit(t){this.ctrl.watchUnit(t)}watchValue(t){this.ctrl.watchValue(t)}componentWillLoad(){this.ctrl.componentWillLoad({high:this._high,label:this._label,low:this._low,max:this._max,min:this._min,optimum:this._optimum,orientation:this._orientation,unit:this._unit,value:this._value})}disconnectedCallback(){this.ctrl.destroy()}render(){const{high:t,low:e,optimum:n}=this.ctrl.getMeterData();return i(B,{key:"ed5af1db7e9a4cf7c618856cbd1135a58ebbd851"},i(q,{key:"0504e9c2df6e79b4d803dcfe49ff4f88e7f50fb5",high:t,label:this.ctrl.getRenderProp("label"),low:e,liveValue:this.liveValue,max:this.ctrl.getRenderProp("max"),min:this.ctrl.getRenderProp("min"),optimum:n,orientation:this.ctrl.getRenderProp("orientation"),unit:this.ctrl.getRenderProp("unit"),value:this.ctrl.getRenderProp("value")}))}static get watchers(){return{_high:["watchHigh"],_label:["watchLabel"],_low:["watchLow"],_max:["watchMax"],_min:["watchMin"],_optimum:["watchOptimum"],_orientation:["watchOrientation"],_unit:["watchUnit"],_value:["watchValue"]}}};F.style={default:j};export{F as kol_meter};
//# sourceMappingURL=kol-meter.entry-B5efE7nH.js.map
