<!DOCTYPE html>
	<html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
	<head>
<title>Đức Phật Nói Về Bốn Niềm Vui Của Người Tu Tại Gia</title>
<meta name="description" content="Đức Phật Nói Về Bốn Niềm Vui Của Người Tu Tại Gia - Savefile - Tin Tức -...">
<meta name="author" content="Phật Giáo Phú Thọ">
<meta name="copyright" content="Phật Giáo Phú Thọ [admin@phatgiaophutho.com]">
<meta name="generator" content="NukeViet v4.6">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#0d6efd">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="Chua Khai Nguyen">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Đức Phật Nói Về Bốn Niềm Vui Của Người Tu Tại Gia">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - http&#x3A;&#x002F;&#x002F;phatgiaophutho.com&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;luan&#x002F;duc-phat-noi-ve-bon-niem-vui-cua-nguoi-tu-tai-gia-24.html">
<meta property="og:site_name" content="Phật Giáo Phú Thọ">
<meta property="og:url" content="http://phatgiaophutho.com/vi/news/savefile/luan/duc-phat-noi-ve-bon-niem-vui-cua-nguoi-tu-tai-gia-24.html">
<link rel="shortcut icon" href="http://phatgiaophutho.com/uploads/logo150.png">
<link rel="canonical" href="http://phatgiaophutho.com/vi/news/savefile/luan/duc-phat-noi-ve-bon-niem-vui-cua-nguoi-tu-tai-gia-24.html">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/Tin-tuc/" title="Tin Tức - Tin tức" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/thong-bao/" title="Tin Tức - Thông Báo" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/can-biet/" title="Tin Tức - Cần biết" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/chu-vi-ton-tuc/" title="Tin Tức - Chư Vị Tôn Túc" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/ghpg-tinh-phu-tho/" title="Tin Tức - GHPG tỉnh Phú Thọ" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/chua-trong-tinh/" title="Tin Tức - Chùa Trong Tỉnh" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/chua-trong-nuoc/" title="Tin Tức - Chùa Trong Nước" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/phat-su-trong-tinh/" title="Tin Tức - Phật sự Trong Tỉnh" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/phat-su-trong-nuoc/" title="Tin Tức - Phật sự Trong Nước" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/phat-su-the-gioi/" title="Tin Tức - Phật sự Thế Giới" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/phat-hoc/" title="Tin Tức - Phật Học" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/kinh/" title="Tin Tức - Kinh" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/luat/" title="Tin Tức - Luật" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/luan/" title="Tin Tức - Luận" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/lich-su/" title="Tin Tức - Lịch Sử" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/chuyen-de/" title="Tin Tức - Chuyên Đề" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/thu-vien-video/" title="Tin Tức - Thư Viện Video" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/phat-giao-va-doi-song/" title="Tin Tức - Phật giáo và Đời sống" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/phat-giao-va-khoa-hoc/" title="Tin Tức - Phật giáo và Khoa học" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/phat-giao-va-tuoi-tre/" title="Tin Tức - Phật giáo và Tuổi trẻ" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/van-hoc/" title="Tin Tức - Văn Học" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/truyen-ngan/" title="Tin Tức - Truyện Ngắn" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/tho/" title="Tin Tức - Thơ" type="application/rss+xml">
<link rel="alternate" href="http://phatgiaophutho.com/vi/news/rss/tuy-but/" title="Tin Tức - Tuỳ Bút" type="application/rss+xml">
<link rel="manifest" href="http://phatgiaophutho.com/manifest.json">
<link rel="apple-touch-icon" href="http://phatgiaophutho.com/assets/images/icons/icon-192x192.png">
<link rel="manifest" href="http://phatgiaophutho.com/&#x002F;manifest.webmanifest?v&#x3D;1">
<link rel="apple-touch-icon" href="http://phatgiaophutho.com/&#x002F;uploads&#x002F;pwa&#x002F;apple-touch-icon-180.png">
<link rel="preload" as="style" href="http://phatgiaophutho.com/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/bootstrap.min.css" type="text/css">
<link rel="preload" as="style" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/style.css" type="text/css">
<link rel="preload" as="style" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/style.responsive.css" type="text/css">
<link rel="preload" as="style" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/custom.css" type="text/css">
<link rel="preload" as="style" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/news.css" type="text/css">
<link rel="preload" as="script" href="http://phatgiaophutho.com/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/themes/phatgiaophutho/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/themes/phatgiaophutho/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/themes/phatgiaophutho/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.googletagmanager.com/gtag/js?id=G-86PHME7W30" type="text/javascript">
<link rel="preload" as="script" href="http://phatgiaophutho.com/themes/phatgiaophutho/js/bootstrap.min.js" type="text/javascript">
<link rel="StyleSheet" href="http://phatgiaophutho.com/assets/css/font-awesome.min.css">
<link rel="StyleSheet" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/bootstrap.min.css">
<link rel="StyleSheet" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/style.css">
<link rel="StyleSheet" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/style.responsive.css">
<link rel="StyleSheet" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/custom.css">
<link rel="StyleSheet" href="http://phatgiaophutho.com/themes/phatgiaophutho/css/news.css">
<style type="text/css">
	body{background: #fff;}
</style>
		<!-- PWA Integration -->
<!-- PWA Mobile Support Start -->
<!-- PWA Mobile Support End -->
</head>
	<body>
<!-- Google tag (gtag.js) -->
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">Phật Giáo Phú Thọ</h2>
		<p class="pull-right"><a title="Phật Giáo Phú Thọ" href="http://phatgiaophutho.com/">http://phatgiaophutho.com</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Đức Phật Nói Về Bốn Niềm Vui Của Người Tu Tại Gia</h1>
		<ul class="list-inline">
			<li>Thứ tư - 06/01/2016 09:57</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			Đạo Phật từ khởi nguyên cho tới bây giờ luôn tồn tại hai giới tu hành, đó là giới xuất gia và giới tại gia.
		</div>
				<div class="imghome">
			<img alt="duc Phat noi ve bon niem vui cua nguoi tu tai gia" src="http://phatgiaophutho.com/uploads/news/2022_12/duc-phat-noi-ve-bon-niem-vui-cua-nguoi-tu-tai-gia.jpg" width="460" class="img-thumbnail" />
						<p>
				<em>duc Phat noi ve bon niem vui cua nguoi tu tai gia</em>
			</p>
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<div style="text-align: justify;"><span style="font-size:16px;">Người tu xuất gia cũng gọi là xuất gia đầu Phật. Xuất gia - là đến chốn hông nhà.&nbsp;Chữ “nhà”, là nhà ở cửa người thế tục. Người thế tục nào bỏ nhà ở của mình để đến ở nhà của Như Lai, là chùa để giữ gìn mạng mạch Phật pháp trường tồn và phát triển được, gọi là người trụ trì. Trụ, nghĩa ở; còn: Trì, nghĩa là giữ, giữ gìn. Thế nên Trụ Trì là ý nghĩa cao cả trong câu: Trụ Pháp Vương gia - Trì như Lai Tạng. Người tu xuất gia là người lấy Phật đức trang nghiêm thân tâm, khoác y Phật, đưa Phật Pháp vào lời nói, là người trưởng tử của Như Lai, tuyên dương giáo pháp làm lợi ích cho đời; bởi giáo pháp nhà Phật là giáo pháp bất ly thế gian để giác ngộ thế gian (chữ Hán biểu thị bằng câu: Phật pháp bất ly thế gian giác).&nbsp;</span></div><table>	<tbody>		<tr>			<td style="text-align: justify;"><span style="font-size:16px;"><img alt="" src="http://phatgiao.org.vn/Images/Contents/anhminh/20150923/Phatgiao-org-vn-duc-Phat-noi-ve-bon-niem-vui-cua-nguoi-tu-tai-gia.jpg" /></span></td>		</tr>		<tr>			<td style="text-align: justify;">&nbsp;</td>		</tr>	</tbody></table><div style="text-align: justify;"><br /><span style="font-size:16px;">Cho nên tu xuất gia mà dân gian gọi là tu chùa là lối tu cao tuột, hơn hẳn các lối tu khác.&nbsp;<br />&nbsp;<br />Người tu tại gia là người thực hiện các pháp tu ngay tại nơi ở, nơi sinh sống của mình cùng với gia đình (tại gia là tại nhà). Người tu tại gia gọi là Ưu bà tắc; là giới nữ gọi là Ưu bà di. Cũng có thể gọi chung là phật tử, tức con của đức Phật Thích Ca, và chính đức Phật đã chế định và khai mở đường lối tu này khi Ngài còn tại thế.<br />&nbsp;<br />Lịch sử Phật giáo ghi nhận người tu tại gia đầu tiên là một nhà triệu phú ở gần thành Ba-la-nại, khi ông ta đi tìm người con trai của mình tên là Yasa đã bỏ nhà ra đi vì chán cảnh sống thế gian tầm thường, vô vị. Ông đã tìm được người con trai của mình tại Vườn Nai, con trai ông đang nghe Phật thuyết pháp.<br />&nbsp;<br />Đến nơi, được nghe pháp, nhà triệu phú nọ cũng bị thuyết phục bởi những lời giảng của đức Phật về Tứ Đế và Bát Chính đạo. Thế rồi thể theo lời cầu xin của nhà triệu phú, đức Phật đã cho ông được quy y, trở thành người đệ tử tại gia đầu tiên. Nhà triệu phú nọ đã hoan hỷ trở lại nhà mình, tiếp tục công việc làm ăn, buôn bán. Còn người con trai của ông là Yasa thì được Phật cho xuất gia.&nbsp;<br />Từ mẫu hình của người tu tại gia đầu tiên từ thời đức Phật cách đây hơn 25 thế kỷ ấy, thì các pháp tu này vẫn còn nguyên giá trị. Đó là, người phát nguyện tu tại gia nhất thiết phải được nhà chùa chấp thuận và làm lễ Quy y Tam bảo cho.&nbsp;<br />&nbsp;<br />Trong buổi lễ ấy, nhà chùa có thể đặt Pháp danh (tên đạo) cho người được Quy y. Sau buổi lễ người phật tử đó được trở lại nhà ở, gia đình của mình và làm ăn, sinh sống bình thường trong công đồng dân cư và tự giác thực hiện những điều đã phát nguyện trước Tam Bảo trong buổi lễ Quy y.<br />&nbsp;<br />Để phát huy trách nhiệm của người phật tử tu tại gia, trước hết phải quan niệm sâu sắc lời Phật dạy qua kinh sách và những lời giảng Pháp của các thầy với các khóa học dành cho người tu tại gia; và không chỉ học hiểu mà còn biết kiến giải đúng nghĩa các thuật ngữ Phật học phổ thông như Tam Bảo, vô ngã, tứ vô lượng tâm, Phật tính v..v…Thực hành Bát chính đạo, sống có giá trị và ý nghĩa hướng thiện để đời sống của mình có giá trị và ý nghĩa, trở thành tấm gương sống đẹp, thực hành đời sống đạo đức, tâm linh, đồng thời Phật tử tu tại gia phải có tình thần hộ trì hoằng dương Chính Pháp, lợi lạc chúng sinh. Bên cạnh đó, người phật tử tu tại gia nếu có điều kiện sẵn sàng thực hành Pháp thí và Vô úy thí - tức là trao truyền kiến thức tu tập và bảo vệ che chở, đem niềm vui, hạnh phúc tới cho người khác, góp phần làm vơi bớt nỗi khổ niềm đau trên cuộc đời, trong xã hội.<br />&nbsp;<br />Trong văn hóa dân gian Việt Nam từng truyền tụng câu thơ cửa miệng về “sự tu” thật sâu sắc:<br />&nbsp;<br />Thứ nhất là tu tại gia<br />Thứ nhì tu chợ, thứ ba tu chùa<br />&nbsp;<br />Chớ hiểu lầm về sự sắp xếp thứ tự.. nơi tu trong câu lục bát này. Bởi vì: Tu tại gia được xếp “thứ nhất” ấy chỉ là bước đầu tiên trong việc thâm nhập và khai mở tri kiến Phật, chưa phải là lối tu cao tuột của người xuất gia mà trong bài viết này đã đề cập, đã Kiến giải và mặc dù vậy, ngay từ buổi đầu tiên chế định ra đường lối tu này; sau lời truyền Pháp, đức Phật đã hoan hỷ, tuyên dương với đại chúng về bốn niềm vui chính đáng của người Phật tử tu tại gia.&nbsp;Đó là:<br />&nbsp;<br />1. Niềm vui có của cải: Là do lao động chuyên cần bằng mồ hôi và những việc làm chính đáng của mình trong kinh doanh, làm khoa học kỹ thuật, hoặc lao động phổ thông. Sống lành mạnh, có đạo đức nghề nghiệp. được cộng đồng và pháp luật thừa nhận.<br />&nbsp;<br />2. Niềm vui được giàu có: Được giàu có là do lao động siêng năng, lại khéo léo sắp xếp công việc hợp lý, có kế hoạch vì thế tạo ra những lợi nhuận ngày một cao. Khi thụ hưởng giàu sang mà vẫn không quên làm việc lành.<br />&nbsp;<br />3. Niềm vui không có nợ nần: Là do có nghị lực kiềm chế. Thực hành “thiểu dục tri túc”, ít ham muốn, tự biết đủ. Không cờ bạc, rượu chè, giữ ngũ Giới… cho nên không có nợ nần, sống tự tại&nbsp;<br />&nbsp;<br />4. Niềm vui không bị chê trách: Là do các hành động của thân - khẩu - ý luôn thanh tịnh, không có điều gì đáng chê trách cho nên cuộc sống luôn thảnh thơi, tri thức thăng hoa, tâm thường hoan hỷ.<br />&nbsp;<br />Trong bốn niềm vui của người tu tại gia, thì niềm vui thứ tư được đức Phật tán dương nhất; Ngài cho rằng: niềm vui không bị chê trách là niềm vui ưu việt hơn cả.<br />&nbsp;<br />Ở nước ta, trong giới tu tại gia - các cư sĩ, phật tử ở thời nào cũng rất đông đảo. Họ là những thường dân, là thương gia giàu có, nhà khoa học, những nghệ sỹ tài năng và có cả những danh tướng, quân vương… nơi thế tục nhưng hết thảy những việc làm của họ đều xứng danh là các Hộ pháp ở thế gian còn nhiều những khổ đau này.&nbsp;<br />&nbsp;<br />Trong đó có những ngọn đuốc thiền sáng chói rất đáng tự hào, như nhà Trần (1225 - 1400) có Tuệ Trung Thượng sỹ Trần Tung - vị thiền sư lại là một cư sỹ tại gia, một nhà tư tưởng, nhà quân sự và cũng là một nhà thơ. Bác sĩ Tâm Minh - Lê Đình Thám (1897 - 1969) cũng là một cư sỹ tại gia mẫu mực, làm nhiều phật sự lớn như dịch Kinh Phật, mở các trường Phật học đào tạo tăng tài trong phong trào chấn hưng Phật giáo, đầu những năm 30 thế kỷ 20.&nbsp;<br />&nbsp;<br />Vậy là may mắn cho tôi và hết thảy những ai đó chưa hội đủ duyên lành để được làm người tu xuất gia, thì cũng chớ bỏ lỡ cơ hội Quy y Tam bảo, làm người tu tại gia, thực hiện các hạnh lành mà thụ hưởng bốn niềm vui mà đức Phật đã hoan hỷ chỉ bày.<br />&nbsp;<br />Nam mô Công đức lâm Bồ Tát Ma ha tát!</span></div><p style="text-align: justify;">&nbsp;</p><p style="text-align: justify;"><span style="font-size:16px;">Pháp Vương Tử Tạp chí Nghiên cứu Phật học số 5 năm 2015</span></p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="http://phatgiaophutho.com/vi/news/savefile/luan/duc-phat-noi-ve-bon-niem-vui-cua-nguoi-tu-tai-gia-24.html" title="Đức Phật Nói Về Bốn Niềm Vui Của Người Tu Tại Gia">http://phatgiaophutho.com/vi/news/savefile/luan/duc-phat-noi-ve-bon-niem-vui-cua-nguoi-tu-tai-gia-24.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; Phật Giáo Phú Thọ
		</div>
		<div id="contact">
			<a href="mailto:admin@phatgiaophutho.com">admin@phatgiaophutho.com</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="http://phatgiaophutho.com/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
<script src="http://phatgiaophutho.com/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=1,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="http://phatgiaophutho.com/assets/js/language/vi.js"></script>
<script src="http://phatgiaophutho.com/assets/js/DOMPurify/purify3.js"></script>
<script src="http://phatgiaophutho.com/assets/js/global.js"></script>
<script src="http://phatgiaophutho.com/assets/js/site.js"></script>
<script src="http://phatgiaophutho.com/themes/phatgiaophutho/js/news.js"></script>
<script src="http://phatgiaophutho.com/themes/phatgiaophutho/js/main.js"></script>
<script src="http://phatgiaophutho.com/themes/phatgiaophutho/js/custom.js"></script>
<script>
			if ('serviceWorker' in navigator) {
				window.addEventListener('load', function() {
					navigator.serviceWorker.register('/sw.js').then(function(registration) {
						console.log('PWA ServiceWorker registered with scope: ', registration.scope);
					}, function(err) {
						console.log('PWA ServiceWorker registration failed: ', err);
					});
				});
			}
		</script>
<script>(function(){
var d=document,h=d.head||d.getElementsByTagName("head")[0];
function addMeta(n,c){if(!d.querySelector("meta[name='"+n+"']")){var m=d.createElement("meta");m.name=n;m.content=c;h.appendChild(m);}}
function addLink(r,u){if(!d.querySelector("link[rel='"+r+"']")){var l=d.createElement("link");l.rel=r;l.href=u;h.appendChild(l);}}
addLink("manifest","\/manifest.webmanifest?v=1");
addLink("apple-touch-icon","\/uploads\/pwa\/apple-touch-icon-180.png");
addMeta("theme-color","#0d6efd");
addMeta("mobile-web-app-capable","yes");addMeta("apple-mobile-web-app-capable","yes");addMeta("apple-mobile-web-app-title","Chua Khai Nguyen");
if("serviceWorker" in navigator){window.addEventListener("load",function(){navigator.serviceWorker.register("\/sw.js?v=1",{scope:"\/"}).catch(function(e){if(window.console){console.warn("PWA service worker registration failed",e);}});});}
var deferredPrompt = null;
window.addEventListener("beforeinstallprompt", function(e) {
  e.preventDefault();
  deferredPrompt = e;
  if (typeof showPwaBanner === "function") {
    showPwaBanner();
  }
});
window.addEventListener("DOMContentLoaded", function() {
  var isStandalone = window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === true;
  if (isStandalone) return;
  var dismissed = localStorage.getItem("pwa_install_dismissed");
  if (dismissed && (Date.now() - parseInt(dismissed, 10) < 7 * 24 * 60 * 60 * 1000)) return;
  var ua = navigator.userAgent;
  var isIOS = /ipad|iphone|ipod/i.test(ua) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
  var isAndroid = /android/i.test(ua);
  if (!isAndroid && !isIOS) return;
  var isSafari = isIOS && /safari/i.test(ua) && !/crios|fxios|opios|edgios|coc_coc_browser/i.test(ua);
  var isFirefoxAndroid = isAndroid && /firefox|fxios/i.test(ua);
  var isChromium = isAndroid && /chrome|chromium|crios|edg|edgios|brave|vivaldi|opera|opt|coc_coc_browser/i.test(ua);
  var logoUrl = "\/uploads\/pwa\/apple-touch-icon-180.png";
  var css = ".pwa-install-banner{position:fixed;bottom:20px;left:50%;transform:translateX(-50%);width:92%;max-width:440px;background:rgba(255,255,255,0.96);box-shadow:0 10px 25px rgba(0,0,0,0.15);border:1px solid rgba(226,232,240,0.8);border-radius:16px;padding:16px;z-index:99999;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif;opacity:0;transform:translate(-50%,100px);transition:transform 0.4s cubic-bezier(0.16,1,0.3,1),opacity 0.4s;display:block;}" +
    ".pwa-install-banner.pwa-show{opacity:1;transform:translate(-50%,0);}" +
    ".pwa-banner-content{position:relative;display:flex;align-items:center;gap:12px;width:100%;}" +
    ".pwa-close-btn{position:absolute;top:-8px;right:-8px;background:#f1f5f9;border:none;font-size:16px;width:22px;height:22px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;color:#64748b;line-height:1;margin:0;padding:0;}" +
    ".pwa-close-btn:hover{background:#e2e8f0;color:#1e293b;}" +
    ".pwa-logo-container{flex-shrink:0;}" +
    ".pwa-app-logo{width:46px;height:46px;border-radius:10px;object-fit:cover;box-shadow:0 2px 6px rgba(0,0,0,0.1);}" +
    ".pwa-text-container{flex-grow:1;text-align:left;}" +
    ".pwa-title{margin:0 0 3px 0;font-size:14px;font-weight:600;color:#0f172a;}" +
    ".pwa-desc{margin:0;font-size:11px;color:#475569;line-height:1.4;}" +
    ".pwa-action-container{flex-shrink:0;}" +
    ".pwa-install-btn{background:#6a4500;color:#ffffff;border:none;padding:8px 14px;border-radius:8px;font-size:12px;font-weight:600;cursor:pointer;transition:background-color 0.2s,transform 0.1s;white-space:nowrap;}" +
    ".pwa-install-btn:hover{background:#8b5a00;}" +
    ".pwa-install-btn:active{transform:scale(0.95);}" +
    ".pwa-share-icon{display:inline-block;width:12px;height:12px;border:1.5px solid currentColor;border-top:none;position:relative;margin:0 3px;vertical-align:middle;box-sizing:border-box;}" +
    ".pwa-share-icon::before{content:\'\';position:absolute;top:-4px;left:3.5px;width:1.5px;height:8px;background:currentColor;}" +
    ".pwa-share-icon::after{content:\'\';position:absolute;top:-4px;left:1px;width:4px;height:4px;border-top:1.5px solid currentColor;border-left:1.5px solid currentColor;transform:rotate(45deg);}" +
    ".dark-mode .pwa-install-banner,[data-theme=\"dark\"] .pwa-install-banner{background:rgba(15,23,42,0.96);border-color:rgba(51,65,85,0.8);box-shadow:0 10px 25px rgba(0,0,0,0.35);}" +
    ".dark-mode .pwa-title,[data-theme=\"dark\"] .pwa-title{color:#f8fafc;}" +
    ".dark-mode .pwa-desc,[data-theme=\"dark\"] .pwa-desc{color:#94a3b8;}" +
    ".dark-mode .pwa-close-btn,[data-theme=\"dark\"] .pwa-close-btn{background:#334155;color:#94a3b8;}" +
    ".dark-mode .pwa-close-btn:hover,[data-theme=\"dark\"] .pwa-close-btn:hover{background:#475569;color:#f8fafc;}";
  var style = d.createElement("style");
  style.textContent = css;
  h.appendChild(style);
  window.showPwaBanner = function() {
    if (d.getElementById("pwa-install-banner")) return;
    var banner = d.createElement("div");
    banner.id = "pwa-install-banner";
    banner.className = "pwa-install-banner";
    var isChromiumPrompt = isChromium && deferredPrompt;
    var title = "Cài đặt Ứng dụng";
    var desc = "Cài đặt ứng dụng Chùa Khai Nguyên để sử dụng mượt mà và truy cập ngoại tuyến.";
    var actionHtml = "";
    if (isChromiumPrompt) {
      actionHtml = '<button class="pwa-install-btn" id="pwa-action-btn">Cài đặt</button>';
    } else if (isSafari && isIOS) {
      title = "Cài đặt trên iPhone/iPad";
      desc = "Bấm nút <strong>Chia sẻ</strong> <span class=\"pwa-share-icon\"></span> ở dưới thanh công cụ Safari, sau đó chọn <strong>\"Thêm vào Màn hình chính\"</strong>.";
    } else if (isIOS && !isSafari) {
      title = "Yêu cầu Safari";
      desc = "Vui lòng sao chép liên kết dưới đây và mở bằng trình duyệt <strong>Safari</strong> trên iPhone/iPad để cài đặt.";
      actionHtml = '<button class="pwa-install-btn" id="pwa-action-btn">Copy link</button>';
    } else if (isFirefoxAndroid) {
      title = "Cài đặt trên Firefox";
      desc = "Nhấp vào nút <strong>Menu</strong> (3 chấm dọc) ở góc trình duyệt Firefox và chọn <strong>\"Cài đặt\"</strong> hoặc <strong>\"Thêm vào Màn hình chính\"</strong>.";
    } else {
      title = "Cài đặt Ứng dụng";
      desc = "Bấm nút <strong>Menu (3 chấm)</strong> trên trình duyệt và chọn <strong>\"Thêm vào Màn hình chính\"</strong> để cài đặt.";
    }
    banner.innerHTML = '<div class="pwa-banner-content">' +
      '<button class="pwa-close-btn" id="pwa-close-btn">&times;</button>' +
      '<div class="pwa-logo-container">' +
        '<img src="http://phatgiaophutho.com/' + logoUrl + '" alt="App Logo" class="pwa-app-logo">' +
      '</div>' +
      '<div class="pwa-text-container">' +
        '<h4 class="pwa-title">' + title + '</h4>' +
        '<p class="pwa-desc">' + desc + '</p>' +
      '</div>' +
      (actionHtml ? '<div class="pwa-action-container">' + actionHtml + '</div>' : '') +
    '</div>';
    d.body.appendChild(banner);
    var closeBtn = d.getElementById("pwa-close-btn");
    var actionBtn = d.getElementById("pwa-action-btn");
    function dismissBanner() {
      banner.style.transition = "transform 0.4s ease, opacity 0.4s ease";
      banner.style.transform = "translate(-50%, 100px)";
      banner.style.opacity = "0";
      localStorage.setItem("pwa_install_dismissed", Date.now());
      setTimeout(function() { banner.remove(); }, 400);
    }
    closeBtn.addEventListener("click", dismissBanner);
    if (actionBtn) {
      if (isChromiumPrompt) {
        actionBtn.addEventListener("click", function() {
          if (!deferredPrompt) return;
          try {
            deferredPrompt.prompt();
            if (deferredPrompt.userChoice) {
              deferredPrompt.userChoice.then(function(choice) {
                if (choice && choice.outcome === "accepted") {
                  dismissBanner();
                }
              }).catch(function(err) {
                if (window.console) console.warn("PWA choice error:", err);
              });
            }
          } catch (err) {
            if (window.console) console.error("PWA prompt error:", err);
            alert("Vui lòng click vào dấu 3 chấm trên trình duyệt và chọn 'Thêm vào màn hình chính' để cài đặt.");
          }
        });
      } else if (isIOS && !isSafari) {
        actionBtn.addEventListener("click", function() {
          var url = window.location.href;
          if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(url).then(function() {
              actionBtn.innerText = "Đã copy!";
              setTimeout(function() { actionBtn.innerText = "Copy link"; }, 2000);
            });
          } else {
            var dummy = d.createElement("input");
            d.body.appendChild(dummy);
            dummy.value = url;
            dummy.select();
            d.execCommand("copy");
            d.body.removeChild(dummy);
            actionBtn.innerText = "Đã copy!";
            setTimeout(function() { actionBtn.innerText = "Copy link"; }, 2000);
          }
        });
      }
    }
    setTimeout(function() { banner.classList.add("pwa-show"); }, 50);
  };
  if (isSafari && isIOS) {
    showPwaBanner();
  } else if (isIOS && !isSafari) {
    showPwaBanner();
  } else if (isFirefoxAndroid) {
    showPwaBanner();
  } else if (isChromium) {
    if (deferredPrompt) {
      showPwaBanner();
    }
  } else {
    showPwaBanner();
  }
});
})();</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-86PHME7W30"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-86PHME7W30');
</script>
<script src="http://phatgiaophutho.com/themes/phatgiaophutho/js/bootstrap.min.js"></script>
<script>
        $(function() {
            if (!$('.ctv-scroll-tools').length) {
                var isTw = (typeof nv_lang_data !== 'undefined' && nv_lang_data === 'tw');
                var labels = {
                    nav: isTw ? '頁面導覽' : 'Điều hướng trang',
                    topTitle: isTw ? '回到頁首' : 'Lên đầu trang',
                    topText: isTw ? '回頂部' : 'Lên top',
                    upTitle: isTw ? '向上捲動' : 'Cuộn lên',
                    upText: isTw ? '向上' : 'Lên',
                    downTitle: isTw ? '向下捲動' : 'Cuộn xuống',
                    downText: isTw ? '向下' : 'Xuống'
                };
                $('body').append('<div class="ctv-scroll-tools" aria-label="' + labels.nav + '"><button type="button" class="ctv-scroll-btn" data-scroll-action="top" title="' + labels.topTitle + '"><i class="fa fa-angle-double-up" aria-hidden="true"></i><span>' + labels.topText + '</span></button><button type="button" class="ctv-scroll-btn" data-scroll-action="up" title="' + labels.upTitle + '"><i class="fa fa-angle-up" aria-hidden="true"></i><span>' + labels.upText + '</span></button><button type="button" class="ctv-scroll-btn" data-scroll-action="down" title="' + labels.downTitle + '"><i class="fa fa-angle-down" aria-hidden="true"></i><span>' + labels.downText + '</span></button></div>');
            }
            if (!$('#ctv-scroll-tools-style').length) {
                $('head').append('<style id="ctv-scroll-tools-style">.ctv-scroll-tools{position:fixed;right:16px;bottom:96px;z-index:9998;display:flex;flex-direction:column;gap:8px;opacity:0;visibility:hidden;transform:translateY(10px);transition:opacity .18s ease,visibility .18s ease,transform .18s ease}.ctv-scroll-tools.is-visible{opacity:1;visibility:visible;transform:translateY(0)}.ctv-scroll-btn{display:flex;align-items:center;justify-content:center;gap:6px;min-width:82px;height:36px;padding:0 10px;border:1px solid rgba(15,23,42,.14);border-radius:18px;background:rgba(255,255,255,.94);color:#0f172a;font-weight:700;font-size:12px;line-height:1;box-shadow:0 8px 24px rgba(15,23,42,.18)}.ctv-scroll-btn:hover,.ctv-scroll-btn:focus{background:#0d6efd;color:#fff;border-color:#0d6efd;outline:none}.ctv-scroll-btn i{font-size:16px}@media(max-width:767px){.ctv-scroll-tools{right:10px;bottom:72px}.ctv-scroll-btn{min-width:44px;width:44px;height:44px;border-radius:50%;padding:0}.ctv-scroll-btn span{display:none}.ctv-scroll-btn i{font-size:20px}}</style>');
            }
            function ctvToggleScrollTools() {
                $('.ctv-scroll-tools').toggleClass('is-visible', $(document).height() > $(window).height() + 120);
            }
            ctvToggleScrollTools();
            $(window).off('scroll.ctvScrollTools resize.ctvScrollTools load.ctvScrollTools').on('scroll.ctvScrollTools resize.ctvScrollTools load.ctvScrollTools', ctvToggleScrollTools);
            $(document).off('click.ctvScrollTools', '[data-scroll-action]').on('click.ctvScrollTools', '[data-scroll-action]', function() {
                var action = $(this).data('scroll-action');
                var currentTop = $(window).scrollTop();
                var viewport = Math.max(320, Math.floor($(window).height() * 0.78));
                var targetTop = currentTop;
                if (action === 'top') {
                    targetTop = 0;
                } else if (action === 'up') {
                    targetTop = Math.max(0, currentTop - viewport);
                } else if (action === 'down') {
                    targetTop = Math.min($(document).height() - $(window).height(), currentTop + viewport);
                }
                $('html, body').stop().animate({scrollTop: targetTop}, 360);
                return false;
            });
        });
        </script>
</body>
</html>