// #region Imports
import { DirectiveBase, PartType } from '../Controls/Directives/Abstracts/DirectiveBase';
import { directive } from 'lit/directive.js';
import { RendererServiceLocator } from '../Dom/Renderer';
class RouterLinkDirective extends DirectiveBase {
    constructor(args) {
        super(args);
        if (args.type !== PartType.ELEMENT) {
            throw new Error('routerLink directive can only be used on elements.');
        }
    }
    render(_opts) {
        return;
    }
    update(part, [opts]) {
        const element = part.element;
        const href = this.buildUrl(opts.href, opts.query ?? {});
        RendererServiceLocator.current.setAttribute(element, 'role', 'link');
        RendererServiceLocator.current.setAttribute(element, 'href', href);
        if (opts.target) {
            RendererServiceLocator.current.setAttribute(element, 'target', opts.target);
        }
        else {
            RendererServiceLocator.current.setAttribute(element, 'target', '');
        }
        return;
    }
    buildUrl(href, query) {
        const url = new URL(href, window.location.origin);
        Object.entries(query).forEach(([key, value]) => {
            url.searchParams.append(key, value);
        });
        return url.toString();
    }
}
export const routerLink = directive(RouterLinkDirective);
//# sourceMappingURL=RouterLinkDirective.js.map