# frozen_string_literal: true class RsAuthComponent < ViewComponent::Base include OauthHelper def initialize(authorizations:) @authorizations = authorizations @auth = authorizations.first @web_app = @auth.web_app end def name @web_app&.name.presence || @auth.app_name.presence || @auth.client_id end def root_access? (@auth.permissions & [":r", ":rw"]).any? end def scope_summary return "All folders and files" if root_access? count = @auth.permissions.size "#{count} #{'folder'.pluralize(count)}" end def device_name @auth.device_name.presence || "Unknown device" end def expiry_label return "Never expires" if @auth.expire_at.blank? return "Expired" if @auth.expired? "Expires #{@auth.expire_at.strftime('%-d %b %Y')}" end def multiple_authorizations? @authorizations.size > 1 end end