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CAAc;AAGjB;IADP,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;4CAC4B;AAfrD,IAAI;IADhB,aAAa,CAAC,OAAO,CAAC;GACV,IAAI","sourcesContent":["import { LitElement, html, svg, type TemplateResult } from 'lit';\nimport { customElement } from 'lit/decorators/custom-element.js';\nimport { property } from 'lit/decorators/property.js';\nimport { classMap } from 'lit/directives/class-map.js';\n\nimport { consume } from '@lit/context';\n\nimport { thRoleContext } from './context.js';\n\nimport '@patternfly/elements/pf-button/pf-button.js';\n\nimport styles from './pf-th.css';\n\nconst DIRECTIONS = { asc: 'desc', desc: 'asc' } as const;\n\nexport class RequestSortEvent extends Event {\n constructor(\n public key: string,\n public direction: 'asc' | 'desc',\n ) {\n super('request-sort', {\n bubbles: true,\n cancelable: true,\n });\n }\n}\n\nconst paths = new Map(Object.entries({\n asc: `M88 166.059V468c0 6.627 5.373 12 12 12h56c6.627 0 12-5.373 12-12V166.059h46.059c21.382 0 32.09-25.851 16.971-40.971l-86.059-86.059c-9.373-9.373-24.569-9.373-33.941 0l-86.059 86.059c-15.119 15.119-4.411 40.971 16.971 40.971H88z`,\n desc: `M168 345.941V44c0-6.627-5.373-12-12-12h-56c-6.627 0-12 5.373-12 12v301.941H41.941c-21.382 0-32.09 25.851-16.971 40.971l86.059 86.059c9.373 9.373 24.569 9.373 33.941 0l86.059-86.059c15.119-15.119 4.411-40.971-16.971-40.971H168z`,\n sort: `M214.059 377.941H168V134.059h46.059c21.382 0 32.09-25.851 16.971-40.971L144.971 7.029c-9.373-9.373-24.568-9.373-33.941 0L24.971 93.088c-15.119 15.119-4.411 40.971 16.971 40.971H88v243.882H41.941c-21.382 0-32.09 25.851-16.971 40.971l86.059 86.059c9.373 9.373 24.568 9.373 33.941 0l86.059-86.059c15.12-15.119 4.412-40.971-16.97-40.971z`,\n}));\n\n/**\n * Table header cell\n * @slot - Place element content here\n */\n@customElement('pf-th')\nexport class PfTh extends LitElement {\n static readonly styles: CSSStyleSheet[] = [styles];\n\n @property({ type: Boolean, reflect: true }) sortable?: boolean = false;\n\n @property({ type: Boolean, reflect: true }) selected?: boolean = false;\n\n @property({\n reflect: true,\n attribute: 'sort-direction',\n }) sortDirection?: 'asc' | 'desc';\n\n @property() key!: string;\n\n @consume({ context: thRoleContext })\n private contextualRole: 'colheader' | 'rowheader' = 'rowheader';\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.setAttribute('role', this.contextualRole);\n }\n\n render(): TemplateResult<1> {\n const selected = !!this.selected;\n return this.sortable ?\n html`\n <button id=\"sort-button\"\n class=\"sortable ${classMap({ selected })}\"\n part=\"sort-button\"\n @click=\"${this.#onClick}\">\n <slot></slot>\n <span class=\"visually-hidden\">${!this.sortDirection ? '' : `(sorted ${this.sortDirection === 'asc' ? 'ascending' : 'descending'})`}</span>\n <span id=\"sort-indicator\">\n <svg fill=\"currentColor\" height=\"1em\" width=\"1em\" viewBox=\"0 0 256 512\" aria-hidden=\"true\" role=\"img\" style=\"vertical-align: -0.125em;\">${svg`\n <path d=\"${paths.get(this.sortDirection ?? 'sort')}\"></path>`}\n </svg>\n </span>\n </button>\n ` : html`\n <slot></slot>\n `;\n }\n\n #onClick() {\n if (this.sortable) {\n this.sort();\n }\n }\n\n sort(): void {\n const next = DIRECTIONS[this.sortDirection ?? 'asc'];\n this.dispatchEvent(new RequestSortEvent(this.key, next));\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'pf-th': PfTh;\n }\n}\n"]}